Home » Modeling » Epsilon » [ECL] The Matches Method, Abstract Classes, and Super-Rules
[ECL] The Matches Method, Abstract Classes, and Super-Rules [message #657408] |
Wed, 02 March 2011 11:59  |
Eclipse User |
|
|
|
Hi,
first of all, my first impression of ECL is great! Congratulations!
Thatswhy, I'm currently trying to integrate ECL in one of my projects. I
already managed to setup a module and programmatically match two
EObjects. Now I've several questions to the ECL itself.
My examples are all for Ecore models...
I was trying to set up a rule which matches equally named EClasses that
are in the same EPackage... here is what I wrote:
<code>
rule EClass
match l : Left!EClass
with r : Right!EClass {
compare : l.name = r.name and l.ePackage.matches(r.ePackage)
}
rule EPackage
match l : Left!EPackage
with r : Right!EPackage {
compare : l.nsURI = r.nsURI and
l.eSuperPackage.matches(r.eSuperPackage)
}
</code>
However, I get the following exception:
<stacktrace>
Caused by: Method 'matches' not found (ecore.ecl@5:45)
at
org.eclipse.epsilon.eol.execute.PointExecutor.executeOperati on(PointExecutor.java:169)
at
org.eclipse.epsilon.eol.execute.PointExecutor.execute(PointE xecutor.java:74)
at
org.eclipse.epsilon.eol.execute.PointExecutor.execute(PointE xecutor.java:42)
at
org.eclipse.epsilon.eol.execute.PointExecutor.execute(PointE xecutor.java:130)
at
org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(E xecutorFactory.java:179)
at
org.eclipse.epsilon.eol.execute.OperatorExecutor.and(Operato rExecutor.java:194)
at
org.eclipse.epsilon.eol.execute.OperatorExecutor.execute(Ope ratorExecutor.java:43)
at
org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(E xecutorFactory.java:179)
at
org.eclipse.epsilon.eol.execute.ExecutorFactory.executeBlock OrExpressionAst(ExecutorFactory.java:134)
at org.eclipse.epsilon.ecl.MatchRule.match(MatchRule.java:345)
at org.eclipse.epsilon.ecl.EclModule.match(EclModule.java:162)
at
org.modelversioning.ecl.matcher.impl.ECLFileMatcherImpl.matc hes(ECLFileMatcherImpl.java:65)
... 60 more
</stacktrace>
In several examples I saw in the book and on the web, the method
"matches" was used... what am I doing wrong?
My second question concerns rules for abstract classes. For instance,
when I use the following rule, it won't be used for matching EClasses
(although they are also EClassifiers):
<code>
rule EClassifier
match l : Left!EClassifier
with r : Right!EClassifier {
compare : l.name = r.name
}
</code>
Isn't that possible in general (using super types in rules), or am I
mistaking something?
This brings me to my last question... in the Epsilon Book and in the
aforementioned paper, you wrote something about "super-rules". However,
I couldn't find an example, how to syntactically write such rules... I
thought, maybe this is what I was looking for when trying to match
EClassifiers (cf. previous question).
In general, is there more documentation about ECL than the Epsilon Book
and the Springer publication "Establishing Correspondences between
Models with the ECL"? I couldn't really find more... Would be great!!!
Many thanks in advance for your help! Hope to learn more about ECL soon!
Thanks,
Philip
|
|
| |
Re: [ECL] The Matches Method, Abstract Classes, and Super-Rules [message #659428 is a reply to message #658422] |
Sun, 13 March 2011 15:46   |
Eclipse User |
|
|
|
Hi Dimitris,
thank you very much for your reply and sorry for my late reply!
I'll try the @greedy annotation! Sounds good!
I just sent you a small project containing the minimal configuration in which I'm experiencing the "matches not found" issue.
Another small remark:
When retrieving a Match from a module, the method Match.isMatching returns true although no rule actually "fired". From my perspective, this is kind of misleading since these two objects haven't actually been matched---there was just no rule for them. This is why, I have to use...
Match match = module.match(left, right, false);
boolean matched = match.getRule() != null && match.isMatching();
...in my code, to check if there actually was a rule matching the objects left and right.
Thanks a lot!
Philip
|
|
|
Re: [ECL] The Matches Method, Abstract Classes, and Super-Rules [message #660085 is a reply to message #657408] |
Wed, 16 March 2011 14:34  |
Eclipse User |
|
|
|
Hi,
just received the solution to my first issue (method "matches" not found) from Dimitris (thank you very much, btw). Just to document the solution. The module has to be correctly initialized. The working code:
// initialize left and right model
Resource leftResource = ...;
Resource rightResource = ...;
InMemoryEmfModel leftModel = new InMemoryEmfModel(leftResource);
leftModel.setName("Left");
InMemoryEmfModel rightModel = new InMemoryEmfModel(rightResource);
rightModel.setName("Right");
// set up module
EclModule module = new EclModule();
module.getContext().setOperationFactory(new EclOperationFactory());
// set variables to context
Variable matchTraceVariable = Variable.createReadOnlyVariable(
"matchTrace", module.getContext().getMatchTrace());
module.getContext().getFrameStack().put(matchTraceVariable);
Variable contextVariable = Variable.createReadOnlyVariable(
"context", module.getContext());
module.getContext().getFrameStack().put(contextVariable);
Variable selfVariable = Variable.createReadOnlyVariable("self",
module);
module.getContext().getFrameStack().put(selfVariable);
// parse ecl file
module.parse(eclFileURI); // URI to ECL file
// set left and right model to context
module.getContext().getModelRepository().addModel(leftModel);
module.getContext().getModelRepository().addModel(rightModel);
EclipseContextManager.setup(module.getContext());
// now we can check for matching eObjects
EObject left = ...;
EObject right = ...;
Match match = module.match(left, right, false);
boolean matching = match.getRule() != null && match.isMatching();
Thanks lot for your help, Dimitris!
Cheers,
Philip
|
|
|
Goto Forum:
Current Time: Sun Jul 20 11:26:18 EDT 2025
Powered by FUDForum. Page generated in 0.04060 seconds
|