Jalopy 1.0b10

de.hunsicker.jalopy.language
Class JavaNodeHelper

java.lang.Object
  |
  +--de.hunsicker.jalopy.language.JavaNodeHelper

public final class JavaNodeHelper
extends Object

Some common helpers for dealing with the nodes of a Java AST.

Version:
$Revision: 1.1 $
Author:
Marco Hunsicker

Method Summary
static AST advanceToFirstNonParen(AST lparen)
          Advance to the first non-LPAREN node for the rare case where both operands are enclosed by several parenthesis groups, e.g.
static String getDottedName(AST tree)
          Builds the dotted name string representation of the object contained within the JavaNode.
static AST getFirstChainLink(AST node)
          Determines the first chain link in the given chain.
static AST getFirstChild(AST node, int type)
          Return the first occurrence of the child node with the given type, if any.
static JavaNode getLastChild(AST node)
          DOCUMENT ME!
static boolean isAbstractMethod(AST node)
          Determines whether the given node represents an abstract method.
static boolean isAnonymousInnerClass(AST node)
          Determines wether the given node represents an anonymous inner class or interface.
static boolean isBlockNext(AST node)
          Determines whether the given node will be followed by a block.
static boolean isChained(AST node)
          Determines whether the given node is part of a chain.
static boolean isEmptyBlock(AST node)
          Determines whether the given node, which represents a block, is empty.
static boolean isFreestandingBlock(JavaNode node)
          Determines whether the given node represents a freestanding block.
static boolean isInnerClass(AST node)
          Determines whether the given node represents an inner class or interface.
static boolean isLocalVariable(AST node)
          Determines wether the given node represents a local variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isAbstractMethod

public static boolean isAbstractMethod(AST node)
Determines whether the given node represents an abstract method.
Parameters:
node - a METHOD_DEF node.
Returns:
true if the given node represents an abstract method.
Throws:
IllegalArgumentException - if node.getType() != METHOD_DEF

isAnonymousInnerClass

public static boolean isAnonymousInnerClass(AST node)
Determines wether the given node represents an anonymous inner class or interface.
Parameters:
node - a CLASS_DEF or INTERFACE_DEF node.
Returns:
true if the given node represents an anonymous inner class.
Throws:
IllegalArgumentException - if node.getType() != CLASS_DEF || INTERFACE_DEF
Since:
1.0b8

isBlockNext

public static boolean isBlockNext(AST node)
Determines whether the given node will be followed by a block.
Parameters:
node - a node.
Returns:
true if the following node marks the start of a block. Note that if node == null this method always returns false.
Since:
1.0b8

isChained

public static boolean isChained(AST node)
Determines whether the given node is part of a chain.
Parameters:
node - the first child of a chain.
Returns:
true if the given node is part of a chain.
Since:
1.0b8

getDottedName

public static String getDottedName(AST tree)
Builds the dotted name string representation of the object contained within the JavaNode.
Parameters:
tree - the JavaNode containing the entire hierarchy of the object.
Returns:
string.

isEmptyBlock

public static boolean isEmptyBlock(AST node)
Determines whether the given node, which represents a block, is empty.
Parameters:
node - SLIST or OBJBLOCK.
Returns:
true if the given node is empty, i.e. contains no siblings.
Throws:
IllegalArgumentException - if the given node is not of type SLIST, CASESLIST or OBJBLOCK.

getFirstChainLink

public static AST getFirstChainLink(AST node)
Determines the first chain link in the given chain. The first chain node is actually the deepest child node in the AST portion!
Parameters:
node - the last chain link in the node chain.
Returns:
the first node in the chain.
Since:
1.0b8
See Also:
isChained(de.hunsicker.antlr.collections.AST)

getFirstChild

public static AST getFirstChild(AST node,
                                int type)
Return the first occurrence of the child node with the given type, if any.
Parameters:
node - node to search.
type - type to search for.
Returns:
first child node with the given type. Returns null if no child node with the given type exists.

isFreestandingBlock

public static boolean isFreestandingBlock(JavaNode node)
Determines whether the given node represents a freestanding block. A freestanding block is a block without associated block statement.
Parameters:
node - a node representing a block.
Returns:
true if node represents a freestanding block.
Since:
1.0b10

isInnerClass

public static boolean isInnerClass(AST node)
Determines whether the given node represents an inner class or interface.
Parameters:
node - a CLASS_DEF or INTERFACE_DEF node.
Returns:
true if the node represents an inner class or interface.
Throws:
IllegalArgumentException - if node.getType() != CLASS_DEF || INTERFACE_DEF
Since:
1.0b8

getLastChild

public static JavaNode getLastChild(AST node)
DOCUMENT ME!
Parameters:
node - DOCUMENT ME!
Returns:
DOCUMENT ME!
Since:
1.0b8

isLocalVariable

public static boolean isLocalVariable(AST node)
Determines wether the given node represents a local variable.
Parameters:
node - a VARIABLE_DEF node.
Returns:
true if the given node represents a local variable.
Throws:
IllegalArgumentException - if node.getType() != JavaTokenTypes.VARIABLE_DEF.

advanceToFirstNonParen

public static AST advanceToFirstNonParen(AST lparen)
Advance to the first non-LPAREN node for the rare case where both operands are enclosed by several parenthesis groups, e.g. ((LA(4) >= '')), so we acutally skip unnecessary parentheses.
Parameters:
lparen - the first LPAREN child of an expression node.
Returns:
the first non parentheses node or null if no such node exists.
Throws:
NullPointerException - if lparen == null
IllegalArgumentException - if lparen.getType() != JavaTokenTypes.LPAREN

Jalopy 1.0b10

Submit a bug or feature.

For further information and documentation, visit the official Jalopy website.
This page generated: November 14 2002