Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Reuse OCL - access Ecore metamodel entities in runtime
Reuse OCL - access Ecore metamodel entities in runtime [message #1822149] Fri, 28 February 2020 00:25 Go to next message
Mohammadreza Sharbaf is currently offline Mohammadreza SharbafFriend
Messages: 22
Registered: February 2016
Junior Member

Hi,

Inspired from CompleteOCL, I've tried to reuse EssentialOCL grammar using Xtext mixin mechanism to create a new Xtext DSL. In the generated language, I have access to the OCL notations, such as "import", "context", "inv" and etc. But when I import a metamodel in the first line of a simple test of generated language (like to the OCL file),

import uml : 'http://www.eclipse.org/uml2/5.0.0/UML#/'
import graph : 'platform:/resource/TestProject/Graph.ecore#/'

context uml::Class


I haven't access to the imported metamodel entities and I get the following errors:

Quote:

Couldn't resolve reference to Element ''http://www.eclipse.org/uml2/5.0.0/UML#/''.

Couldn't resolve reference to Element ''platform:/resource/TestProject/Graph.ecore#/''.

Multiple markers at this line
- Couldn't resolve reference to Element 'uml'.
- Couldn't resolve reference to Element 'Class'.


In the new language, I need to access entities of different Ecore metamodels (similar to OCL). How can I fix these errors?

Regards,
Mohammadreza
Re: Reuse OCL - access Ecore metamodel entities in runtime [message #1822154 is a reply to message #1822149] Fri, 28 February 2020 06:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Making OCL as easy to use in larger languages as Xbase, remains one of my goals; it is far from easy. However the QVTc and QVTr languages demonstrate that it can be done and you should study those to see why your code fails.

You provide no indication of what you have done, so I can only express a complete lack of surprise that an uninformed attempt to use the undocumented aspects of the OCL framework fails.

It looks like you attempting an OCL embedded with a non-OCL outer language. This was not considered and has never been tried. It can probably work, but I suggest you see how the resolution works in Complete OCL, so that you can emulate it in your DSL. You will certainly need to wrap the OCL ScopeProvider within a different ScopeProvider. and somehow accommodate the text->CS->AS two stage OCL conversion with an Xtext one stage conversion.

Regards

Ed Willink
Re: Reuse OCL - access Ecore metamodel entities in runtime [message #1822917 is a reply to message #1822154] Mon, 16 March 2020 18:04 Go to previous messageGo to next message
Mohammadreza Sharbaf is currently offline Mohammadreza SharbafFriend
Messages: 22
Registered: February 2016
Junior Member

Hi Ed,

Thanks for you comment,

I tried to add and initiate Base, Pivot, and Essential OCL Scope provider in my project with calling an OCLDelegate class in the mwe2 configuration file of Xtext project. But It didn't work yet and I get "Couldn't resolve reference to Element ..." error.

I've put a small example of my project in the following git repository.

https://github.com/MSharbaf/simpleExample

This repository contains the entire Xtext project and a test file (in TestGrammar/test1.mydsl) of the desired grammar. Could you please guide me how can I fix it?

Regards,
Mohammadreza
Re: Reuse OCL - access Ecore metamodel entities in runtime [message #1822925 is a reply to message #1822917] Mon, 16 March 2020 21:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Sorry. Unless you are prepared to pay a very large consultancy fee, I cannot help you on such basic questions in regard to unsupported functionality. You have QVTd as examples. One good way to debug failures is to gradually migrate what works into the form that you want.

Regards

Ed Willink
Re: Reuse OCL - access Ecore metamodel entities in runtime [message #1828057 is a reply to message #1822925] Sun, 31 May 2020 06:06 Go to previous messageGo to next message
Mohammadreza Sharbaf is currently offline Mohammadreza SharbafFriend
Messages: 22
Registered: February 2016
Junior Member

Hi,

After some searching and trying, I finally reused the OCL grammar and editor, in April.

Here are the most important things you need to do:
1- In your grammar, reuse the CompleteOCL grammar using mixin mechanism
2- In your grammar, import the BaseCS, EssentialCS, and CompleteOCL URI
3- In your main Xtext project, Add the OCLDelegateSetup.java for initializing Base, Essential, and CompleteOCL scoping.
4- In the scoping folder of your Xtext project, you need to extend EssentialScopeProvider
5 - In your Xtext project, you need to add a ResourceDescriptionStrategy.xtend that extended DefaultResourceDescriptionStrategy
6- In the AbstractRuntimeModule of your main Xtext project, you should add some EssentialOCLFragment
7- Some elements of your model object, which created based on your grammar, should extend CompleteOCL (in both abstraction and implementation java files)

Best regards,
Mohammadreza
Re: Reuse OCL - access Ecore metamodel entities in runtime [message #1828059 is a reply to message #1828057] Sun, 31 May 2020 07:38 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Congratulations. That cannot have been easy.

If you care to share your reuse on GitHub others may find it useful. I will take a look at it.

I am interested in your comment about ResourceDescriptionStrategy since this is not used by the OCL or QVTd editors. Rather custom name lookups observe OCL rather than 'standard' name visibility. See the org.eclipse.ocl.pivot.internal.scoping package. Maybe the Xtext approach could be tailored, but I try very hard to avoid the Xtext index since it is a classic example of index-the-world burning build time and often being unhelpful. There is absolutely nopoint indexing every *.ocl file in ordeerr to execute a *.mwe2 script; *.mwe2 can only see *.mwe2 file names which should all be locatable on the import paths without a magic index. (There was actually a bug whereby an invoked *.mwe2 file would locate itself via the index and due to duplicate entries actually execute a different content!)

Have a look at e.g. /org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/GenerateCompleteOCLEditor.mwe2 where you will find the EssentialOCLFragment and two other additional fragments activated.

Regards

Ed Willink
Previous Topic:Problems with OCL validation and derived properties
Next Topic:eAllContents() or closure of eContents() in OCL
Goto Forum:
  


Current Time: Sat Apr 27 05:00:59 GMT 2024

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

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

Back to the top