Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Generate Java code for generic classes
Generate Java code for generic classes [message #1837493] Mon, 01 February 2021 05:57 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 346
Registered: August 2013
Senior Member
Hi

Here is a sample project https://github.com/AresEkb/ocl_generic_class_test

The model contains a generic class and a derived reference with OCL expression.

The OCLinEcore editor shows the following error:
"java.lang.IllegalArgumentException: Incorrect template bindings for template type"
index.php/fa/39871/0/

And also when I run a genmodel I get the error "Failed to pre-generate ocl_generic_class_test constraints" with exception:

java.lang.UnsupportedOperationException
	at org.eclipse.ocl.pivot.internal.library.executor.AbstractIdResolver.visitClassId(AbstractIdResolver.java:1647)
	at org.eclipse.ocl.pivot.internal.library.executor.AbstractIdResolver.visitClassId(AbstractIdResolver.java:1)
	at org.eclipse.ocl.pivot.internal.ids.GeneralizedClassIdImpl.accept(GeneralizedClassIdImpl.java:27)
	at org.eclipse.ocl.pivot.internal.library.executor.AbstractIdResolver.getClass(AbstractIdResolver.java:773)
	at org.eclipse.ocl.examples.codegen.java.types.BoxedValuesDescriptor.getEcoreDescriptor(BoxedValuesDescriptor.java:101)
	at org.eclipse.ocl.examples.codegen.java.JavaCodeGenerator.getTypeDescriptor(JavaCodeGenerator.java:437)
	at org.eclipse.ocl.examples.codegen.java.JavaCodeGenerator.isPrimitive(JavaCodeGenerator.java:506)
	at org.eclipse.ocl.examples.codegen.java.JavaStream.isPrimitive(JavaStream.java:1214)
	at org.eclipse.ocl.examples.codegen.java.CG2JavaVisitor.appendCGEcorePropertyCallExp(CG2JavaVisitor.java:257)
	at org.eclipse.ocl.examples.codegen.java.CG2JavaVisitor.visitCGEcorePropertyCallExp(CG2JavaVisitor.java:1679)
	at org.eclipse.ocl.examples.codegen.java.CG2JavaVisitor.visitCGEcorePropertyCallExp(CG2JavaVisitor.java:1)
	at org.eclipse.ocl.examples.codegen.cgmodel.impl.CGEcorePropertyCallExpImpl.accept(CGEcorePropertyCallExpImpl.java:162)
	at org.eclipse.ocl.examples.codegen.java.JavaStream.appendLocalStatements(JavaStream.java:933)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCG2JavaVisitor.generateBody(OCLinEcoreCG2JavaVisitor.java:173)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCG2JavaVisitor.generateBodies(OCLinEcoreCG2JavaVisitor.java:149)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCodeGenerator.generate(OCLinEcoreCodeGenerator.java:413)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreCodeGenerator.generatePackage(OCLinEcoreCodeGenerator.java:356)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGenModelGeneratorAdapter$OCLinEcoreStateAdapter.createFeatureBodies(OCLinEcoreGenModelGeneratorAdapter.java:485)
	at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGenModelGeneratorAdapter.doPreGenerate(OCLinEcoreGenModelGeneratorAdapter.java:712)
	at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.preGenerate(AbstractGeneratorAdapter.java:285)
	at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:735)
	at org.eclipse.emf.codegen.ecore.genmodel.presentation.GeneratorUIUtil$GeneratorOperation.execute(GeneratorUIUtil.java:178)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.lambda$0(WorkspaceModifyOperation.java:110)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:131)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)


Does Java code generator support generic classes?
Re: Generate Java code for generic classes [message #1837503 is a reply to message #1837493] Mon, 01 February 2021 09:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7665
Registered: July 2009
Senior Member
Hi

https://bugs.eclipse.org/bugs/show_bug.cgi?id=570802 raised.

Regards

Ed Willink
Re: Generate Java code for generic classes [message #1837525 is a reply to message #1837503] Mon, 01 February 2021 19:14 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7665
Registered: July 2009
Senior Member
Hi

Fixed in 6.14.0M2 which is available now.

Regards

Ed Willink
Re: Generate Java code for generic classes [message #1837540 is a reply to message #1837525] Tue, 02 February 2021 04:08 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 346
Registered: August 2013
Senior Member
Thanks a lot! I've checked, it works!

However it seems that it generates wrong Java code:
	public EList<BaseGeneric<?>> getGenericsA() {
		/**
		 * self.generics
		 */
		final /*@NonInvalid*/ List<BaseGeneric> generics = this.getGenerics();
		return (EList<BaseGeneric>) generics;
	}


I guess that BaseGeneric should be replaced by BaseGeneric<?>:
	public EList<BaseGeneric<?>> getGenericsA() {
		/**
		 * self.generics
		 */
		final /*@NonInvalid*/ List<BaseGeneric<?>> generics = this.getGenerics();
		return (EList<BaseGeneric<?>>) generics;
	}
Re: Generate Java code for generic classes [message #1837595 is a reply to message #1837540] Tue, 02 February 2021 23:14 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7665
Registered: July 2009
Senior Member
Hi

Fixed in latest N-build.

http://www.eclipse.org/modeling/download.php?file=/modeling/mdt/ocl/downloads/drops/6.14.0/N202102022250/mdt-ocl-Update-N202102022250.zip

Regards

Ed Willink
Re: Generate Java code for generic classes [message #1837597 is a reply to message #1837595] Wed, 03 February 2021 04:25 Go to previous message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 346
Registered: August 2013
Senior Member
Thanks again! Everything works!
Previous Topic:Missing Javadoc
Next Topic:Issue with mdt-ocl-Update sites
Goto Forum:
  


Current Time: Sun Jul 21 10:50:59 GMT 2024

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

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

Back to the top