[CompleteOCL] Accessing the metamodel [message #726044] |
Fri, 16 September 2011 09:17  |
Eclipse User |
|
|
|
Hi all,
I am using CompleteOCL documents to enrich my UML model with OCL constraints. This works quite fine.
Now i want to have access to the OCL constraints packages and contexts in the CompleteOCL document. Therefore I instanceiated a CompleteOCL xtext resource and navigated through the content tree of the resource. I found all elements needed in the resource.
What i didn't manage was to access elements from my UML model. For example i want to get the name or element of my OCL context. I found no way to get it from the ClassifierContextDeclCS instance of the xText resource. Here an example of my ocl file
package packa::subpack
context ElementA
inv checkName :
let name :String = self.name in
name.size()<=12
endpackage
How can I retrieve the context "ElementA" from the CompleteOCL file. Has this something to do with the pivot model?
Can anyone please give me some hints how to retrieve this information ?
Thanks Ambros
|
|
|
|
|
Re: [CompleteOCL] Accessing the metamodel [message #726846 is a reply to message #726663] |
Mon, 19 September 2011 13:00  |
Eclipse User |
|
|
|
Hi Ambros
You are navigating the the Concrete Syntax resource which is a
proprietary model. For Essential OCL, the OCL specification defines a
non-normative model, for Complete OCL the specification defines nothing.
The new Eclipse OCL Concrete Syntax models are designed for ease of use
with Xtext and so referenced nodes exist as references that Xtext
initialises with proxies and resolves to the required elements. You can
recover the text behind the CS elements using ElementUtil.getText(). It
is possible that the new CS models may influence the missing
non-normative specifications for OCL 2.4.
Navigating the proprietary CS is not recommended. You should navigate
the Abstract Syntax pivot model, which is close to the OCL
specification, and arguably beyond the OCL specification since the pivot
model prototypes UML-alignment and other solutions that may be approved
for OCL 2.4.
Most CS nodes have a 'pivot' property that identifies the corresponding
AST node. If you want to navigate this with type 'safety' you may use
PivotUtil.getPivot().
In the pivot model you should find one Package per PackageDeclarationCS
and merged Classes for multiple ClassifierContextDeclCSes. The Package
for the Complete OCL PackageDeclarationCS is not merged with an
equivalently named Package from perhaps OCLinEcore, rather it sits
alongside. Methods in the TypeManager facilitate treatment of multiple
merged contributions as a single coherent element.
If you really want to see multiple 'context Xyzzy' as multiple nodes you
do need to navigate the ClassifierContextDeclCS. However if you are
really more interested in the Xyzzy class, then the pivot is more useful.
If you invoke
C2Pivot.findAdapter(completeOCLDocument.eResource().getResourceSet())
you will get the CS 2 AS conversion controller that provides a variety
of useful facilities for interacting with the CS and AS.
Regards
Ed Willink
On 19/09/2011 09:19, Ambros Morscher wrote:
> Hi Edward,
>
> Thank you for your quick answer unfortunately this is not what I was
> looking for. In order to clarify here is the code how I access
> contraints from the Complete OCL resrouce.
>
>
> CompleteOCLDocumentCS completeOCLDocument =
> (CompleteOCLDocumentCS)oclResource.getContents().get(0);
> for(PackageDeclarationCS packageDecl :completeOCLDocument.getPackages()){
> for
> (org.eclipse.ocl.examples.xtext.completeocl.completeOCLCST.ContextDeclCS
> ctx:packageDecl.getContexts()){
> //get the name of the context
> }
> }
>
>
> In the second "FOR" loop I navigate through the contexts of my package
> declaration. How can I acces the name or type of the context using the
> ctx variable.
>
> Thanks again.
>
> Ambros Morscher
|
|
|
Powered by
FUDForum. Page generated in 0.03657 seconds