Skip to main content



      Home
Home » Modeling » OCL » OCL generator and EMF super types
OCL generator and EMF super types [message #1774435] Sat, 14 October 2017 06:25 Go to next message
Eclipse UserFriend
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="http://www.eclipse.org/OCL/GenModel">
    <details key="Use Delegates" value="false"/>
  </genAnnotations>


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:

index.php/fa/31004/0/

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

Quote:

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 06:42] by Moderator

Re: OCL generator and EMF super types [message #1774437 is a reply to message #1774435] Sat, 14 October 2017 08:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi

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.

Regards

Ed Willink
Re: OCL generator and EMF super types [message #1774443 is a reply to message #1774437] Sat, 14 October 2017 13:44 Go to previous message
Eclipse UserFriend
Thanks Ed for your feedback.

please refer to the following link https://bugs.eclipse.org/bugs/show_bug.cgi?id=526041
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: Thu Apr 24 19:59:16 EDT 2025

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

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

Back to the top