Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with OCL and Xtend code generator project(XTend code generator project for ecore model doesn't work with OCL constraints)
Problem with OCL and Xtend code generator project [message #1776599] Sat, 18 November 2017 11:05 Go to next message
Ambreen Hussain is currently offline Ambreen HussainFriend
Messages: 8
Registered: September 2012
Junior Member
Hi there,
I want to write a code generator in Xtend for my ecore model. I am replicating this tutorial
https://christiandietrich.wordpress.com/2011/07/29/xtend2-code-generators-with-non-xtext-models/
The code is generated fine for the model but when I added OCL constraints I got errors such as
ERROR Mwe2Launcher - Problems running workflow my.generator.project: Validation problems:
Unable to find delegate to evaluate the 'check1' constraint on 'root.impl.TestImpl@6f0ca692{file:/C:/Users/Ambreen/Documents/phdModel/phdModel/my.generator.project/model/a.root#//@tests.0}': http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot
On running .mwe2 file in my.generator.project the errors will come up.
I have added the required libraries. I found this code in the forums but couldn't understand where to put this to check if the project works with this code
String ocldelegateURI = OCLdelegateDomain.OCL_delegate_URI;

Operation.Internal.Invocationdelegate.Factory.Registry.INSTANCE.put(ocldelegateURI,
new OCLInvocationdelegateFactory.Global());

EStructuralFeature.Internal.Settingdelegate.Factory.Registry.INSTANCE.put(ocldelegateURI,
new OCLSettingdelegateFactory.Global());

EValidator.Validationdelegate.Registry.INSTANCE.put(ocldelegateURI,
new OCLValidationdelegateFactory.Global());
I have a demo project but size is big to upload with this message. If you can send me your email address I can send you this directly. Many Thanks
Re: Problem with OCL and Xtend code generator project [message #1776604 is a reply to message #1776599] Sat, 18 November 2017 11:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Specifically, you may find http://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/utilities/OCLDelegateSetup.java helpful.

It is invoked as:

bean = OCLDelegateSetup { resourceSet = resourceSet }

see http://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/GenerateCSModelsFromUML.mwe2

However you should find that the above is unnecessarily detailed. I revised the initialization so that most of the OCL sub-systems are initialized automatically from any use of OCL at all. You should find that all you actually need to invoke in Java is PivotStandaloneSetup.init().

Regards

Ed Willink
Re: Problem with OCL and Xtend code generator project [message #1776633 is a reply to message #1776604] Sun, 19 November 2017 16:06 Go to previous messageGo to next message
Ambreen Hussain is currently offline Ambreen HussainFriend
Messages: 8
Registered: September 2012
Junior Member
Hi, I created a OCLDelegateSetup class and entered the bean for this class in .mwe2 file. It still doesn't work. I didn't understand which java class should I put
PivotStandaloneSetup.init() method in. The java classes I have are either generated for my model or the ones to setup generator project shown in screenshot attached. Please help?

Thanks,
Re: Problem with OCL and Xtend code generator project [message #1776636 is a reply to message #1776633] Sun, 19 November 2017 18:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Put it in an MWE2 bean class just like OCLDelegateSetup.java

Regards

Ed Willink
Re: Problem with OCL and Xtend code generator project [message #1776642 is a reply to message #1776636] Sun, 19 November 2017 20:42 Go to previous messageGo to next message
Ambreen Hussain is currently offline Ambreen HussainFriend
Messages: 8
Registered: September 2012
Junior Member
Hi,
I put this method in OCLDelegateSetup.java with import of org.eclipse.ocl.pivot.utilities.PivotStandaloneSetup library because it is already a bean in .mwe2. But it didn't work. I tried separate OCLPivotSetup.java class and added bean just like OCLDelegateSetup.java. That didn't work too. Both are shown in the picture. I am still getting errors. Did I do the right thing?

Thanks,
Re: Problem with OCL and Xtend code generator project [message #1776684 is a reply to message #1776642] Mon, 20 November 2017 11:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

I cannot reproduce from screen shots. Please provide a zipped project that demonstrates the problem.

Regards

Ed Willink
Re: Problem with OCL and Xtend code generator project [message #1776719 is a reply to message #1776684] Mon, 20 November 2017 17:53 Go to previous messageGo to next message
Ambreen Hussain is currently offline Ambreen HussainFriend
Messages: 8
Registered: September 2012
Junior Member
Hi Ed,
I have shared the project via dropbox because of the size it cannot be uploaded with this message. You should receive an email.

Many Thanks,
Ambreen
Re: Problem with OCL and Xtend code generator project [message #1776860 is a reply to message #1776719] Wed, 22 November 2017 10:45 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Using your GitHub project...

After fixing the following isssues
non-existent project issues: you have both ...examples.pivot and ...pivot. ...examples.pivot existed only as a placeholder. Removed for Neon++/Oxygen.
plugin.genmodel referencing non-exiusting genmodels.

(You have many *.class in GIT; this is not normally recommended.)

Thereafter I get the message:

3439 ERROR Mwe2Launcher - Problems running workflow my.generator.project.EMSGenerator: Validation problems:
1 error:
a.root - C:\Users\Edward\git\phdModel\phdModel\my.generator.project\model\a.root
1: An exception occurred while delegating evaluation of the 'check1' constraint on 'root.impl.TestImpl@3ef41c66{file:/C:/Users/Edward/git/phdModel/phdModel/my.generator.project/model/a.root#//@tests.0}': org.eclipse.ocl.pivot.internal.delegate.OCLDelegateException: Failed to create Xtext resource for '___IiYM9jEeeQ0-KShs-0iA.essentialocl'
Make sure EssentialOCLStandaloneSetup.doSetup() has been called.

I'm not sure why you didn't report this. It is a very strong clue that you could have debugged.

Calling EssentialOCLStandaloneSetup.doSetup() (OCL parsing and OCL model init) rather than PivotStandaloneSetup.init() (OCL model init) doesn't help.

The problem is that you are using org.eclipse.xtext.mwe.Reader rather than org.eclipse.emf.mwe.utils.Reader.

org.eclipse.emf.mwe.utils.Reader has a resourceSet argument that enables you to re-use the ResourceSet that has been initialized with OCL capabilities.

org.eclipse.xtext.mwe.Reader creates a new ResourceSet unless you are clever enough to configure a ResourceSetProvider that re-uses an old one.

If I change to:

component = Reader {
uri = "../org.eclipse.example.EMSModel/model/test.ecore"
resourceSet = resourceSet
modelSlot = "model"
}

the file reads, and the problem is

Caused by: java.lang.IllegalStateException: Slot contents was not a Resource but a 'EPackageImpl'!

which is just an EObject.eResource() call away from compatible. Perhaps that is why I developed /org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/utilities/ResourceReader.java (eek 7 years ago!).

I am afraid that I cannot help with subsequent GeneratorComponent issues since I have never used it. My perception has always been that the optional/independent generation of Java from OCL does not fit the standard Xtext all-in-one lifecycle.

Regards

Ed Willink
Re: Problem with OCL and Xtend code generator project [message #1776865 is a reply to message #1776860] Wed, 22 November 2017 11:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Correction. I didn't read the error message carefully enough; I invoked EssentialOCLStandaloneSetup.init() which omits the injector/editor configuration.

If you invoke EssentialOCLStandaloneSetup.doSetup() global registries are initialized and you can use org.eclipse.xtext.mwe.Reader. You shouldn't need other OCL initializations unless you want UML or Complete OCL support too (UMLStandaloneSetup.init(), CompleteOCLStandaloneSetup.doSetup()).

Regards

Ed Willink

Re: Problem with OCL and Xtend code generator project [message #1777572 is a reply to message #1776865] Thu, 30 November 2017 12:02 Go to previous messageGo to next message
Ambreen Hussain is currently offline Ambreen HussainFriend
Messages: 8
Registered: September 2012
Junior Member
Hi Ed,
I tried all above and got the same error EPackageImpl. Thanks for your inputs. But because of the problems I am now using Acceleo instead of Xtend for code generation. Eclipse Neon generates code in Java with validator.java file for OCL constraints. My question is it possible to use this file for validation of generated code using Acceleo. Or is there any other way to use OCL constraints written for Model in generated code using Acceleo. I read this question at https://www.eclipse.org/forums/index.php/t/200179/ but that was 7 years ago and you said in this post that "A flexible OCL to Java or ... code generator is planned for MDT/OCL; not sure when." Did you mean by this validator.java class? or is there a way to generate code from OCL constraints into Java using Acceleo?
Many Thanks,
Re: Problem with OCL and Xtend code generator project [message #1777576 is a reply to message #1777572] Thu, 30 November 2017 13:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

My first attempts at OCL2Java used Acceleo but limitations in Acceleo and the complexity of the problem meant that a simple M2T is totally inappropriate. By the time there is a significant M2M prelude the subsequent M2T is less relevant. The current OCL2Java is almost entirely manual Java code exploiting Xtend-generated Visitor hierarchies. My next rewrite will change from AS2CG2JavaText using Java to AS2CG2JavaModel2JavaText using QVTr defined M2M and hopefully a standard JavaModel2JavaText. If that standard JavaModel2JavaText is available in Acceleo I may well use it.

The OCL2Java code generator has been available for about 4 years now.

Acceleo as with most EMF applications should not care about the particular technologies used by user models. Even if you use the JavaScript variant of model validation, Acceleo should just work because it's all hidden behind the EMF API.

Regards

Ed Willink
Re: Problem with OCL and Xtend code generator project [message #1777698 is a reply to message #1777576] Fri, 01 December 2017 17:13 Go to previous messageGo to next message
Ambreen Hussain is currently offline Ambreen HussainFriend
Messages: 8
Registered: September 2012
Junior Member
Dear Ed,
Can you please tell me where I can find OCL2Java code generator. Searched on it but couldn't find it.
Many Thanks,
Ambreen
Re: Problem with OCL and Xtend code generator project [message #1777701 is a reply to message #1777698] Fri, 01 December 2017 18:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
HI

For OCLinEcore it's integrated into EMF GenModel. See the CG section of the OCLinEcore tutorial.

For other purposes you may produce a variant derivation of the various org.eclipse.ocl.examples.codegen AS2CG and CG2Java classes. QVTd does this.

Regards

Ed Willink
Re: Problem with OCL and Xtend code generator project [message #1777720 is a reply to message #1777701] Sat, 02 December 2017 13:33 Go to previous message
Ambreen Hussain is currently offline Ambreen HussainFriend
Messages: 8
Registered: September 2012
Junior Member
Hi Ed,
Thanks for your help.

Ambreen
Previous Topic:What is the license of the generated code
Next Topic:resolution of uriFragment '|29' failed.
Goto Forum:
  


Current Time: Sun Sep 23 00:13:46 GMT 2018

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

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

Back to the top