Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » allInstances, unrecognized variable
allInstances, unrecognized variable [message #834755] Mon, 02 April 2012 11:00 Go to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
Hi,

I have created an Invariant which works fine except using the allInstances Construct:

createInvariant("self.allInstances.var < 10");

The error is:

org.eclipse.ocl.SemanticException: Unrecognized variable: (allInstances)

Does anybody know why it's wrong?

In the Eclipse OCL Tutorial I read something about an extent Map. Do I have to use this?

Thank's!
Re: allInstances, unrecognized variable [message #834826 is a reply to message #834755] Mon, 02 April 2012 12:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4060
Registered: July 2009
Senior Member
Hi

allInstances is a type operation, so you should do

self.oclType().allInstances()

which might work with the new pivot-based OCL for which oclType() is
defined.

For the Ecore-based OCL you will need the explivit type:
MyType.allInstances()

In general allInstances() should be avoided wherever possible since it
involves a total search of an implementation-specific domain. Most uses
of allInstances() can be eliminated by placing the OCL in a more
suitable context.

Regards

Ed Willink

On 02/04/2012 12:00, fv fv wrote:
> Hi,
>
> I have created an Invariant which works fine except using the
> allInstances Construct:
>
> createInvariant("self.allInstances.var < 10");
>
> The error is:
>
> org.eclipse.ocl.SemanticException: Unrecognized variable: (allInstances)
>
> Does anybody know why it's wrong?
>
> In the Eclipse OCL Tutorial I read something about an extent Map. Do I
> have to use this?
>
> Thank's!
Re: allInstances, unrecognized variable [message #834916 is a reply to message #834826] Mon, 02 April 2012 14:51 Go to previous messageGo to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
Hi,

thank's for your reply.

I tried self.oclType().allInstances() but it produces the error:

org.eclipse.ocl.SemanticException: Cannot find operation (oclType()) for the type (MyClass)

It seems that only your second proposal remains but I don't understand it. For what does MyType stands?
Can you give me an example?

Sorry, I'm totally new to this.

Thank's
Re: allInstances, unrecognized variable [message #835055 is a reply to message #834916] Mon, 02 April 2012 18:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4060
Registered: July 2009
Senior Member
Hi

I wrote that oclType() is not implemented for the old Ecore-based
Eclipse OCL; you need the new experimental Pivot-based version in the
examples plugins. org.eclipse.ocl.SemanticException shows that you are
using the old code.

MyType is the known type of self, which from the error message appears
to be "MyClass".

Regards

Ed Willink

On 02/04/2012 15:51, fv fv wrote:
> Hi,
>
> thank's for your reply.
>
> I tried self.oclType().allInstances() but it produces the error:
>
> org.eclipse.ocl.SemanticException: Cannot find operation (oclType())
> for the type (MyClass)
>
> It seems that only your second proposal remains but I don't understand
> it. For what does MyType stands?
> Can you give me an example?
>
> Sorry, I'm totally new to this.
>
> Thank's
>
Re: allInstances, unrecognized variable [message #835700 is a reply to message #835055] Tue, 03 April 2012 15:09 Go to previous messageGo to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
Hi,

I've tried "MyClass.allInstances.var < 10", but the same error comes.
Are there other possibilities besides using the pivot version?


Another question appeared when reading the OCL Tutorial.
I have tried to use the library example project. It created the three projects:
org.eclipse.emf.examples.library
org.eclipse.emf.examples.library.edit
org.eclipse.emf.examples.library.editor

Then I created the following java class to parse an OCL Query as it is described in the tutorial (I should mention I used UMLEnvironmentFactory instead of the EcoreEnvironmentFactory because eclipse always told me that EcoreEnvironmentFactory cannot be resolved to a variable!?):





	import org.eclipse.emf.ecore.EClassifier;
	import org.eclipse.emf.ecore.EObject;
	import org.eclipse.emf.examples.extlibrary.EXTLibraryPackage;
	import org.eclipse.ocl.expressions.OCLExpression;
	import org.eclipse.uml2.uml.CallOperationAction;
	import org.eclipse.uml2.uml.Class;
	import org.eclipse.uml2.uml.Classifier;
	import org.eclipse.uml2.uml.Constraint;
	import org.eclipse.uml2.uml.EnumerationLiteral;
	import org.eclipse.uml2.uml.Operation;
	import org.eclipse.uml2.uml.Package;
	import org.eclipse.uml2.uml.Parameter;
	import org.eclipse.uml2.uml.Property;
	import org.eclipse.uml2.uml.SendSignalAction;
	import org.eclipse.uml2.uml.State;
	import org.eclipse.ocl.OCL;
	import org.eclipse.ocl.ParserException;
	import org.eclipse.ocl.helper.OCLHelper;
	import org.eclipse.ocl.uml.UMLEnvironmentFactory;

	public class LibTest {

		
		boolean valid;
		OCLExpression<EClassifier> query = null;

		
		public void parseOCLExpr() {
		

			 OCL<Package, Classifier, Operation, Property, EnumerationLiteral, Parameter, State, CallOperationAction, SendSignalAction, Constraint, Class, EObject> ocl;
			 UMLEnvironmentFactory umlEnv = new UMLEnvironmentFactory();
			 ocl = OCL.newInstance(umlEnv);
		   
		   
		    // create an OCL helper object
		    OCLHelper helper = ocl.createOCLHelper();
		    
		    try {
		    // set the OCL context classifier
		    helper.setContext(EXTLibraryPackage.Literals.WRITER);
		    
		   query = helper.createQuery("self.books->collect(b : Book | b.category)->asSet()");
		  
		    // record success
		    valid = true;
		} catch (ParserException e) {
		    // record failure to parse
		    valid = false;
		    System.err.println(e.getLocalizedMessage());
		    e.printStackTrace();
		}
		
		}
		
		
		public static void main(String[] args) {
			LibTest a = new LibTest();
			a.parseOCLExpr();
		}
	}






But I just get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: lpg/runtime/RuleAction
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(Unknown Source)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.access$000(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at LibTest.parseOCLExpr(LibTest.java:35)
	at LibTest.main(LibTest.java:61)
Caused by: java.lang.ClassNotFoundException: lpg.runtime.RuleAction
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 14 more


The reason for this seems to be the line:
ocl = OCL.newInstance(umlEnv);

Does anybody know what I did wrong?

Thank's.

[Updated on: Tue, 03 April 2012 15:15]

Report message to a moderator

Re: allInstances, unrecognized variable [message #835766 is a reply to message #835700] Tue, 03 April 2012 16:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4060
Registered: July 2009
Senior Member
Hi

Comments below

On 03/04/2012 16:09, fv fv wrote:
> Hi,
>
> I've tried "MyClass.allInstances.var < 10", but the same error comes.
> Are there other possibilities besides using the pivot version?
>
Read the earlier comments and use allInstances().

The, I've no idea what .var < 10 is supposed to do since .var is an
implicit collect and so returns a collection that cannot be compared
with an integer.
>
> Another question appeared when reading the OCL Tutorial.
> I have tried to use the library example project. It created the three
> projects:
> org.eclipse.emf.examples.library
> org.eclipse.emf.examples.library.edit
> org.eclipse.emf.examples.library.editor
>
> Then I created the following java class to parse an OCL Query as it is
> described in the tutorial:
>
>
>
>
>
>
> import org.eclipse.emf.ecore.EClassifier;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.examples.extlibrary.EXTLibraryPackage;
> import org.eclipse.ocl.expressions.OCLExpression;
> import org.eclipse.uml2.uml.CallOperationAction;
> import org.eclipse.uml2.uml.Class;
> import org.eclipse.uml2.uml.Classifier;
> import org.eclipse.uml2.uml.Constraint;
> import org.eclipse.uml2.uml.EnumerationLiteral;
> import org.eclipse.uml2.uml.Operation;
> import org.eclipse.uml2.uml.Package;
> import org.eclipse.uml2.uml.Parameter;
> import org.eclipse.uml2.uml.Property;
> import org.eclipse.uml2.uml.SendSignalAction;
> import org.eclipse.uml2.uml.State;
> import org.eclipse.ocl.OCL;
> import org.eclipse.ocl.ParserException;
> import org.eclipse.ocl.helper.OCLHelper;
> import org.eclipse.ocl.uml.UMLEnvironmentFactory;
>
> public class LibTest {
>
>
> boolean valid;
> OCLExpression<EClassifier> query = null;
>
>
> public void parseOCLExpr() {
>
>
> OCL<Package, Classifier, Operation, Property,
> EnumerationLiteral, Parameter, State, CallOperationAction,
> SendSignalAction, Constraint, Class, EObject> ocl;
> UMLEnvironmentFactory umlEnv = new UMLEnvironmentFactory();
> ocl = OCL.newInstance(umlEnv);
> // create an OCL helper object
> OCLHelper helper = ocl.createOCLHelper();
> try {
> // set the OCL context classifier
> helper.setContext(EXTLibraryPackage.Literals.WRITER);
> query =
> helper.createQuery("self.books->collect(b : Book |
> b.category)->asSet()");
> // record success
> valid = true;
> } catch (ParserException e) {
> // record failure to parse
> valid = false;
> System.err.println(e.getLocalizedMessage());
> e.printStackTrace();
> }
>
> }
>
>
> public static void main(String[] args) {
> LibTest a = new LibTest();
> a.parseOCLExpr();
> }
> }
>
>
>
>
>
>
> But I just get the following exception:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> lpg/runtime/RuleAction
> at java.lang.ClassLoader.defineClass1(Native Method)
> at java.lang.ClassLoader.defineClassCond(Unknown Source)
> at java.lang.ClassLoader.defineClass(Unknown Source)
> at java.security.SecureClassLoader.defineClass(Unknown Source)
> at java.net.URLClassLoader.defineClass(Unknown Source)
> at java.net.URLClassLoader.access$000(Unknown Source)
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at LibTest.parseOCLExpr(LibTest.java:35)
> at LibTest.main(LibTest.java:61)
> Caused by: java.lang.ClassNotFoundException: lpg.runtime.RuleAction
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> ... 14 more
>
>
> The reason for this seems to be the line:
> ocl = OCL.newInstance(umlEnv);
>
> Does anybody know what I did wrong?
It looks as if lpg.runtime is missing, which is because you are using a
Java application rather than an Eclipse plugin project, which I
recommend since it has a MANIFEST that sorts nearly all the classpath
problems out. If you use Jav projects you have to solve all these
problems yourself. Fix the classpath.

Regards

Ed Willink
Re: allInstances, unrecognized variable [message #840595 is a reply to message #835766] Tue, 10 April 2012 09:28 Go to previous messageGo to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
Hi,

now, both the query and the library example works Smile

My next step is to create a Syntax Tree of an OCL Expression.
I read the article: www.eclipse.org/articles/printable.php?file=Article-HowToProcessOCLAbstractSyntaxTrees/index.html

In this article the OCLAstView is mentioned.
I extracted OCLASTView_1.0.0.jar and copied OCLASTView.jar in the plugins folder. Now I have the OCL Ast View as it is depicted in the tutorial.
I thought I just have to select an invariant in an ecore file and the OCL Ast View is updated (as it looks like in figure 1 in the tutorial). But nothing happens.
How do I have to use the View?
Re: allInstances, unrecognized variable [message #840596 is a reply to message #835766] Tue, 10 April 2012 09:28 Go to previous messageGo to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
No Message Body

[Updated on: Tue, 10 April 2012 09:29]

Report message to a moderator

Re: allInstances, unrecognized variable [message #840630 is a reply to message #840595] Tue, 10 April 2012 10:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4060
Registered: July 2009
Senior Member
Hi

That article was written in 2007 and led to the MDT/OCL Tools project
proposal which failed to progress past the creation review. That article
should not be linked to from current Eclipse OCL Documentation.

The main MDT/OCL project now provides many of the tools envisaged by the
proposed project:
- editors
- code generator

The new Xtext-based editors have an Outline view.

The article predates Xtext and so is very misleading about what can be
done with the new pivot-based UML-aligned Eclipse OCL. It may however
provide an example of the use of visitors, but in a clumsy fashion since
EClass is not visitable whereas org.eclipse.ocl.examples.pivot.Class is.

In general, synchronization of meta-model evolution is not supported by
EMF, and while many tools successfully make it work, useful
functionality is currently a bonus. Within Eclipse OCL, I was surprised
to find that the OCLinEcore editor updates when the *.ecore file is
changed externally. I know that the Console View does not update
correctly. I'm not surprised that the view in the old tutorial fails to
update.

Regards

Ed Willink

On 10/04/2012 10:28, fv fv wrote:
> Hi,
>
> now, both the query and the library example works :)
>
> My next step is to create a Syntax Tree of an OCL Expression.
> I read the article:
> www.eclipse.org/articles/printable.php?file=Article-HowToProcessOCLAbstractSyntaxTrees/index.html
>
> In this article the OCLAstView is mentioned.
> I extracted OCLASTView_1.0.0.jar and copied OCLASTView.jar in the
> plugins folder. Now I have the OCL Ast View as it is depicted in the
> tutorial.
> I thought I just have to select an invariant in an ecore file and the
> OCL Ast View is updated (as it looks like in figure 1 in the
> tutorial). But nothing happens.
> How do I have to use the View?
Re: allInstances, unrecognized variable [message #840955 is a reply to message #840630] Tue, 10 April 2012 18:20 Go to previous messageGo to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
Hi,

thank's for your explanation.

After searching for the possiblities of creating an OCL Syntax Tree, I came across the AbstractVisitor Class. I also read something about the classes "OCLAnalyzer" and "CSTNode", would these classes also come into consideration for creating a syntax tree?

I'd be glad to hear your opinion (maybe you know some other classes/tutorials/examples ..?) on this.

Thank's,
Re: allInstances, unrecognized variable [message #840991 is a reply to message #840955] Tue, 10 April 2012 19:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4060
Registered: July 2009
Senior Member
Hi

I've no idea what you're actually trying to do.

But I'm pretty sure it has nothing to do with "allInstances,
unrecognized variable".

Regards

Ed Willink


On 10/04/2012 19:20, fv fv wrote:
> Hi,
>
> thank's for your explanation.
>
> After searching for the possiblities of creating an OCL Syntax Tree, I
> came across the AbstractVisitor Class. I also read something about the
> classes "OCLAnalyzer" and "CSTNode", would these classes also come
> into consideration for creating a syntax tree?
>
> I'd be glad to hear your opinion (maybe you know some other
> classes/tutorials/examples ..?) on this.
> Thank's,
Re: allInstances, unrecognized variable [message #841387 is a reply to message #840991] Wed, 11 April 2012 08:33 Go to previous messageGo to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
I want to create a Syntax Tree (e.g. an XML File) of an arbitrary OCL Expression.
Re: allInstances, unrecognized variable [message #841447 is a reply to message #841387] Wed, 11 April 2012 10:09 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4060
Registered: July 2009
Senior Member
Hi

The syntax tree is already created, you just need to grab its resource
and save it.

Regards

Ed Willink

On 11/04/2012 09:33, fv fv wrote:
> I want to create a Syntax Tree (e.g. an XML File) of an arbitrary OCL
> Expression.
Previous Topic:Avoiding 'import' in CompleteOclEditor using OCL Registry?
Next Topic:Problem when using ereference to another registered package
Goto Forum:
  


Current Time: Wed Oct 01 16:36:40 GMT 2014

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

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