OCL 'source code' of an OCLExpression [message #556303] |
Tue, 31 August 2010 12:54  |
Eclipse User |
|
|
|
Hi!
I have trouble obtaining the OCL source code of an OCLExpression instance. I thought this to be a rather trivial problem at first, so I hope I didn't miss something obvious!
I want to annotate an Ecore model with OCL expressions for validation, but when I create an EAnnotation with the return value of myOclExpr.toString() as the value of a detail entry, I get code which is syntactically incorrect, e.g.
PackageA::ClassA.allInstances()->forAll(x : ClassA, y : ClassA | x.referenceA->includes(y).implies(x.referenceB->includes(y)))
instead of
PackageA::ClassA.allInstances()->forAll(x : ClassA, y : ClassA | x.referenceA->includes(y) implies x.referenceB->includes(y))
Obviously I'm not able to run any validation on my model with this code.
I figure the toString()-method (and hence the ToStringVisitor) is not the correct way to obtain the OCL source, but what exactly IS the correct way?
Kind regards,
Martin
|
|
|
Re: OCL 'source code' of an OCLExpression [message #556312 is a reply to message #556303] |
Tue, 31 August 2010 13:22   |
Eclipse User |
|
|
|
Hi Martin
The API of ToStringVisitor is documented as:
* Converts an OCL expression to a string for debugging. This is not
intended
* to be used by client applications as an AST-to-text transformation.
For debugging purposes ".implies()" etc is more readable than "implies".
There is an explicit OCL unparser as part of the M2M/QVTd project.
There is unparsing as part of the Xtext editors, but slightly difficult
to access. Please raise a Bugzilla to have a useful public API for this.
I'm not clear why you are starting with the AST. If you use OCLinEcore
you can annotate your Ecore model directly.
Regards
Ed Willink
On 31/08/2010 17:54, Martin Knauer wrote:
> Hi!
>
> I have trouble obtaining the OCL source code of an OCLExpression
> instance. I thought this to be a rather trivial problem at first, so I
> hope I didn't miss something obvious!
>
> I want to annotate an Ecore model with OCL expressions for validation,
> but when I create an EAnnotation with the return value of
> myOclExpr.toString() as the value of a detail entry, I get code which is
> syntactically incorrect, e.g.
> PackageA::ClassA.allInstances()->forAll(x : ClassA, y : ClassA |
> x.referenceA->includes(y).implies(x.referenceB->includes(y)))
>
> instead of
> PackageA::ClassA.allInstances()->forAll(x : ClassA, y : ClassA |
> x.referenceA->includes(y) implies x.referenceB->includes(y))
>
> Obviously I'm not able to run any validation on my model with this code.
>
> I figure the toString()-method (and hence the ToStringVisitor) is not
> the correct way to obtain the OCL source, but what exactly IS the
> correct way?
>
> Kind regards,
> Martin
|
|
|
|
Re: OCL 'source code' of an OCLExpression [message #556522 is a reply to message #556429] |
Wed, 01 September 2010 12:11  |
Eclipse User |
|
|
|
Hi
For now, I would recommend starting with
org.eclipse.qvt.declarative.parser.unparser.OCLUnparser
since it's simple with few dependencies. You can tweak it to your taste.
The Xtext config is part of a more powerful framework so it may be
harder to exploit.
Regards
Ed Willink
On 01/09/2010 11:10, Martin Knauer wrote:
> Hi Ed,
>
> thanks a lot for your reply!
>
> Edward Willink wrote on Tue, 31 August 2010 19:22
>> I'm not clear why you are starting with the AST. If you use OCLinEcore
>> you can annotate your Ecore model directly.
>
> The model and the OCL constraints are supposed to be programmatically
> generated at the same time, so the plan was to build an AST rather than
> to build the OCL code with Strings. I hope I will find what I need in
> M2M/QVTd or Xtext!
>
> Thanks again,
> regards,
> Martin
|
|
|
Powered by
FUDForum. Page generated in 0.05632 seconds