Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » EditorAction on Acceleo-Editor
EditorAction on Acceleo-Editor [message #1413685] Fri, 29 August 2014 06:56 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
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 07:50]

Report message to a moderator

Re: EditorAction on Acceleo-Editor [message #1415173 is a reply to message #1413685] Tue, 02 September 2014 08:45 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
So noone has a clue?
Re: EditorAction on Acceleo-Editor [message #1415335 is a reply to message #1415173] Tue, 02 September 2014 14:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
On 02/09/2014 09:45, Alexander R wrote:
> So noone has a clue?

Unfortunately it is a few months since any of the Obeo developers have
responded on this list, and you are asking a very specialized question.
Few users are likely to try to extend the editor.

I can only give you half an answer that may not be accurate since my
answer is specific to Eclipse OCL which Acceleo extends, but Acceleo
sensibly limits its project dependencies to improve portability and so
it may not be extending the OCL parsing framework.

The normal process for discovery of an AS context is to follow the
parsing process:

File containing a sequence of Character
Tokens comprising a sequence String
Concrete Syntax model comprising a source-text-like Object tree
(probably MTLCST.ecore)
Abstract Syntax model comprising an information focussed object graph
(e.g. mtl.ecore)

mtl.ecore is mandated by the OMG MOFM2T specification to support tool
interchange.
MTLCST.ecore is an internal convenience for a particular tool.

In the Classic Ecore-based form of Eclipse OCL used by Acceleo, the CST
is defined by OCLCST.ecore. The AST is defined by OCLEcore.ecore that
extends OCL.ecore. The LPG parser manages the tokens and creaes the CST.

At the heart of the OCL CST is CSTNode for which a getAST() method
navigates to the AST. It seems you have already found a CSTNode so
getAST() should complete the work.

Regards

Ed Willink
Re: EditorAction on Acceleo-Editor [message #1420803 is a reply to message #1415335] Wed, 10 September 2014 13:54 Go to previous message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
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

Previous Topic:[Acceleo] error in definition of Set
Next Topic:[Acceleo] Testing for superclass and Interfaces
Goto Forum:
  


Current Time: Mon Jul 23 03:51:17 GMT 2018

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

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

Back to the top