Skip to main content



      Home
Home » Modeling » OCL » OCLinEclipse Discarding Tuple Type Information on Operations
icon8.gif  OCLinEclipse Discarding Tuple Type Information on Operations [message #1705392] Fri, 14 August 2015 10:12 Go to next message
Eclipse UserFriend
Hi,

If I create a new ECore file and edit it with the OCLinEcore editor and add the following content...

package MOD : mod = 'http://localhost/'
{
	class Foo
	{
		operation foo() : Tuple(m: Integer, n: Integer)
		{
			body: Tuple{m:Integer = 5, n:Integer = 5};
		}
	}
}


...it type-checks fine. However, if I save, close and then reopen the file I get this:

package MOD : mod = 'http://localhost/'
{
	class Foo
	{
		operation foo()
		{
			body: Tuple{m:Integer = 5, n:Integer = 5};
		}
	}
}


...which doesn't typecheck because the return type of foo has been discarded for some unknown reason. Is this something I am doing incorrectly?

Best wishes,
Keith
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1705419 is a reply to message #1705392] Fri, 14 August 2015 18:02 Go to previous messageGo to next message
Eclipse UserFriend
HI

This is a known limitation.

Ecore has no equivalent of an OCL Tuple and I have not yet figured out
how to fudge it. Not a high priority.

I suggest that you define a proper class.

Regards

Ed Willink


On 14/08/2015 16:39, Keith Ó Dúlaigh wrote:
> Hi,
>
> If I create a new ECore file and edit it with the OCLinEcore editor
> and add the following content...
>
>
> package MOD : mod = 'http://localhost/'
> {
> class Foo
> {
> operation foo() : Tuple(m: Integer, n: Integer)
> {
> body: Tuple{m:Integer = 5, n:Integer = 5};
> }
> }
> }
>
>
> ..it type-checks fine. However, if I save, close and then reopen the
> file I get this:
>
>
> package MOD : mod = 'http://localhost/'
> {
> class Foo
> {
> operation foo()
> {
> body: Tuple{m:Integer = 5, n:Integer = 5};
> }
> }
> }
>
>
> ..which doesn't typecheck because the return type of foo has been
> discarded for some unknown reason. Is this something I am doing
> incorrectly?
>
> Best wishes,
> Keith
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1705420 is a reply to message #1705419] Fri, 14 August 2015 18:34 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the reply and suggestion Ed.

All the best,
Keith
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1707014 is a reply to message #1705419] Tue, 01 September 2015 09:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Related to this question. Suppose I have created a class TupleIntInt similar to the following code. Then can I use OCL to construct a new instance of TupleIntInt?

class TupleIntInt
{
	property m : Integer;
	property n : Integer;
	
       operation create() : TupleIntInt[1]
      {
          body: TupleIntInt{m = 1, n = 2};		
      }
}


Constructing a new object always returns "invalid" when I attempt to construct a new object.

I note in an earlier post there is a link to a bug report that says "...pivot now has a prototype of type constructors."


Thanks,
Keith

=====================================
Earlier related post:

https://www.eclipse.org/forums/index.php/t/543504/
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1707024 is a reply to message #1707014] Tue, 01 September 2015 10:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi

It should work, but rather more simply than you have suggested. OCL has
no mutation, so no constructors. The prototyped behavior is just direct
initialization with explicit/default values.

class TupleIntInt
{
property m : Integer;
property n : Integer;
}

let aTII = TupleIntInt{m = 1, n = 2} in aTII.m * aTII.n

The current prototype is inaccurate wrt to the shadow semantics that
requires shared copies, so

TupleIntInt{m = 1, n = 2} = TupleIntInt{m = 1, n = 2}

should be unequivocably true. It is false when executed using the OCL
interpreter. It is perhaps true if the code generator is given an
opportunity to do common subexpression elimination. Fixed on a WIP branch.

Regards

Ed Willink



On 01/09/2015 14:51, Keith Ó Dúlaigh wrote:
> Hi,
>
> Related to this question. Suppose I have created a class TupleIntInt
> similar to the following code. Then can I use OCL to construct a new
> instance of TupleIntInt?
>
> class TupleIntInt
> {
> property m : Integer;
> property n : Integer;
>
> operation create() : TupleIntInt[1]
> {
> body: TupleIntInt{m = 1, n = 2};
> }
> }
>
>
> Constructing a new object always returns "invalid" when I attempt to
> construct a new object.
>
> I note in an earlier post there is a link to a bug report that says
> "...pivot now has a prototype of type constructors."
>
>
> Thanks,
> Keith
>
> =====================================
> Earlier related post:
>
> https://www.eclipse.org/forums/index.php/t/543504/
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1707035 is a reply to message #1707024] Tue, 01 September 2015 11:48 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Ed, maybe my Java code is the problem because I still have "invalid" being returned.

My full OCL looks like this...

package example : web = 'URL REMOVED BECAUSE I'VE < 5 POSTS'
{
	class TupleIntInt
	{
		operation test() : Integer
		{
			body: let ai = TupleIntInt{m= 5, n = 1} 
			      in ai.m * ai.n;
		}
		operation test2() : Integer
		{
			body: 5;
		}
		operation test3() : TupleIntInt[1]
		{
			body: TupleIntInt{m= 5, n = 1};
		}		 
		attribute m : Integer[?];
		attribute n : Integer[?];
	}
}


...and my Java like this:

package main;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EParameter;
import org.eclipse.ocl.OCL;
import org.eclipse.ocl.ParserException;
import org.eclipse.ocl.Query;
import org.eclipse.ocl.ecore.Constraint;
import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
import org.eclipse.ocl.expressions.OCLExpression;
import org.eclipse.ocl.helper.OCLHelper;

import example.ExampleFactory;

public class Application {

	public static void main(String... args) {
		ExampleFactory.eINSTANCE.eClass();

		Object o = runOcl("test2()");		
		System.out.println(o);
		
		o = runOcl("test()");		
		System.out.println(o);
		
		o = runOcl("test3()");		
		System.out.println(o);
	}

	private static Object runOcl(String queryText) {
		OCL<?, EClassifier, ?, ?, ?, EParameter, ?, ?, ?, Constraint, EClass, EObject> ocl = OCL
				.newInstance(EcoreEnvironmentFactory.INSTANCE);
		OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper();
		helper.setContext(ExampleFactory.eINSTANCE.createTupleIntInt().eClass());

		Query<EClassifier, EClass, EObject> query = null;

		try {
			OCLExpression<EClassifier> expression = helper.createQuery(queryText);
			query = ocl.createQuery(expression);
		} catch (ParserException error) {

			throw new RuntimeException(error);
		}

		return query.evaluate(ExampleFactory.eINSTANCE);
	}
}


Running the Java code yields:

5
invalid
invalid

[Updated on: Tue, 01 September 2015 11:49] by Moderator

Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1707040 is a reply to message #1707035] Tue, 01 September 2015 13:16 Go to previous messageGo to next message
Eclipse UserFriend
Hi

On 01/09/2015 16:48, Keith Ó Dúlaigh wrote:
> OCLHelper<EClassifier, ?, ?, Constraint>
This is a dead give-away.

The Classic Ecore/UML OCL has long template parameter lists.

The Pivot OCL has very limited parameter lists.

Only the Pivot-based OCL prototypes new OCL facilities.

Regards

Ed Willink
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1707097 is a reply to message #1707040] Wed, 02 September 2015 06:12 Go to previous message
Eclipse UserFriend
Okay thanks again Ed. It works now.

The updated Java code is:

package main;

import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
import org.eclipse.ocl.pivot.ExpressionInOCL;
import org.eclipse.ocl.pivot.utilities.OCL;
import org.eclipse.ocl.pivot.utilities.OCLHelper;
import org.eclipse.ocl.pivot.utilities.ParserException;
import org.eclipse.ocl.xtext.essentialocl.EssentialOCLStandaloneSetup;

import example.ExampleFactory;
import example.ExamplePackage;
import example.TupleIntInt;

public class Application {

	public static void main(String... args) throws ParserException {
		ExampleFactory.eINSTANCE.eClass();

		Object o;

		o = runOcl("test2()");
		System.out.println(o);

		o = runOcl("test()");
		System.out.println(o);

		o = runOcl("test3()");
		System.out.println(o);
	}

	private static Object runOcl(String queryText) throws ParserException {
		EPackage.Registry registry = new EPackageRegistryImpl();
		registry.put(ExamplePackage.eNS_URI, ExamplePackage.eINSTANCE);

		EssentialOCLStandaloneSetup.doSetup();

		OCL ocl = OCL.newInstance(registry);
		TupleIntInt example = ExampleFactory.eINSTANCE.createTupleIntInt();
		OCLHelper helper = ocl.createOCLHelper(ExamplePackage.Literals.TUPLE_INT_INT);
		ExpressionInOCL expression = helper.createQuery(queryText);
		Object result = ocl.evaluate(example, expression);

		return result;
	}
}


The OCL code remaines the same as above and the dependencies required are:

1. org.eclipse.core.runtime
2. org.eclipse.emf.ecore
3. org.eclipse.emf
4. org.eclipse.ocl.pivot
5. org.apache.log4j
6. com.google.guava
7. com.google.inject
8. org.eclipse.ocl.xtext.essentialocl

Previous Topic:Some random errors
Next Topic:Unable to resolve OCL pivot variable types in standalone mode when browsing abstract syntax
Goto Forum:
  


Current Time: Tue Jul 01 00:44:05 EDT 2025

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

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

Back to the top