EditorAction on Acceleo-Editor [message #1413685] |
Fri, 29 August 2014 02:56  |
Eclipse User |
|
|
|
Hello,
I want to do the following, and wanted to ask for the best way to achieve it:
1. I want to select some text in an acceleo editor
2. I want to find the underlying model-element to the selected text (find the metamodel-instance, and the selected element)
At the moment I am able to achieve 1 by implementing IEditorActionDelegate and using the selectionChanged-method. So I have the lenght and offset of the selected textpart. Then I looked around the acceleo-code and found this class: AcceleoSourceContent. With an instance of this class I can get a
CSTNode by using following code:
int startPos = sel.getOffset();
int endPos = sel.getOffset() + sel.getLength();
AcceleoSourceContent mtlSource = this.editor.getContent();
// create the model
mtlSource.createCST();
org.eclipse.acceleo.parser.cst.Module modelModule = mtlSource.getCST();
CSTNode foundCSTNode = mtlSource.getCSTNode(startPos, endPos);
But I think this is not the right way, because the modelModule is not the expected mtl-model. In the org.eclipse.acceleo.model project I found several metamodels.
What are these models: mtl.ecore, MTLCST.ecore, AST-model ?
Is there maybe a nice way to find an mtl-element corresponding to the selected text? Or is there maybe a mechanisn to map an CST-Element to a MTL-Element?
All hints are welcome!
~Alex
[Updated on: Fri, 29 August 2014 03:50] by Moderator
|
|
|
|
|
Re: EditorAction on Acceleo-Editor [message #1420803 is a reply to message #1415335] |
Wed, 10 September 2014 09:54  |
Eclipse User |
|
|
|
Hello,
I asked in the french Acceleoforum for some advice and recieved some help.
Acceleo uses two metamodels under the hood: AST-Metamodel (OCL-AST-Metamodell/with a speciazed MTL.ecore metamodel)
and a CST-Metamodel. The CST-MM containing only the raw data from the parsing.
The AST-MM containing the data resulting from the parsing and the analysis of the data parsed.
So this is clear now.
It is also quit nice to handle from an EditorAction, because one can get the AST from the EditorContent. For this the emf-resource (.emtl) file is just loaded.
Here some code for a better understanding:
AcceleoSourceContent mtlSource = this.editor.getContent();
// Loads the .emlt model (serialized AST) in the /bin folder via a
// local ResourceSet
globalResourceSet = mtlSource.getAST().eResource().getResourceSet();
// This AST node is already the ModuleElement of the Model!!!
org.eclipse.ocl.utilities.ASTNode foundASTNode = mtlSource.getResolvedASTNode(startPos, endPos);
One has to remember, that an Modul-Element is also an ASTNode! Afterwards everything is quit straight forward.
~Alex
|
|
|
Powered by
FUDForum. Page generated in 0.05200 seconds