LeastFixedPoint/java-parser-tools

Add getParent to AbstractNode class.

Closed this issue · 1 comments


Adding getParent() to Abstract node will make it easier to navigate node 
trees.

Consider the following grammar...
   predicateObjectList ::= (verb objectList {";" verb  objectList}) 
   objectList ::= (object {"," object}) 
   verb ::= (resource | "a") 

Then consider the task of processing the verbs and associated objects in a 
predicateObjectList.


We can first get the all the verb nodes..

List<AbstractNode> verbNodes= Navigation.findAllDecendentsById
(predicateObjectListNode, "verb");


Now, given a verb node how can we get the associated object nodes?
There currently is no easy way except to manually navigate the 
predicateObjectList node and process the verbs and objects are we 
encounter them, yuck.

If we add getParent() to the AbstractNode class then we can easily find 
all the objects nodes for verb like so...

List<AbstractNode> objectNodes= Navigation.findAllDecendentsById
(verbNode.getParent(), "object");



Original issue reported on code.google.com by emorning on 9 Apr 2009 at 10:27

I have discovered that I don't need this feature - instead the grammar can be 
designed to provide easier navigation.
The grammar in the example can be refactored to group verbs with their 
associated 
objects together.
Here is the refactored grammar...
   predicateObjectList ::= (predicateValues {";" predicateValues}) 
   predicateValues ::= (verb objectList)
   objectList ::= (object {"," object}) 
   verb ::= (resource | "a") 

Now I can navigate like so...

First get the predicateValues...
List<AbstractNode> predicateNodes= Navigation.findAllDecendentsById
(predicateObjectListNode, "predicateValues")

Then get the verb...
AbstractNode verb= Navigation.findDecendentsById(predicateObjectListNode, 
"verb")

Then get the objects...
List<AbstractNode> objects= Navigation.findDecendentsById
(predicateObjectListNode, "objects")





Original comment by emorning on 15 Apr 2009 at 10:14

  • Changed state: WontFix