public abstract class GNode extends Node
create(String) or create(String,int) methods
can have a variable number of children. While such nodes provide
considerable flexibility in creating and managing an abstract
syntax tree, their implementation also has a relatively high memory
and thus performance overhead. Consequently, this class provides
another set of create() methods, which directly take
the new node's children as arguments and return nodes specialized
for that number of children. After creation, the number of
children cannot be changed anymore. Code using generic nodes can
test whether a node supports a variable number of children through
Node.hasVariable() and convert fixed size nodes into variable
sized nodes through ensureVariable(GNode).| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_FIXED
The maximum number of children for generic nodes that are
optimized to hold a fixed number of children.
|
| Modifier and Type | Method and Description |
|---|---|
static GNode |
cast(java.lang.Object o)
Cast the specified object to a generic node.
|
static GNode |
create(GNode node)
Create a new generic node that is a (shallow) copy of the
specified node.
|
static GNode |
create(java.lang.String name)
Create a new generic node with the specified name.
|
static GNode |
create(java.lang.String name,
boolean variable)
Create a new generic node with the specified name.
|
static GNode |
create(java.lang.String name,
int capacity)
Create a new generic node with the specified name.
|
static GNode |
create(java.lang.String name,
java.lang.Object child)
Create a new generic node with the specified name and child.
|
static GNode |
create(java.lang.String name,
java.lang.Object c1,
java.lang.Object c2)
Create a new generic node with the specified name and children.
|
static GNode |
create(java.lang.String name,
java.lang.Object c1,
java.lang.Object c2,
java.lang.Object c3)
Create a new generic node with the specified name and children.
|
static GNode |
create(java.lang.String name,
java.lang.Object c1,
java.lang.Object c2,
java.lang.Object c3,
java.lang.Object c4)
Create a new generic node with the specified name and children.
|
static GNode |
create(java.lang.String name,
java.lang.Object c1,
java.lang.Object c2,
java.lang.Object c3,
java.lang.Object c4,
java.lang.Object c5)
Create a new generic node with the specified name and children.
|
static GNode |
create(java.lang.String name,
java.lang.Object c1,
java.lang.Object c2,
java.lang.Object c3,
java.lang.Object c4,
java.lang.Object c5,
java.lang.Object c6)
Create a new generic node with the specified name and children.
|
static GNode |
create(java.lang.String name,
java.lang.Object c1,
java.lang.Object c2,
java.lang.Object c3,
java.lang.Object c4,
java.lang.Object c5,
java.lang.Object c6,
java.lang.Object c7)
Create a new generic node with the specified name and children.
|
static GNode |
create(java.lang.String name,
java.lang.Object c1,
java.lang.Object c2,
java.lang.Object c3,
java.lang.Object c4,
java.lang.Object c5,
java.lang.Object c6,
java.lang.Object c7,
java.lang.Object c8)
Create a new generic node with the specified name and children.
|
static GNode |
createFromPair(java.lang.String name,
java.lang.Object base,
Pair rest)
Create a new generic node with the specified children.
|
static GNode |
createFromPair(java.lang.String name,
Pair p)
Create a new generic node with the list's nodes as its children.
|
static GNode |
ensureVariable(GNode node)
Ensure that the specified node supports a variable number of
children.
|
boolean |
equals(java.lang.Object o)
Determine whether this generic node equals the specified object.
|
java.lang.String |
getName()
Get the name of this node.
|
int |
hashCode()
Get this generic node's hash code.
|
boolean |
hasName(java.lang.String name)
Determine whether this node's name is the same as the specified
name.
|
boolean |
hasTraversal()
Determine whether this node supports generic traversal of its
children.
|
boolean |
isGeneric()
Determine whether this node is generic.
|
static boolean |
test(java.lang.Object o)
Test whether the specified object is a generic node, possibly
wrapped in annotations.
|
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, get, getBoolean, getBooleanProperty, getGeneric, getList, getLocation, getNode, getProperty, getString, getStringProperty, getTokenText, hasLocation, hasProperty, hasVariable, indexOf, isAnnotation, isEmpty, isList, isToken, iterator, lastIndexOf, properties, remove, removeProperty, set, setLocation, setLocation, setProperty, size, strip, toAnnotation, toList, toString, toToken, writepublic static final int MAX_FIXED
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - The object to compare to.true if this generic node equals the object.public final boolean isGeneric()
public final boolean hasTraversal()
Nodefalse.hasTraversal in class Nodetrue if this node supports generic traversal
of its children.public final java.lang.String getName()
Nodepublic final boolean hasName(java.lang.String name)
Nodepublic static GNode create(java.lang.String name)
name - The name.public static GNode create(java.lang.String name, int capacity)
name - The name.capacity - The initial capacity.java.lang.IllegalArgumentException - Signals that the capacity is negative.public static GNode create(java.lang.String name, boolean variable)
create(String). Invoking this method with a false variabel
flag results in a generic node with no children.name - The name.variable - Flag for whether the new node supports a variable
number of children.public static GNode create(java.lang.String name, java.lang.Object child)
name - The name.child - The child.public static GNode create(java.lang.String name, java.lang.Object c1, java.lang.Object c2)
name - The name.c1 - The first child.c2 - The second child.public static GNode create(java.lang.String name, java.lang.Object c1, java.lang.Object c2, java.lang.Object c3)
name - The name.c1 - The first child.c2 - The second child.c3 - The third child.public static GNode create(java.lang.String name, java.lang.Object c1, java.lang.Object c2, java.lang.Object c3, java.lang.Object c4)
name - The name.c1 - The first child.c2 - The second child.c3 - The third child.c4 - The fourth child.public static GNode create(java.lang.String name, java.lang.Object c1, java.lang.Object c2, java.lang.Object c3, java.lang.Object c4, java.lang.Object c5)
name - The name.c1 - The first child.c2 - The second child.c3 - The third child.c4 - The fourth child.c5 - The fifth child.public static GNode create(java.lang.String name, java.lang.Object c1, java.lang.Object c2, java.lang.Object c3, java.lang.Object c4, java.lang.Object c5, java.lang.Object c6)
name - The name.c1 - The first child.c2 - The second child.c3 - The third child.c4 - The fourth child.c5 - The fifth child.c6 - The sixth child.public static GNode create(java.lang.String name, java.lang.Object c1, java.lang.Object c2, java.lang.Object c3, java.lang.Object c4, java.lang.Object c5, java.lang.Object c6, java.lang.Object c7)
name - The name.c1 - The first child.c2 - The second child.c3 - The third child.c4 - The fourth child.c5 - The fifth child.c6 - The sixth child.c7 - The seventh child.public static GNode create(java.lang.String name, java.lang.Object c1, java.lang.Object c2, java.lang.Object c3, java.lang.Object c4, java.lang.Object c5, java.lang.Object c6, java.lang.Object c7, java.lang.Object c8)
name - The name.c1 - The first child.c2 - The second child.c3 - The third child.c4 - The fourth child.c5 - The fifth child.c6 - The sixth child.c7 - The seventh child.c8 - The eigth child.public static GNode createFromPair(java.lang.String name, Pair p)
name - The name.p - The list of children.public static GNode createFromPair(java.lang.String name, java.lang.Object base, Pair rest)
name - The name.base - The first child.rest - The rest of the children.public static GNode create(GNode node)
node - The node to copy.public static GNode ensureVariable(GNode node)
node - The generic node.public static final boolean test(java.lang.Object o)
o - The object.true if the object is a possibly annotated
generic node.public static final GNode cast(java.lang.Object o)
annotations, they are stripped before returning the object as a generic
node.o - The object.test(Object)Copyright © 2012. All Rights Reserved.