Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » From ASTNode to IModelElement
From ASTNode to IModelElement [message #516017] Mon, 22 February 2010 14:01 Go to next message
Andreas Nusser is currently offline Andreas Nusser
Messages: 7
Registered: October 2009
Junior Member
Hello Everybody,

The short question is: Is there a way to get the corresponding IModelElement from an ASTNode?

The long question is:
I try to implement some call flow analysis like call hierarchy from the JDT or PDT (Actually the call hierarchy feature of PDT 2.1.1 doesn't work. Even for very trivial cases). As I wasn't able to find something like the "NodeFinder" of the JDT, I desided to walk the AST to find out where the user positioned the cursor. This works pretty well and results in a ASTNode which for example refers to a method call. Now I'm stuck with the problem that I can't find a way to determine where this method was declared. And no, I can't simply use IModelElementVisitor on the SourceModul, as the method might be declared in a different module. Even walking the the whole Workspace wouldn't be be feasible as I can't see a way to get a usable fully qualified name of the ASTNode.

So, back to my original question. How can I get the corresponding IModelElement from an ASTNode?

kgrds,
Andreas
Re: From ASTNode to IModelElement [message #516221 is a reply to message #516017] Tue, 23 February 2010 09:17 Go to previous messageGo to next message
Alex Panchenko is currently offline Alex Panchenko
Messages: 342
Registered: July 2009
Senior Member
Hi Andreas,

The short answer is: it's language dependent.

One of the language-independent ways is to compare names/offsets of all model elements with those of AST nodes.

The related info: if you want to find out model elements for specific offset then you can use ICompilationUnit/ISourceModule.codeSelect().

Regards,
Alex
Re: From ASTNode to IModelElement [message #516226 is a reply to message #516221] Tue, 23 February 2010 09:52 Go to previous messageGo to next message
Andreas Nusser is currently offline Andreas Nusser
Messages: 7
Registered: October 2009
Junior Member
Thanks for the answer! I'll have a look at it.
Re: From ASTNode to IModelElement [message #696873 is a reply to message #516226] Fri, 15 July 2011 02:36 Go to previous messageGo to next message
Timothy Wall is currently offline Timothy Wall
Messages: 21
Registered: July 2009
Junior Member
How about the reverse? Given an IModelElement (well, specifically IMember in the documentation provider), how can I get a corresponding ASTNode?
Re: From ASTNode to IModelElement [message #698184 is a reply to message #696873] Tue, 19 July 2011 00:18 Go to previous message
Timothy Wall is currently offline Timothy Wall
Messages: 21
Registered: July 2009
Junior Member
Converting ASTNode to IModelElement (for SelectionEngine):

Walk the existing model tree using a visitor (IModelSource.getModelElement().accept()).

If a corresponding model element doesn't exist, create one (Ruby uses a FakeField implementation to represent local variable declarations/references.


Converting IModelElement to ASTNode:

Walk your AST with ASTNode.traverse(ASTVisitor); return false from ASTVisitor.visitGeneral(ASTNode), or other appropriate visit method once you've found a match.
Previous Topic:Implement C/C++ style #include the DLTK way...
Next Topic:Problem setting up Eclipse as an OTcl IDE
Goto Forum:
  


Current Time: Sat Oct 25 16:46:52 GMT 2014

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

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