Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » error when resolving the type of a variable
error when resolving the type of a variable [message #1070370] Wed, 17 July 2013 20:41 Go to next message
felix Kurth is currently offline felix KurthFriend
Messages: 5
Registered: July 2013
Junior Member
Hey I encountered a really wired problem when trying to parse an ocl invariant or postcondition with an ocl Helper. With the Peace of code at the end of the post the parsing works well as long as the line
		//p.getType(); // THIS CAUSES THE ERROR
stays commented out. Whenever there has been a call to getType() before the ocl parser can not figure out the type of the Property correctly and will give an error message saying
Cannot find operation (>=(Integer)) for the type (null)
I found two workarounds for that:
1: in this minimal code example you could just replace the line causing the error by
((PropertyImpl) p).basicGetType();
this works for that example but fails when you want to evaluate several Constraints on the same model since OCL itself calls the function getType().
2: another workaround that seemed to work for me was not using the UMLPrimitiveType library. Instead you need to model Basic Datatypes with the names Integer, Boolean ... In this case it is crucial to use exactly the same names as in the UMLPrimitiveTypeLibrary.

Now my Questions: is this a bug in OCL? or did i just do something that was not intendet? Are there better ways to solve this problem?

I attached a simple model and a peace of code reproducing the error.
	public static void main(String[] args) throws ParserException, IOException {
		// Loading the Resource
		ResourceSet RESOURCE_SET = new ResourceSetImpl();
		UMLResourcesUtil.init(RESOURCE_SET); // MDT/UML2 4.0.0 (Juno)
		Resource resource = RESOURCE_SET.createResource(URI
				.createFileURI("src/oclBugMinimal/Model.uml"));
		resource.load(null);

		// navigating through the model finding context elements
		Model model = (Model) resource.getContents().get(0);
		Class class1 = (Class) model.getPackagedElement("Class1");

		for (Property p : class1.getOwnedAttributes()) {
			//p.getType(); // THIS CAUSES THE ERROR
		}

		// Try parsing a simple ocl constraint
		OCL ocl = OCL.newInstance();
		Helper helper = ocl.createOCLHelper();
		helper.setContext(class1);
		helper.createInvariant("x>=5");

	}

The content of the model file is the following:
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="20110701" xmlns:xmi="HTTPECLIPSEORG/spec/XMI/20110701" xmlns:uml="HTTPECLIPSEORG/uml2/4.0.0/UML" xmi:id="_824b49cf-8739-46e1-946f-01fe7db160ef" name="SomeActivityDiagrams">
  <packagedElement xmi:type="uml:Class" xmi:id="_b46209c4-a730-4f9c-8663-740dd5f97be7" name="Class1">
    <ownedAttribute xmi:id="_02d2fb85-4294-44cb-a4ff-aaff3731fe83" name="x" visibility="private" aggregation="composite">
      <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
    </ownedAttribute>
  </packagedElement>
</uml:Model>
Re: error when resolving the type of a variable [message #1070524 is a reply to message #1070370] Thu, 18 July 2013 06:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The wierd definitely seems like a bug.

You omitted the package imports so I cannot be sure that you're using
the new PIvot-based OCL, however I have fixed a problem with unifying
the many different primitive types in the last couple of weeks. So you
might try downloading the latest I-build from
http://www.eclipse.org/modeling/download.php?file=/modeling/mdt/ocl/downloads/drops/4.2.0/I201307170419/mdt-ocl-Update-tools-I201307170419.zip.

Regards

Ed Willink


On 17/07/2013 21:48, felix Kurth wrote:
> Hey I encountered a really wired problem when trying to parse an ocl
> invariant or postcondition with an ocl Helper. With the Peace of code
> at the end of the post the parsing works well as long as the
> line //p.getType(); // THIS CAUSES THE ERROR stays commented
> out. Whenever there has been a call to getType() before the ocl parser
> can not figure out the type of the Property correctly and will give an
> error message saying Cannot find operation (>=(Integer)) for the type
> (null) I found two workarounds for that:
> 1: in this minimal code example you could just replace the line
> causing the error by ((PropertyImpl) p).basicGetType(); this works for
> that example but fails when you want to evaluate several Constraints
> on the same model since OCL itself calls the function getType().
> 2: another workaround that seemed to work for me was not using the
> UMLPrimitiveType library. Instead you need to model Basic Datatypes
> with the names Integer, Boolean ... In this case it is crucial to use
> exactly the same names as in the UMLPrimitiveTypeLibrary.
>
> Now my Questions: is this a bug in OCL? or did i just do something
> that was not intendet? Are there better ways to solve this problem?
>
> I attached a simple model and a peace of code reproducing the error.
> public static void main(String[] args) throws ParserException,
> IOException {
> // Loading the Resource
> ResourceSet RESOURCE_SET = new ResourceSetImpl();
> UMLResourcesUtil.init(RESOURCE_SET); // MDT/UML2 4.0.0 (Juno)
> Resource resource = RESOURCE_SET.createResource(URI
> .createFileURI("src/oclBugMinimal/Model.uml"));
> resource.load(null);
>
> // navigating through the model finding context elements
> Model model = (Model) resource.getContents().get(0);
> Class class1 = (Class) model.getPackagedElement("Class1");
>
> for (Property p : class1.getOwnedAttributes()) {
> //p.getType(); // THIS CAUSES THE ERROR
> }
>
> // Try parsing a simple ocl constraint
> OCL ocl = OCL.newInstance();
> Helper helper = ocl.createOCLHelper();
> helper.setContext(class1);
> helper.createInvariant("x>=5");
>
> }
> The content of the model file is the following:
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="20110701"
> xmlns:xmi="HTTPECLIPSEORG/spec/XMI/20110701"
> xmlns:uml="HTTPECLIPSEORG/uml2/4.0.0/UML"
> xmi:id="_824b49cf-8739-46e1-946f-01fe7db160ef"
> name="SomeActivityDiagrams">
> <packagedElement xmi:type="uml:Class"
> xmi:id="_b46209c4-a730-4f9c-8663-740dd5f97be7" name="Class1">
> <ownedAttribute xmi:id="_02d2fb85-4294-44cb-a4ff-aaff3731fe83"
> name="x" visibility="private" aggregation="composite">
> <type xmi:type="uml:PrimitiveType"
> href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
> </ownedAttribute>
> </packagedElement>
> </uml:Model>
>
Re: error when resolving the type of a variable [message #1070725 is a reply to message #1070524] Thu, 18 July 2013 14:39 Go to previous message
felix Kurth is currently offline felix KurthFriend
Messages: 5
Registered: July 2013
Junior Member
no i used the org.eclipse.ocl.uml
here are the missing imports
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.ocl.ParserException;
import org.eclipse.ocl.uml.OCL;
import org.eclipse.ocl.uml.OCL.Helper;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.internal.impl.PropertyImpl;
import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;

I am currently trying to get it with pivot model work
Previous Topic:Type Checking: Union Operation
Next Topic:INOUT parameters
Goto Forum:
  


Current Time: Tue Apr 23 12:10:13 GMT 2024

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

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

Back to the top