org.jrubyparser.ast
Class Node

java.lang.Object
  extended by org.jrubyparser.ast.Node
All Implemented Interfaces:
ISourcePositionHolder
Direct Known Subclasses:
AliasNode, ArgAuxillaryNode, ArgsNode, ArgsPushNode, ArgumentNode, AssignableNode, AttrAssignNode, BackRefNode, BareKeywordNode, BeginNode, BignumNode, BinaryOperatorBaseNode, BlockArg18Node, BlockPassNode, BreakNode, CallNode, CaseNode, ClassNode, ClassVarNode, Colon3Node, ConstNode, DefinedNode, DotNode, EncodingNode, EnsureNode, EvStrNode, FCallNode, FixnumNode, FlipNode, FloatNode, GlobalVarNode, HashNode, IfNode, ImplicitNilNode, InstVarNode, IterNode, KeywordArgNode, ListNode, LiteralNode, Match2Node, Match3Node, MatchNode, MethodDefNode, ModuleNode, NamedNode, NewlineNode, NextNode, NotNode, NthRefNode, OpAsgnNode, OpElementAsgnNode, OptArgNode, RedoNode, RegexpNode, RescueBodyNode, RescueNode, RetryNode, ReturnNode, RootNode, SClassNode, SplatNode, StarNode, StrNode, SuperNode, SValueNode, SyntaxNode, ToAryNode, UnaryCallNode, UndefNode, UntilNode, VAliasNode, WhenNode, WhileNode, XStrNode, YieldNode, ZArrayNode, ZeroArgNode, ZSuperNode

public abstract class Node
extends Object
implements ISourcePositionHolder

Base class for all Nodes in the AST


Constructor Summary
Node(SourcePosition position)
           
 
Method Summary
abstract  Object accept(NodeVisitor visitor)
           
 Node adopt(Node child)
           
 Node adopt(Node child, int index)
           
protected  Node adoptUsingNodesPosition(Node node)
          Adopt the node in it's proper location amongst the children of this node.
 List<Node> childNodes()
           
 int comparePositionWith(Node testNode)
          Is the testNode before, inside, or after this node?
protected static List<Node> createList(Node... nodes)
           
 IScope getClosestIScope()
          Get the most immediate ParameterScope.
 IModuleScope getClosestModule()
          Get closest parent Module/Class/SClass for this node
 Node getGrandParent()
           
 CommentNode getInlineComment()
          Get the comment which happens to appear on the same line as this node immediately after it.
 IterNode getInnermostIter()
          Return closest iter node unless this is contained within a non-block scope and then return null instead.
 MethodDefNode getMethodFor()
          Which method is this node contained in?
 Node getNodeAt(int offset)
          Find the leaf node (which is not invisible) at the specified offset).
protected  String getNodeName()
           
abstract  NodeType getNodeType()
           
 IterNode getOutermostIter()
           
 Node getParent()
           
 SourcePosition getPosition()
          Location of this node within the source
 SourcePosition getPositionIncludingComments()
           
 List<CommentNode> getPreviousComments()
          Look for all comment nodes immediately preceeding this one.
 void insertAfter(Node newNode)
           
 void insertAll(List<? extends Node> nodes)
          Put entire list of nodes into their proper positions based on the SourcePosition specified by each node in the list.
 void insertBefore(Node newNode)
           
 void insertNode(Node node)
           
 boolean isBlockParameter()
          Is this node specifying a parameter in a block statement?
 boolean isDescendentOf(Node testParent)
          Is this node the same or a descendent of the supplied testParent node?
 boolean isLeaf()
          Is this AST node considered a leaf node?
 boolean isMethodParameter()
          Is this node specifying a parameter in a method definition?
 boolean isSame(Node other)
          Checks node for 'sameness' for diffing.
 void setParent(Node parent)
           
 void setPosition(SourcePosition position)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node(SourcePosition position)
Method Detail

getPosition

public SourcePosition getPosition()
Location of this node within the source

Specified by:
getPosition in interface ISourcePositionHolder

adopt

public Node adopt(Node child)

adopt

public Node adopt(Node child,
                  int index)

isSame

public boolean isSame(Node other)
Checks node for 'sameness' for diffing.

Parameters:
other - The node to be compared to.
Returns:
Returns a boolean.

adoptUsingNodesPosition

protected Node adoptUsingNodesPosition(Node node)
Adopt the node in it's proper location amongst the children of this node. Used internally by insertNode. It is possible subclasses will know enough to use it so it is marked protected.


getParent

public Node getParent()

getGrandParent

public Node getGrandParent()

setParent

public void setParent(Node parent)

isDescendentOf

public boolean isDescendentOf(Node testParent)
Is this node the same or a descendent of the supplied testParent node?


setPosition

public void setPosition(SourcePosition position)
Specified by:
setPosition in interface ISourcePositionHolder

accept

public abstract Object accept(NodeVisitor visitor)

childNodes

public List<Node> childNodes()

createList

protected static List<Node> createList(Node... nodes)

toString

public String toString()
Overrides:
toString in class Object

getNodeName

protected String getNodeName()

getPositionIncludingComments

public SourcePosition getPositionIncludingComments()

isLeaf

public boolean isLeaf()
Is this AST node considered a leaf node?


getNodeType

public abstract NodeType getNodeType()
Returns:
the nodeId

insertAll

public void insertAll(List<? extends Node> nodes)
Put entire list of nodes into their proper positions based on the SourcePosition specified by each node in the list. This list must be in sorted order to work.

Parameters:
nodes -

insertNode

public void insertNode(Node node)

insertBefore

public void insertBefore(Node newNode)

insertAfter

public void insertAfter(Node newNode)

comparePositionWith

public int comparePositionWith(Node testNode)
Is the testNode before, inside, or after this node?

Returns:
-1 if before, 0 is inside, or 1 if after

getPreviousComments

public List<CommentNode> getPreviousComments()
Look for all comment nodes immediately preceeding this one. Additional pure-syntax nodes will not break up contiguous comments (e.g. extra whitespace or an errant ';').


getInlineComment

public CommentNode getInlineComment()
Get the comment which happens to appear on the same line as this node immediately after it.


getNodeAt

public Node getNodeAt(int offset)
Find the leaf node (which is not invisible) at the specified offset).

Parameters:
offset - in characters into the source unit

getMethodFor

public MethodDefNode getMethodFor()
Which method is this node contained in?

Returns:
the method or null if one cannot be found

getClosestModule

public IModuleScope getClosestModule()
Get closest parent Module/Class/SClass for this node


getInnermostIter

public IterNode getInnermostIter()
Return closest iter node unless this is contained within a non-block scope and then return null instead.


getOutermostIter

public IterNode getOutermostIter()

getClosestIScope

public IScope getClosestIScope()
Get the most immediate ParameterScope.

Returns:

isBlockParameter

public boolean isBlockParameter()
Is this node specifying a parameter in a block statement?


isMethodParameter

public boolean isMethodParameter()
Is this node specifying a parameter in a method definition?



Copyright © 2013. All Rights Reserved.