Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Why does printing parent node of a node returns parent + child nodes?
Why does printing parent node of a node returns parent + child nodes? [message #803363] Tue, 21 February 2012 08:43 Go to next message
Fabrice Marcelin is currently offline Fabrice MarcelinFriend
Messages: 15
Registered: February 2011
Location: USA
Junior Member

Given a start position, I can find a node by passing it to org.eclipse.jdt.core.dom.NodeFinder class.

NodeFinder node = new NodeFinder(root, m.getSourceStart(), m.getSourceEnd() - m.getSourceStart() + 1);
ASTNode n = node.getCoveredNode();
Let assume that this node has a parent and get the node's parent n.getParent(); does anyone know why it prints out the parent node and the node?

For instance we know the starting point of foo() in bar.foo() so if I do System.Out.Println(n.getParent().toString()); it prints bar.foo(). Shouldn't it print only bar?

Thanks in advance for your insight.
Re: Why does printing parent node of a node returns parent + child nodes? [message #803606 is a reply to message #803363] Tue, 21 February 2012 15:04 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 2/21/2012 2:13 PM, Fabrice Marcelin wrote:
> For instance we know the starting point of foo() in bar.foo() so if I do
> System.Out.Println(n.getParent().toString()); it prints bar.foo().
> Shouldn't it print only bar?

If you use the AST view plugin
(http://www.eclipse.org/jdt/ui/astview/index.php), you will realize that
the parent here is the MethodInvocation node or bar.foo().

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Re: Why does printing parent node of a node returns parent + child nodes? [message #803689 is a reply to message #803606] Tue, 21 February 2012 17:08 Go to previous messageGo to next message
Fabrice Marcelin is currently offline Fabrice MarcelinFriend
Messages: 15
Registered: February 2011
Location: USA
Junior Member

This is a very informative tool. Thanks. So quick question, how could i get only the parent's name in that case?
Re: Why does printing parent node of a node returns parent + child nodes? [message #803932 is a reply to message #803689] Wed, 22 February 2012 01:39 Go to previous message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 2/21/2012 10:38 PM, Fabrice Marcelin wrote:
> This is a very informative tool. Thanks. So quick question, how could i
> get only the parent's name in that case?

Again, if you use the tool you will realize that what you are looking
for is the Expression property of the parent.

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Previous Topic:Getting sources for a (bundle) JarPackageFragmentRoot
Next Topic:Eclipse Indigo - Strange JPA Problems in known-good code
Goto Forum:
  


Current Time: Sat Sep 21 08:28:36 GMT 2024

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

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

Back to the top