Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Inconsisten Evaluation of OCL Constraint
Inconsisten Evaluation of OCL Constraint [message #62783] Fri, 10 October 2008 14:09 Go to next message
sth2000 is currently offline sth2000Friend
Messages: 10
Registered: July 2009
Junior Member
Hi,

I stumbled across the following peculiar effect. In the following code
snippet two integer variables 'nl' and 'np' (both have value '1') are
compared with the expression 'nl <= np' which should be true obviously.
However, evaluating the expression with query.check() results in false while
ocl.check() returns true. Is this a bug?

Best Regards,

Stephan



Diagram diagram = (Diagram) inputModelResource.getContents().get(0);

OCL ocl = OCL.newInstance();


Helper helper = ocl.createOCLHelper();


helper.setContext(EcorePackage.eINSTANCE.getEObject());


org.eclipse.ocl.expressions.Variable<EClassifier, EParameter> v =
ocl.getEnvironment().getOCLFactory().createVariable();

v.setName("nl");

v.setType(ocl.getEnvironment().getOCLStandardLibrary().getIn teger());


ocl.getEnvironment().addElement(v.getName(), v, true);


ocl.getEvaluationEnvironment().add(v.getName(), 1);


v = ocl.getEnvironment().getOCLFactory().createVariable();

v.setName("np");

v.setType(ocl.getEnvironment().getOCLStandardLibrary().getIn teger());


ocl.getEnvironment().addElement(v.getName(), v, true);


ocl.getEvaluationEnvironment().add(v.getName(), 1);

try

{

Constraint oclExpression = helper.createInvariant("nl <= np");


Query query = ocl.createQuery(oclExpression);

Boolean b = query.check(diagram); //Evaluates to false


System.out.println("Query successful.\nResult: " + b.toString());


b = ocl.check(diagram, oclExpression); //Evaluates to true


System.out.println("Query successful.\nResult: " + b.toString());

}

catch (ParserException e)

{

System.out.println("Query failed.");

// TODO Auto-generated catch block

e.printStackTrace();

}
Re: Inconsisten Evaluation of OCL Constraint [message #62802 is a reply to message #62783] Fri, 10 October 2008 16:58 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Stephan,

The query.check() invocation is failing with an exception, which results
in an OclInvalid token, which is not equal to the Boolean "true" value,
so the Java method returns "false."

The problem is that the Query object creates its own evaluation
environment, in which you have not provided variable bindings. That's
one of the benefits of the queries: you can create several, assign them
different variable bindings, and evaluate them repeatedly.

HTH,

Christian


Stephan wrote:
> Hi,
>
> I stumbled across the following peculiar effect. In the following code
> snippet two integer variables 'nl' and 'np' (both have value '1') are
> compared with the expression 'nl <= np' which should be true obviously.
> However, evaluating the expression with query.check() results in false while
> ocl.check() returns true. Is this a bug?
>
> Best Regards,
>
> Stephan
>
>
>
> Diagram diagram = (Diagram) inputModelResource.getContents().get(0);
>
> OCL ocl = OCL.newInstance();
>
>
> Helper helper = ocl.createOCLHelper();
>
>
> helper.setContext(EcorePackage.eINSTANCE.getEObject());
>
>
> org.eclipse.ocl.expressions.Variable<EClassifier, EParameter> v =
> ocl.getEnvironment().getOCLFactory().createVariable();
>
> v.setName("nl");
>
> v.setType(ocl.getEnvironment().getOCLStandardLibrary().getIn teger());
>
>
> ocl.getEnvironment().addElement(v.getName(), v, true);
>
>
> ocl.getEvaluationEnvironment().add(v.getName(), 1);
>
>
> v = ocl.getEnvironment().getOCLFactory().createVariable();
>
> v.setName("np");
>
> v.setType(ocl.getEnvironment().getOCLStandardLibrary().getIn teger());
>
>
> ocl.getEnvironment().addElement(v.getName(), v, true);
>
>
> ocl.getEvaluationEnvironment().add(v.getName(), 1);
>
> try
>
> {
>
> Constraint oclExpression = helper.createInvariant("nl <= np");
>
>
> Query query = ocl.createQuery(oclExpression);
>
> Boolean b = query.check(diagram); //Evaluates to false
>
>
> System.out.println("Query successful.\nResult: " + b.toString());
>
>
> b = ocl.check(diagram, oclExpression); //Evaluates to true
>
>
> System.out.println("Query successful.\nResult: " + b.toString());
>
> }
>
> catch (ParserException e)
>
> {
>
> System.out.println("Query failed.");
>
> // TODO Auto-generated catch block
>
> e.printStackTrace();
>
> }
>
>
Previous Topic:Is there a tutorial on OCL?
Next Topic:[Announce] MDT OCL 1.2.3 M200810101330 is available
Goto Forum:
  


Current Time: Tue Apr 23 07:10:37 GMT 2024

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

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

Back to the top