From ASTNode to IModelElement [message #516017] |
Mon, 22 February 2010 09:01  |
Eclipse User |
|
|
|
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 #698184 is a reply to message #696873] |
Mon, 18 July 2011 20:18  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04524 seconds