Skip to main content



      Home
Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » From ASTNode to IModelElement
From ASTNode to IModelElement [message #516017] Mon, 22 February 2010 09:01 Go to next message
Eclipse UserFriend
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 04:17 Go to previous messageGo to next message
Eclipse UserFriend
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 04:52 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the answer! I'll have a look at it.
Re: From ASTNode to IModelElement [message #696873 is a reply to message #516226] Thu, 14 July 2011 22:36 Go to previous messageGo to next message
Eclipse UserFriend
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] Mon, 18 July 2011 20:18 Go to previous message
Eclipse UserFriend
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: Fri Jul 04 04:11:00 EDT 2025

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

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

Back to the top