Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Fail to correctly parse CompleteOCL constraints
Fail to correctly parse CompleteOCL constraints [message #1799076] Thu, 29 November 2018 14:22 Go to next message
Florian Amberg is currently offline Florian AmbergFriend
Messages: 6
Registered: November 2018
Junior Member
Hello,
i am trying to parse OCL constraints programmaticaly in an Eclipse plugin. I want to use the new pivot OCL for this purpose. I created an minimal example using the library example and attached it to this post.
After the Sample Menu -> Sample Command button is clicked the PivotParser Class is executing the parsing. It loads the library.ocl constraints using the example at https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FOCLInterpreterTutorial.html .
The problem is that my constraint is getting parsed from:
	inv test:
books->exists( book | book.title = '')

to:
{test=self.books->exists(book : extlibrary::Book[1] | invalid.=(''))}


and evaluating this constraint of course results in invalid. I already wrote this plugin using ClassicOCL without any problems. I'm not sure what i am doing wrong, so help is really appreciated.
Regards
  • Attachment: parseOCL.zip
    (Size: 12.27KB, Downloaded 156 times)
Re: Fail to correctly parse CompleteOCL constraints [message #1799084 is a reply to message #1799076] Thu, 29 November 2018 15:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Thanks for the detailed repro; it saves a lot of time.

It works for me....

The pretty printed expression shows that book.title parsed as invalid which strongly suggests that the library example model failed to load. It probably works for me because I have org.eclipse.emf.examples.library installed in my installation and as an open project in my workspace. Closing the project and it still works for me.

(You can install org.eclipse.emf.examples.library via Install->New Software... working with http://download.eclipse.org/modeling/emf/emf/builds/release/latest to install EMF Examples.)

A more plausible example is: https://help.eclipse.org/photon/topic/org.eclipse.ocl.doc/help/PivotParsingDocuments.html?cp=75_6_6
where you will see
import 'http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0'
using an nsURI rather than platform URL.

registry.put("platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore",
EXTLibraryPackage.eINSTANCE);

won't work because platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore is not an nsURI. Use

registry.put(EXTLibraryPackage.eNS_URI, EXTLibraryPackage.eINSTANCE);

or just rely on the side effect from

EXTLibraryPackage.class.getName()


If you really want to
import 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore'
rather than
import 'http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0'
you will need to wind up ProjectMap to do a classpath analysis to discover the equivalence.

Much easier to work with nsURIs just as the documentation does.

Regards

Ed Willink










Re: Fail to correctly parse CompleteOCL constraints [message #1799109 is a reply to message #1799084] Thu, 29 November 2018 19:53 Go to previous messageGo to next message
Florian Amberg is currently offline Florian AmbergFriend
Messages: 6
Registered: November 2018
Junior Member
Thank you for your anwser. I changed the registry to
registry.put(EXTLibraryPackage.eNS_URI, EXTLibraryPackage.eINSTANCE);
, i installed the emf software, imported the project, but it still fails. I ran the
/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/PivotDocumentationExamples.java
tests, but all 3 tests failed (see Attachment 1) .
Quote:
org.eclipse.ocl.pivot.utilities.SemanticException: The «unknown» 'extlibrary::Library' is invalid: 'books->collect(b : Book | b.category)->asSet()'
1: Unresolved Iteration '::collect(b : Book| b.category)'
at org.eclipse.ocl.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:210)
at org.eclipse.ocl.pivot.internal.context.AbstractParserContext.parse(AbstractParserContext.java:233)
at org.eclipse.ocl.pivot.internal.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:133)
at org.eclipse.ocl.pivot.utilities.OCL.createQuery(OCL.java:281)
at org.eclipse.ocl.examples.test.xtext.PivotDocumentationExamples.test_evaluatingConstraintsExample(PivotDocumentationExamples.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)


Since the tests should be working and you had no problems with my project, i installed Eclipse on another computer, imported everything and there the tests and my sample project works. I'm not sure what is wrong with my previous Eclipse instance, but after installing Eclipse again it is working now.
  • Attachment: test_fail.png
    (Size: 44.91KB, Downloaded 141 times)
Re: Fail to correctly parse CompleteOCL constraints [message #1799129 is a reply to message #1799109] Fri, 30 November 2018 08:43 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Thanks for getting back.

While your original installation was mostly working, there was clearly something wrong, probably with the org.eclipse.emf.examples.library plugin. Debugging broken installations is not very profitable, but it is sometimes helpful to identify how a user managed to dig a deep hole.

If you can post the bad configuration. Help->About Eclipse->Installation Details->Configuration, it might be possible to investigate.

If you can recall some 'foolish' sequence of actions that led to the bad installation, perhaps some extra diagnostic might be provided.

Your original code omitted the error checking. Following

Resource asResource = ocl.parse(completeOclUri);

you should look at asResource.getErrors() and possibly asResource.getWarnings() and more generally at all asResource.getResourceSet().getResources() getErrors()/getWarnings()

You will probably find an IOException diagnostic that might shed light on the bad installation.

Regards

Ed Willink

Previous Topic:a derived property
Next Topic:Eclipse OCL latest P2 repos
Goto Forum:
  


Current Time: Thu Apr 25 01:47:27 GMT 2024

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

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

Back to the top