de.hunsicker.jalopy.language
Class JavaNodeHelper

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

public final class JavaNodeHelper
extends java.lang.Object

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

Version:
$Revision: 1.1.2.2 $
Author:
Marco Hunsicker

Method Summary
static antlr.collections.AST advanceToFirstNonParen(antlr.collections.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 java.lang.String getDottedName(antlr.collections.AST tree)
          Builds the dotted name string representation of the object contained within the JavaNode.
static antlr.collections.AST getFirstChainLink(antlr.collections.AST node)
          Determines the first chain link in the given chain.
static antlr.collections.AST getFirstChild(antlr.collections.AST node, int type)
          Return the first occurrence of the child node with the given type, if any.
static JavaNode getLastChild(antlr.collections.AST node)
          DOCUMENT ME!
static boolean isAbstractMethod(antlr.collections.AST node)
          Determines whether the given node represents an abstract method.
static boolean isAnonymousInnerClass(antlr.collections.AST node)
          Determines wether the given node represents an anonymous inner class or interface.
static boolean isBlockNext(antlr.collections.AST node)
          Determines whether the given node will be followed by a block.
static boolean isChained(antlr.collections.AST node)
          Determines whether the given node is part of a chain.
static boolean isEmptyBlock(antlr.collections.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(antlr.collections.AST node)
          Determines whether the given node represents an inner class or interface.
static boolean isLocalVariable(antlr.collections.AST node)
          Determines whether 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(antlr.collections.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:
java.lang.IllegalArgumentException - if node.getType() != METHOD_DEF

isAnonymousInnerClass

public static boolean isAnonymousInnerClass(antlr.collections.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:
java.lang.IllegalArgumentException - if node.getType() != CLASS_DEF || INTERFACE_DEF
Since:
1.0b8

isBlockNext

public static boolean isBlockNext(antlr.collections.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(antlr.collections.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 java.lang.String getDottedName(antlr.collections.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(antlr.collections.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:
java.lang.IllegalArgumentException - if the given node is not of type SLIST, CASESLIST or OBJBLOCK.

getFirstChainLink

public static antlr.collections.AST getFirstChainLink(antlr.collections.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(antlr.collections.AST)

getFirstChild

public static antlr.collections.AST getFirstChild(antlr.collections.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(antlr.collections.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:
java.lang.IllegalArgumentException - if node.getType() != CLASS_DEF || INTERFACE_DEF
Since:
1.0b8

getLastChild

public static JavaNode getLastChild(antlr.collections.AST node)
DOCUMENT ME!

Parameters:
node - DOCUMENT ME!
Returns:
DOCUMENT ME!
Since:
1.0b8

isLocalVariable

public static boolean isLocalVariable(antlr.collections.AST node)
Determines whether the given node represents a local variable.

Parameters:
node - a VARIABLE_DEF node.
Returns:
true if the given node represents a local variable.
Throws:
java.lang.IllegalArgumentException - if node.getType() != JavaTokenTypes.VARIABLE_DEF.

advanceToFirstNonParen

public static antlr.collections.AST advanceToFirstNonParen(antlr.collections.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 actually 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:
java.lang.NullPointerException - if lparen == null
java.lang.IllegalArgumentException - if lparen.getType() != JavaTokenTypes.LPAREN


Copyright © 1997-2005 Jalopy. All Rights Reserved.