[Check, xTend] [message #496590] |
Tue, 10 November 2009 16:19 |
|
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?
website: http://www.federico-tomassetti.it
|
|
|
|
Re: [Check, xTend] [message #496758 is a reply to message #496750] |
Wed, 11 November 2009 10:17 |
|
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
website: http://www.federico-tomassetti.it
|
|
|
|
Re: [Check, xTend] [message #496812 is a reply to message #496780] |
Wed, 11 November 2009 13:19 |
|
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?
website: http://www.federico-tomassetti.it
|
|
|
Powered by
FUDForum. Page generated in 0.25405 seconds