Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Check, xTend]
[Check, xTend] [message #496590] Tue, 10 November 2009 16:19 Go to next message
Federico Tomassetti is currently offline Federico Tomassetti
Messages: 186
Registered: July 2009
Location: Torino
Senior Member

Hi,
I am trying to insert in Check a constraint on the value of a property (of type EString) called "conditionToBeShown" of an EClass called "LocationElement".

So I started writing the rule in a Check file:

context SitePack::LocationElement ERROR "Condition is not correct" :

ok, no problem for the first rule, now, it seems that I can use just properties of LocationElement to express the constraints. But I don't know how to extend LocationElement with a method able to judge the property "conditionToBeShown" correctly. I tried using an extension.

So I created a file DslExtensions.ext and tried.

First of all I mapped the Java method containing the verification logic. It was not difficult:

import SitePack

Boolean isConditionTextCorrect(String text):
JAVA it.tomassetti.mdwe.ConditionDsl.isCorrect(java.lang.String);

Boolean isConditionTextCorrect(LocationElement element):
JAVA it.tomassetti.mdwe.ConditionDsl.isCorrect(SitePack.LocationE lement);

as you can imagine both the Java method perform the same operation ( the method receining a LocationElement just calls the other one public static boolean isCorrect(LocationElement element){
return isCorrect(element.getConditionToBeShown());
}).

Now, How can I use one of this extension to verify the constraint inside the Check file?
I tried with:

import DslExtensions;

context SitePack::LocationElement ERROR "Condition is not correct" :
this.isConditionTextCorrect();

Suggestions? Documentation that I missed? Am I totally wrong?


Re: [Check, xTend] [message #496750 is a reply to message #496590] Wed, 11 November 2009 09:58 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1769
Registered: July 2009
Senior Member
You don't need to delegate both calls to Java.

isConditionTextCorrect(LocationElement element) :
isConditionTextCorrect(element.conditionToBeShown);

Boolean isConditionTextCorrect(String text):
JAVA it.tomassetti.mdwe.ConditionDsl.isCorrect(java.lang.String);

Cheers,
Sven

Federico Tomassetti schrieb:
> Hi,
> I am trying to insert in Check a constraint on the value of a property
> (of type EString) called "conditionToBeShown" of an EClass called
> "LocationElement".
>
> So I started writing the rule in a Check file:
>
> context SitePack::LocationElement ERROR "Condition is not correct" :
>
> ok, no problem for the first rule, now, it seems that I can use just
> properties of LocationElement to express the constraints. But I don't
> know how to extend LocationElement with a method able to judge the
> property "conditionToBeShown" correctly. I tried using an extension.
>
> So I created a file DslExtensions.ext and tried.
>
> First of all I mapped the Java method containing the verification logic.
> It was not difficult:
>
> import SitePack
>
> Boolean isConditionTextCorrect(String text):
> JAVA it.tomassetti.mdwe.ConditionDsl.isCorrect(java.lang.String);
>
> Boolean isConditionTextCorrect(LocationElement element):
> JAVA it.tomassetti.mdwe.ConditionDsl.isCorrect(SitePack.LocationE
> lement);
>
> as you can imagine both the Java method perform the same operation (
> the method receining a LocationElement just calls the other one public
> static boolean isCorrect(LocationElement element){
> return isCorrect(element.getConditionToBeShown());
> }).
>
> Now, How can I use one of this extension to verify the constraint inside
> the Check file?
> I tried with:
>
> import DslExtensions;
>
> context SitePack::LocationElement ERROR "Condition is not correct" :
> this.isConditionTextCorrect();
>
> Suggestions? Documentation that I missed? Am I totally wrong?
> From - Wed


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [Check, xTend] [message #496758 is a reply to message #496750] Wed, 11 November 2009 10:17 Go to previous messageGo to next message
Federico Tomassetti is currently offline Federico Tomassetti
Messages: 186
Registered: July 2009
Location: Torino
Senior Member

Thank you for your reply,

I still don't know how to call this extension from a CheckFile, I tried in this way:

import DslExtensions;

context SitePack::LocationElement ERROR "Condition is not correct" :
this.isConditionTextCorrect();

becuase I read in some documentation on the old oaw site that is possible to invoke an extension using the first parameter before the dot in this way:

SomeOperation(MyFirstParam)
MyFirstParam.SomeOperation()

Am I wrong? How can I express the constraint using my extension?

Thank you,
Federico


Re: [Check, xTend] [message #496780 is a reply to message #496758] Wed, 11 November 2009 11:12 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1769
Registered: July 2009
Senior Member
extensions are imported through a special statement:

import packageName;
extension my::path::too::DslExtensions;

context SitePack::LocationElement ERROR "Condition is not correct" :
this.isConditionTextCorrect();


Federico Tomassetti schrieb:
> becuase I read in some documentation on the old oaw site that is
> possible to invoke an extension using the first parameter before the dot
> in this way:
>
> SomeOperation(MyFirstParam)
> MyFirstParam.SomeOperation()

Yes, that's possible.

Cheers,
Sven


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [Check, xTend] [message #496812 is a reply to message #496780] Wed, 11 November 2009 13:19 Go to previous message
Federico Tomassetti is currently offline Federico Tomassetti
Messages: 186
Registered: July 2009
Location: Torino
Senior Member

Thank you, now my extension is called from the Check file.
I was so desperate that I was trying to create a Component just to invoke that java function.

Now the extension is called but... I get an error:

Caused by: java.lang.IllegalArgumentException: SitePack::TextInput is not responsible for java type SitePack.LocationElement
	at org.eclipse.xtend.typesystem.AbstractTypeImpl.convert(AbstractTypeImpl.java:178)
	at org.eclipse.internal.xtend.xtend.ast.JavaExtensionStatement.convertTypesToMethodSignature(JavaExtensionStatement.java:86)
	at org.eclipse.internal.xtend.xtend.ast.JavaExtensionStatement.evaluateInternal(JavaExtensionStatement.java:73)
	... 15 more


a TextInput is a ECore class having as ancestore LocationElement so I thought I could make use of polymorphism here... was I wrong?


Previous Topic:XSD metamodel - XSD caching
Next Topic:Should I be using the "middleend"?
Goto Forum:
  


Current Time: Thu Oct 23 02:28:45 GMT 2014

Powered by FUDForum. Page generated in 0.01870 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software