Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL generator and EMF super types
OCL generator and EMF super types [message #1774435] Sat, 14 October 2017 10:25 Go to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Hi all,

I detect a strange behavior during the EMF generation when I have OCL constraints generated in the EMF java code.

So, I have a first metamodel

package metamodel : metamodel = 'http://metamodel'
	class ClassA extends Class
		attribute name : String[?];
		invariant name_inv: name <> 'test';
	class Class;

In the associated genmodel, I add this annotation

  <genAnnotations source="">
    <details key="Use Delegates" value="false"/>

EMF generation works perfectly, and I code of my name_inv is generated:
public boolean name_inv(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
		 * inv name_inv:
		 *   let severity : Integer[1] = 'ClassA::name_inv'.getSeverity()
		 *   in
		 *     if severity <= 0
		 *     then true
		 *     else
		 *       let result : Boolean[1] = name <> 'test'
		 *       in
		 *         'ClassA::name_inv'.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0)
		 *     endif
		final /*@NonInvalid*/ Executor executor = PivotUtilInternal.getExecutor(this);
		final /*@NonInvalid*/ IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, MetamodelTables.STR_ClassA_c_c_name_inv);
		final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, MetamodelTables.INT_0).booleanValue();
		/*@NonInvalid*/ boolean symbol_0;
		if (le) {
			symbol_0 = ValueUtil.TRUE_VALUE;
		else {
			final /*@NonInvalid*/ String name = this.getName();
			final /*@NonInvalid*/ boolean result = !MetamodelTables.STR_test.equals(name);
			final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, MetamodelTables.STR_ClassA_c_c_name_inv, this, (Object)null, diagnostics, context, (Object)null, severity_0, result, MetamodelTables.INT_0).booleanValue();
			symbol_0 = logDiagnostic;
		return Boolean.TRUE == symbol_0;

Now, I have this second metamodel:

import metamodel : '../../metamodel.emf/model/Metamodel.ecore#/' ;

package metamodel2 : metamodel2 = 'http://metamodel2'
	class ClassB extends metamodel::Class,metamodel::ClassA;

So, I have this diagram:


When I generate the EMF model code of the second metamodel,
I obtain errors on ClassBImpl class saying that:


The type ClassBImpl must implement the inherited abstract method ClassA.name_inv(DiagnosticChain, Map<Object,Object>)

To resolve it, I add the unimplemented method using the quick fix.

HOWEVER, when I edit my second metamodel by changing the order of the extended classes,

import metamodel : '../../metamodel.emf/model/Metamodel.ecore#/' ;

package metamodel2 : metamodel2 = 'http://metamodel2'
	class ClassB extends metamodel::ClassA, metamodel::Class;

the generation works perfectly without errors.

So, my questions are:

Is that a OCL generation bug?
Otherwise, Is the order of extended classes important?
and must conform to a specific representation enforced by EMF and OCL ?

[Updated on: Sat, 14 October 2017 10:42]

Report message to a moderator

Re: OCL generator and EMF super types [message #1774437 is a reply to message #1774435] Sat, 14 October 2017 12:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7663
Registered: July 2009
Senior Member

I'm inclined to blame EMF2Java. Java only supports one super class and many super interfaces but EMF models many super classes and has to re-implement concrete functionality from non-first superclasses. By putting the 'better' ClassA second you required EMF to re-synthesize ClassA::name_inv that was only inherited as an interface into ClassB::name_inv.

Hm. The OCL2Java code generator could understand this limitation and re-synthesize for you. Could you attach a small repro to a Bugzilla that I might get round to. Cannot promise to do so soon since you have an easy workaround.


Ed Willink
Re: OCL generator and EMF super types [message #1774443 is a reply to message #1774437] Sat, 14 October 2017 17:44 Go to previous message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Thanks Ed for your feedback.

please refer to the following link
Previous Topic:Programmatically run OCL queries with multiple meta-models produces unknown type errors
Next Topic:Is is possible to install OCL without installing UML?
Goto Forum:

Current Time: Sun Jul 14 20:31:36 GMT 2024

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

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

Back to the top