Opened 15 years ago

Closed 15 years ago

#301 closed enhancement (fixed)

AST root node: override child

Reported by: Stephen Siegel Owned by: zirkel
Priority: major Milestone: 1.1
Component: ast Version: 1.1
Keywords: child ast node child Cc:

Description

The child method defined in ASTNodeIF should be overridden in RootNodeIF as follows:

	public GlobalScopeNodeIF child(int index) throws NoSuchElementException;

This is assuming all children of a root node are global scope nodes.

Similar actions should be taken in similar circumstances, where a sub-class is known to return a sub-type of the return type of a method defined in a class.

Change History (5)

comment:1 by zirkel, 15 years ago

As it is implemented right now, the RootNodeIF has a child that is a SequenceNodeIF<GlobalScopeNodeIF>. Should this be changed so that the global scope nodes are the direct children of the root?

comment:2 by Stephen Siegel, 15 years ago

I just noticed that, and was about to say:

Actually, I see now that the root node has one child, which is a sequence node of GlobalScopeNodeIF. Could someone please clarify that in the javadocs for RootNodeIF.

The overridden method should be:

public SequenceNodeIF<GlobalScopeNodeIF> child(int index) throws NoSuchElementException;

And the comments should clearly indicate that index must be 0, etc.

comment:3 by Stephen Siegel, 15 years ago

Actually, instead of overriding the child method, it would make more sense and be more consistent with similar cases to add a new method to RootNodeIF

public SequenceNodeIF<GlobalScopeNodeIF> getGlobalScopeSequenceNode();

or something like that. It is equivalent to getChild(0).

comment:4 by zirkel, 15 years ago

We actually already have a method for that:

	SequenceNodeIF<GlobalScopeNodeIF> globalScopeNodes();

I just noticed that this is missing the "public" modifier, though.

comment:5 by zirkel, 15 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.