Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Build an OCL AST - Set OperationCallExp{source,argument,name}
Build an OCL AST - Set OperationCallExp{source,argument,name} [message #1020971] Tue, 19 March 2013 05:18 Go to next message
Eugen Kuksa is currently offline Eugen Kuksa
Messages: 2
Registered: March 2013
Junior Member
Hi,

I'm trying to generate an OCL AST with org.eclipse.ocl.ecore.EFactory, but I cannot find a way to create an OperationCallExp. Also I cannot find any good documentation about that topic.

I'm currently interested in the String output of the OCL constraints I generate. The constraints are supposed to be related to an ecore model. Later, I want to save the constraints in an OCL file. Thus, it is important to have the AST.

As for the beginning, I made a Unit Test to get used to the API:
def void testExpressions() {
	var lnull = factory.createNullLiteralExp
	assertEquals("null", lnull.toString)
	
	var lbool = factory.createBooleanLiteralExp
	lbool.booleanSymbol = true
	assertEquals("true", lbool.toString)
	lbool.booleanSymbol = false
	assertEquals("false", lbool.toString)
	
	var lint = factory.createIntegerLiteralExp
	lint.integerSymbol = 1234
	assertEquals("1234", lint.toString)
		
	var lreal = factory.createRealLiteralExp
	lreal.realSymbol = 1.234
	assertEquals("1.234", lreal.toString)
		
	var lif = factory.createIfExp
	lif.condition = lbool
	lif.thenExpression = lint
	lif.elseExpression = lreal
	assertEquals("if false then 1234 else 1.234 endif", lif.toString)
}


The next step would be to create OperationCallExps, but there's no way to set the operation name, the source, the infix-flag and the arguments.

I'm using org.eclipse.ocl version 4.0.2
Re: Build an OCL AST - Set OperationCallExp{source,argument,name} [message #1021056 is a reply to message #1020971] Tue, 19 March 2013 08:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

There is no org.eclipse.ocl.ecore.EFactory.

There is a org.eclipse.ocl.ecore.EcoreFactory which has a
createOperationCallExp()

I presume you are getting confused with org.eclipse.emf.ecore.EcoreFactory.

Creating OCL ASTs programmatically is seriously hard. I suggest you
review your entire design approach and consisder using the available
text to AST facilities, possibly using the new Pivot-based epresentation
that provides a PrettyPrintVisitor as well as a ToStringVisitor.

Regards

Ed Willink


On 19/03/2013 12:18, Eugen Kuksa wrote:
> Hi,
>
> I'm trying to generate an OCL AST with org.eclipse.ocl.ecore.EFactory,
> but I cannot find a way to create an OperationCallExp. Also I cannot
> find any good documentation about that topic.
>
> I'm currently interested in the String output of the OCL constraints I
> generate. The constraints are supposed to be related to an ecore
> model. Later, I want to save the constraints in an OCL file. Thus, it
> is important to have the AST.
>
> As for the beginning, I made a Unit Test to get used to the API:
> def void testExpressions() {
> var lnull = factory.createNullLiteralExp
> assertEquals("null", lnull.toString)
>
> var lbool = factory.createBooleanLiteralExp
> lbool.booleanSymbol = true
> assertEquals("true", lbool.toString)
> lbool.booleanSymbol = false
> assertEquals("false", lbool.toString)
>
> var lint = factory.createIntegerLiteralExp
> lint.integerSymbol = 1234
> assertEquals("1234", lint.toString)
>
> var lreal = factory.createRealLiteralExp
> lreal.realSymbol = 1.234
> assertEquals("1.234", lreal.toString)
>
> var lif = factory.createIfExp
> lif.condition = lbool
> lif.thenExpression = lint
> lif.elseExpression = lreal
> assertEquals("if false then 1234 else 1.234 endif", lif.toString)
> }
>
>
> The next step would be to create OperationCallExps, but there's no way
> to set the operation name, the source, the infix-flag and the arguments.
>
> I'm using org.eclipse.ocl version 4.0.2
Re: Build an OCL AST - Set OperationCallExp{source,argument,name} [message #1021206 is a reply to message #1021056] Tue, 19 March 2013 12:53 Go to previous messageGo to next message
Eugen Kuksa is currently offline Eugen Kuksa
Messages: 2
Registered: March 2013
Junior Member
Ed Willink wrote on Tue, 19 March 2013 08:53

There is no org.eclipse.ocl.ecore.EFactory.

There is a org.eclipse.ocl.ecore.EcoreFactory which has a
createOperationCallExp()

You're right. That was a typo. I actually use org.eclipse.ocl.ecore.EcoreFactory.

Ed Willink wrote on Tue, 19 March 2013 08:53

I presume you are getting confused with org.eclipse.emf.ecore.EcoreFactory.

Thanks for the hint, but I see the difference between those two (and I use both in my project).

Ed Willink wrote on Tue, 19 March 2013 08:53

Creating OCL ASTs programmatically is seriously hard. I suggest you
review your entire design approach and consisder using the available
text to AST facilities, possibly using the new Pivot-based epresentation
that provides a PrettyPrintVisitor as well as a ToStringVisitor.

Is there really no usable way to generate the AST? For some of the OCL features it already works perfectly fine, as can be seen in my initial post.

My approach is to create the AST and then create text from that, not the other way around. The textual representation of OCL is supposed to be the final result of my project. I don't want to do any calculations on the AST - only output a concrete syntax representation.
Re: Build an OCL AST - Set OperationCallExp{source,argument,name} [message #1021222 is a reply to message #1021206] Tue, 19 March 2013 13:20 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

> Is there really no usable way to generate the AST? For some of the OCL
> features it already works perfectly fine, as can be seen in my initial
> post.
The AST is an EMF-generated model so you can fully construct it in Java
and may find some utility routines to help you a bit.

However there are many subtleties such as ownership of synthesized
collection types and references to library operations.

Ultimately you should be aware that, as specified, the OMG AST is
unimplementable.

The classic Ecore/UML-based ASTs are propretary with unpleasant templates.

The new Pivot-based AST could be regarded as a prototype for resolution
of the problems in OCL 2.5, however it is used internally and saved for
debug; it is not yet consistently loadable.

If you really want to do programmatic construction, I recommend define a
richer Factory with methods such as

createIfExp(condExp, thenExp, elseExp)
createCollectionType(kind, elementType)

so that your calling code will be moderately readable and
rationalization of the AST will be substantially hidden.

Such a Facade could make for a useful addition to the Eclipse OCL
project. It bears some resemblance to ValuesUtil and
DomainStandardLibrary in the new code.

Regards

Ed Willink
Previous Topic:checking the attributes of client and supplier in dependency
Next Topic:[Announce] Eclipse OCL 4.1.0 (Kepler) M6 is now available.
Goto Forum:
  


Current Time: Thu Aug 28 21:41:42 EDT 2014

Powered by FUDForum. Page generated in 0.01621 seconds