Reuse OCL - access Ecore metamodel entities in runtime [message #1822149] |
Thu, 27 February 2020 19:25  |
Eclipse User |
|
|
|
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 #1828057 is a reply to message #1822925] |
Sun, 31 May 2020 02:06   |
Eclipse User |
|
|
|
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 03:38  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03570 seconds