Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Generating Java code for OCL constraints
Generating Java code for OCL constraints [message #1028575] Thu, 28 March 2013 12:54 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

I'm trying to generate Java code instead of String which are compiled at run-time for my OCL constraints.
I followed the explanations described here: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCodeGenerationTutorial.html (the two approaches) but my generated code still doesn't contain java code for the constraints (they are still generated as strings).

The reason why I would like to have this is to be able to debug a bit more easily my OCL constraints.

I am using OCLinEcore to edit my domain model with the OCL constraints.

Thanks,
Cédric
Re: Generating Java code for OCL constraints [message #1028598 is a reply to message #1028575] Thu, 28 March 2013 13:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The Juno code geneerator was exoperimental. The Kepler CG is thoroughly
tested with much more efficient code generated directly into the *Impl
files.

I recall some stupidity in the setup, so use at least the M6 OCL release.

If nothing happens please post your example.

Regards

Ed Willink


On 28/03/2013 12:54, Cedric Moonen wrote:
> Hello,
>
> I'm trying to generate Java code instead of String which are compiled
> at run-time for my OCL constraints.
> I followed the explanations described here:
> http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCodeGenerationTutorial.html
> (the two approaches) but my generated code still doesn't contain java
> code for the constraints (they are still generated as strings).
>
> The reason why I would like to have this is to be able to debug a bit
> more easily my OCL constraints.
>
> I am using OCLinEcore to edit my domain model with the OCL constraints.
>
> Thanks,
> Cédric
Re: Generating Java code for OCL constraints [message #1029183 is a reply to message #1028598] Fri, 29 March 2013 09:12 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hi Ed,

Thanks for the reply.

I downloaded Kepler and installed the latest build from OCL tools (via this update site: http://download.eclipse.org/modeling/mdt/ocl/updates/nightly).

For my domain model, it still doesn't generate java code in the classes. However, I tried with a very simple example and there it generates java code. However, if I add an invariant, the code generator throws an exception: "Failed to pre-generate ComponentsTest constraints" with the following stack trace:

java.lang.NullPointerException
	at org.eclipse.ocl.examples.codegen.expression.OCLinEcore2JavaBodies.generateClassBodies(OCLinEcore2JavaBodies.java:200)
	at org.eclipse.ocl.examples.codegen.expression.OCLinEcore2JavaBodies.generateBodies(OCLinEcore2JavaBodies.java:181)
	at org.eclipse.ocl.examples.codegen.ecore.OCLGenModelGeneratorAdapter.createFeatureBodies(OCLGenModelGeneratorAdapter.java:271)
	at org.eclipse.ocl.examples.codegen.ecore.OCLGenModelGeneratorAdapter.doPreGenerate(OCLGenModelGeneratorAdapter.java:308)
	at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.preGenerate(AbstractGeneratorAdapter.java:282)
	at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:646)
	at org.eclipse.emf.codegen.ecore.genmodel.presentation.GeneratorUIUtil$GeneratorOperation.execute(GeneratorUIUtil.java:161)
	at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)


You can find the domain model and the corresponding gen model in attachment.

For privacy reasons, I'll send you my complete domain model via mail.

Regards,
Cédric
Re: Generating Java code for OCL constraints [message #1031210 is a reply to message #1029183] Mon, 01 April 2013 11:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Cedric

On 29/03/2013 09:12, Cedric Moonen wrote:
> For my domain model, it still doesn't generate java code in the classes.
Your model has nested packages! And to make life more challenging a
classifier-less root package

[I hope Ed Merks isn't reading this.]

As always, nested classes expose incompetent programming/inadequate testing.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=404660.

Regards

Ed Willink
Re: Generating Java code for OCL constraints [message #1031416 is a reply to message #1031210] Mon, 01 April 2013 18:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The latest N-build fixes this and also some other issues shown up by
your model.

Regards

Ed Willink

On 01/04/2013 12:07, Ed Willink wrote:
> See https://bugs.eclipse.org/bugs/show_bug.cgi?id=404660.
Re: Generating Java code for OCL constraints [message #1148792 is a reply to message #1031416] Mon, 21 October 2013 18:57 Go to previous messageGo to next message
Stephan Krusche is currently offline Stephan KruscheFriend
Messages: 18
Registered: September 2012
Junior Member
I have a similar problem when I try to generate code from a genmodel with OCL constraints, invariants, derived features and operations...
I'm using Kepler and tried OCL 4.1.0 and OCL 4.1.1 with the option "Generate Java Code in xxxBodies classes"

A simple model works, but a more complex one leads to a null pointer exception with the following stack trace:

java.lang.NullPointerException: null source for mapping to org.eclipse.ocl.examples.codegen.cgmodel.CGValuedElement
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.doVisit(Pivot2CGVisitor.java:268)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitConstraint(Pivot2CGVisitor.java:484)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitConstraint(Pivot2CGVisitor.java:1)
	at org.eclipse.ocl.examples.pivot.internal.impl.ConstraintImpl.accept(ConstraintImpl.java:473)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.doVisit(Pivot2CGVisitor.java:270)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitClass(Pivot2CGVisitor.java:424)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitClass(Pivot2CGVisitor.java:1)
	at org.eclipse.ocl.examples.pivot.internal.impl.ClassImpl.accept(ClassImpl.java:797)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.doVisit(Pivot2CGVisitor.java:270)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitPackage(Pivot2CGVisitor.java:883)
	at org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitPackage(Pivot2CGVisitor.java:1)
	at org.eclipse.ocl.examples.pivot.internal.impl.PackageImpl.accept(PackageImpl.java:876)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCG2JavaVisitor.<init>(OCLinEcoreCG2JavaVisitor.java:78)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCodeGenerator.<init>(OCLinEcoreCodeGenerator.java:101)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGenModelGeneratorAdapter.createFeatureBodies(OCLinEcoreGenModelGeneratorAdapter.java:245)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGenModelGeneratorAdapter.doPreGenerate(OCLinEcoreGenModelGeneratorAdapter.java:288)
	at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.preGenerate(AbstractGeneratorAdapter.java:282)
	at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:646)
	at org.eclipse.emf.codegen.ecore.genmodel.presentation.GeneratorUIUtil$GeneratorOperation.execute(GeneratorUIUtil.java:161)
	at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)


Any ideas what issue can lead to the above stack trace?
Re: Generating Java code for OCL constraints [message #1149641 is a reply to message #1148792] Tue, 22 October 2013 07:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The "null source" may be

a genuinely missing call expression source; have you validated your OCL
in the OCLinEcore editor
an unsuitable Constraint context
a bug in the handling of implicit source; I've fixed a couple recently

Can you post a project, or email me a link so I can check.

Regards

Ed Willink

On 21/10/2013 19:57, Stephan Krusche wrote:
> I have a similar problem when I try to generate code from a genmodel
> with OCL constraints, invariants, derived features and operations...
> I'm using Kepler and tried OCL 4.1.0 and OCL 4.1.1 with the option
> "Generate Java Code in xxxBodies classes"
>
> A simple model works, but a more complex one leads to a null pointer
> exception with the following stack trace:
>
>
> java.lang.NullPointerException: null source for mapping to
> org.eclipse.ocl.examples.codegen.cgmodel.CGValuedElement
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.doVisit(Pivot2CGVisitor.java:268)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitConstraint(Pivot2CGVisitor.java:484)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitConstraint(Pivot2CGVisitor.java:1)
> at
> org.eclipse.ocl.examples.pivot.internal.impl.ConstraintImpl.accept(ConstraintImpl.java:473)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.doVisit(Pivot2CGVisitor.java:270)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitClass(Pivot2CGVisitor.java:424)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitClass(Pivot2CGVisitor.java:1)
> at
> org.eclipse.ocl.examples.pivot.internal.impl.ClassImpl.accept(ClassImpl.java:797)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.doVisit(Pivot2CGVisitor.java:270)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitPackage(Pivot2CGVisitor.java:883)
> at
> org.eclipse.ocl.examples.codegen.analyzer.Pivot2CGVisitor.visitPackage(Pivot2CGVisitor.java:1)
> at
> org.eclipse.ocl.examples.pivot.internal.impl.PackageImpl.accept(PackageImpl.java:876)
> at
> org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCG2JavaVisitor.<init>(OCLinEcoreCG2JavaVisitor.java:78)
> at
> org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCodeGenerator.<init>(OCLinEcoreCodeGenerator.java:101)
> at
> org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGenModelGeneratorAdapter.createFeatureBodies(OCLinEcoreGenModelGeneratorAdapter.java:245)
> at
> org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGenModelGeneratorAdapter.doPreGenerate(OCLinEcoreGenModelGeneratorAdapter.java:288)
> at
> org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.preGenerate(AbstractGeneratorAdapter.java:282)
> at
> org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:646)
> at
> org.eclipse.emf.codegen.ecore.genmodel.presentation.GeneratorUIUtil$GeneratorOperation.execute(GeneratorUIUtil.java:161)
> at
> org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
> at
> org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
> at
> org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
>
>
> Any ideas what issue can lead to the above stack trace?
Re: Generating Java code for OCL constraints [message #1219538 is a reply to message #1031416] Wed, 04 December 2013 14:01 Go to previous messageGo to next message
Conchi Sanz is currently offline Conchi SanzFriend
Messages: 10
Registered: December 2013
Junior Member

Hello,


I am also trying to generate Java code from an ecore with OCL constraints, having some problems about that.

Generating Java code from a basic ecore with OCL constraints works fine at first. However, when the ecore contains several packages, the generated code does not include any delegate code for OCL constraints. Since it seems that the latest OCL version fixes this problem, I have updated Kepler to use OCL 4.2.0M3, but no success.

Furthermore, once you generate Java code for an ecore with nested packages, it seems that OCL constraints are always ignored in the following code generations, even for very simple ecores (without nested packages).


Any help will be welcome.

Thanks,
Conchi

PD: an example of the kind of ecore I want to develop is attached.
  • Attachment: My.ecore
    (Size: 3.14KB, Downloaded 398 times)
Re: Generating Java code for OCL constraints [message #1219610 is a reply to message #1219538] Wed, 04 December 2013 22:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Java CG for multiple package models was fixed a few months ago.

Your example works fine for me with Use Delegates true/false.

Your other comments are too vague for me to react to. For some changes
you need to exit and restart the genmodel editor since the OCL code is
generated as an in-memory model update.

Regards

Ed Willink

On 04/12/2013 14:59, Conchi Sanz wrote:
> Hello,
>
>
> I am also trying to generate Java code from an ecore with OCL constraints, having some problems about that.
>
> Generating Java code from a basic ecore with OCL constraints works fine at first. However, when the ecore contains several packages, the generated code does not include any delegate code for OCL constraints. Since it seems that the latest OCL version fixes this problem, I have updated Kepler to use OCL 4.2.0M3, but no success.
>
> Furthermore, once you generate Java code for an ecore with nested packages, it seems that OCL constraints are always ignored in the following code generations, even for very simple ecores (without nested packages).
>
>
> Any help will be welcome.
>
> Thanks,
> Conchi
>
> PD: an example of the kind of ecore I want to develop is attached.
Re: Generating Java code for OCL constraints [message #1760977 is a reply to message #1219610] Thu, 04 May 2017 20:18 Go to previous message
lina jana is currently offline lina janaFriend
Messages: 1
Registered: May 2017
Junior Member

cliquer sur le model gmf.gen >generate diagram code (X tend2)
Smile Smile Smile Smile Smile
Previous Topic:An Error when loading and OCL File for verification
Next Topic:Setting non-blank root/package URIs in Papyrus
Goto Forum:
  


Current Time: Thu Apr 18 02:30:30 GMT 2024

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

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

Back to the top