|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectxtc.tree.Node
public abstract class Node
A node in an abstract syntax tree.
Subclasses may optionally support two features. First, a subclass may support generic tree traversal. Such a class must overridehasTraversal() to return
true and must provide meaningful implementations for
size(), get(int), and set(int,Object).
Second, a subclass may support a variable number of
children. Such a class must override hasVariable() to return true and must provide
meaningful implementations for add(Object), add(int,Object), and remove(int).
| Constructor Summary | |
|---|---|
Node()
Create a new node. |
|
Node(Location location)
Create a new node. |
|
| Method Summary | ||
|---|---|---|
Node |
add(int index,
java.lang.Object o)
Add the specified object as a child at the specified index. |
|
Node |
add(java.lang.Object o)
Add the specified object as a child. |
|
Node |
addAll(java.util.Collection<?> c)
Add all values in the specified collection as children. |
|
Node |
addAll(int index,
java.util.Collection<?> c)
Add all values in the specified collection as children at the specified index. |
|
Node |
addAll(int index,
Pair<?> p)
Add all values in the list starting with the specified pair as children at the specified index. |
|
Node |
addAll(Pair<?> p)
Add all values in the list starting with the specified pair as children. |
|
void |
addAllTo(java.util.Collection<java.lang.Object> c)
Add all of this node's children to the specified collection. |
|
Node |
addNode(Node node)
Add the specified node as a child. |
|
boolean |
contains(java.lang.Object o)
Determine whether this node has the specified object as a child. |
|
java.lang.Object |
get(int index)
Get the child at the specified index. |
|
boolean |
getBoolean(int index)
Get the boolean child at the specified index. |
|
boolean |
getBooleanProperty(java.lang.String name)
Get a property value as a boolean. |
|
GNode |
getGeneric(int index)
Get the generic node child at the specified index. |
|
|
getList(int index)
Get the list child at the specified index. |
|
Location |
getLocation()
Get this object's location. |
|
java.lang.String |
getName()
Get the name of this node. |
|
Node |
getNode(int index)
Get the node child at the specified index. |
|
java.lang.Object |
getProperty(java.lang.String name)
Get a property value. |
|
java.lang.String |
getString(int index)
Get the string child at the specified index. |
|
java.lang.String |
getStringProperty(java.lang.String name)
Get a property value as a string. |
|
java.lang.String |
getTokenText()
Treat this node as a token and get its text. |
|
boolean |
hasLocation()
Determine whether this object has a location. |
|
boolean |
hasName(java.lang.String name)
Determine whether this node's name is the same as the specified name. |
|
boolean |
hasProperty(java.lang.String name)
Test if this node has a property. |
|
boolean |
hasTraversal()
Determine whether this node supports generic traversal of its children. |
|
boolean |
hasVariable()
Determine whether this node supports a variable number of children. |
|
int |
indexOf(java.lang.Object o)
Determine the index of the specified object. |
|
boolean |
isAnnotation()
Determine whether this node is an annotation. |
|
boolean |
isEmpty()
Determine whether this node has no children. |
|
boolean |
isGeneric()
Determine whether this node is a generic node. |
|
static boolean |
isList(java.lang.Object o)
Determine whether the specified object is a list of nodes. |
|
boolean |
isToken()
Determine whether this node is a token. |
|
java.util.Iterator<java.lang.Object> |
iterator()
Get an iterator over this node's children. |
|
int |
lastIndexOf(java.lang.Object o)
Determine the last index of the specified object. |
|
java.util.Set<java.lang.String> |
properties()
Get the set of property names. |
|
java.lang.Object |
remove(int index)
Remove the child at the specified index. |
|
java.lang.Object |
removeProperty(java.lang.String name)
Remove a property. |
|
java.lang.Object |
set(int index,
java.lang.Object value)
Set the child at the specified index to the specified value. |
|
void |
setLocation(Locatable locatable)
Set this object's location to the specified locatable's location. |
|
void |
setLocation(Location location)
Set this object's location. |
|
java.lang.Object |
setProperty(java.lang.String name,
java.lang.Object value)
Set the value of a property. |
|
int |
size()
Get the number of children. |
|
Node |
strip()
Strip any annotations. |
|
Annotation |
toAnnotation()
Get this node as an annotation. |
|
static Pair<Node> |
toList(java.lang.Object o)
Convert the specified object to a list of nodes. |
|
java.lang.String |
toString()
Return a human readable representation of this node. |
|
Token |
toToken()
Get this node as a token. |
|
void |
write(java.lang.Appendable out)
Write a human readable representation to the specified appendable. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Node()
public Node(Location location)
location - The source location for the new node.| Method Detail |
|---|
public boolean isToken()
true if this node is a token.Tokenpublic Token toToken()
java.lang.ClassCastException - Signals that this node is not a token.public java.lang.String getTokenText()
java.lang.ClassCastException - Signals that this node is not a token.strip()public boolean isAnnotation()
true if this node is an annotation.Annotationpublic Annotation toAnnotation()
java.lang.ClassCastException - Signals that this node is not an
annotation.public boolean isGeneric()
true if this node is a generic node.GNodepublic java.lang.String getName()
public boolean hasName(java.lang.String name)
name - The name.
true if this node's name equals the
specified name.
public java.lang.Object setProperty(java.lang.String name,
java.lang.Object value)
name - The property name.value - The new property value.
null if the
property didn't have a value.public boolean hasProperty(java.lang.String name)
name - The property name.
true if this node has a property with the
specified name.public java.lang.Object getProperty(java.lang.String name)
name - The property name.
null if the
property doesn't have a value.public boolean getBooleanProperty(java.lang.String name)
false.
name - The property name.
public java.lang.String getStringProperty(java.lang.String name)
name - The property name.
public java.lang.Object removeProperty(java.lang.String name)
name - The property name.
null if the
property didn't have a value.public java.util.Set<java.lang.String> properties()
public boolean hasLocation()
Locatable
hasLocation in interface Locatabletrue if this object has a location.public Location getLocation()
Locatable
getLocation in interface Locatablenull if it does
not have a location.public void setLocation(Location location)
Locatable
setLocation in interface Locatablelocation - This object's location.public void setLocation(Locatable locatable)
Locatable
setLocation in interface Locatablelocatable - The locatable object.public boolean hasTraversal()
false.
true if this node supports generic traversal
of its children.public boolean isEmpty()
true if this node has no children.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public java.util.Iterator<java.lang.Object> iterator()
iterator in interface java.lang.Iterable<java.lang.Object>Token.test(Object),
Token.cast(Object),
GNode.test(Object),
GNode.cast(Object)public int size()
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public java.lang.Object get(int index)
index - The index.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.Token.test(Object),
Token.cast(Object),
GNode.test(Object),
GNode.cast(Object)public boolean getBoolean(int index)
index - The index.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.ClassCastException - Signals that the child is not a
boolean.
java.lang.UnsupportedOperationException - Signals that this node does
not support generic traversal.public java.lang.String getString(int index)
index - The index.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.ClassCastException - Signals that the child is not a string
nor an annotated token.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public Node getNode(int index)
index - The index.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.ClassCastException - Signals that the child is not a node.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public GNode getGeneric(int index)
annotations, they are
stripped before returning the child as a
generic node.
index - The index.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.ClassCastException - Signals that the child is not a node.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public <T> Pair<T> getList(int index)
index - The index.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.ClassCastException - Signals that the child is not a list.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.
public java.lang.Object set(int index,
java.lang.Object value)
index - The index.value - The new value.
java.lang.IllegalStateException - Signals that this node is
immutable.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.ClassCastException - Signals that the value is not of the
necessary type.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public int indexOf(java.lang.Object o)
o - The object.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public int lastIndexOf(java.lang.Object o)
o - The object.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public boolean contains(java.lang.Object o)
o - The object.
true if this node has the specified object
as a child.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public void addAllTo(java.util.Collection<java.lang.Object> c)
c - The collection.
java.lang.UnsupportedOperationException - Signals that this node
does not support generic traversal.public boolean hasVariable()
false.
true if this node supports a variable number
of children.hasTraversal()public Node add(java.lang.Object o)
o - The object.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.public Node addNode(Node node)
add(Object). For
annotations supporting a variable number of children, this method
adds the annotated node. Any previously added children precede
that node and any children added after the call to this method
succeed that node.
node - The node.
java.lang.IllegalStateException - Signals that this method has
already been invoked on an annotation supporting a variable
number of children.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.
public Node add(int index,
java.lang.Object o)
index - The index.o - The object.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.public Node addAll(Pair<?> p)
p - The pair.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.
public Node addAll(int index,
Pair<?> p)
index - The index.p - The pair.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.public Node addAll(java.util.Collection<?> c)
c - The collection.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.
public Node addAll(int index,
java.util.Collection<?> c)
index - The index.c - The collection.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.public java.lang.Object remove(int index)
index - The index.
java.lang.IndexOutOfBoundsException - Signals that the index is out
of range.
java.lang.UnsupportedOperationException - Signals that this node does
not support a variable number of children.public Node strip()
Annotation
public void write(java.lang.Appendable out)
throws java.io.IOException
Object.toString().
out - The appendable.
java.io.IOException - Signals an I/O error.public java.lang.String toString()
write(Appendable).
toString in class java.lang.Objectpublic static final boolean isList(java.lang.Object o)
o - The object.
true if the specified object is a list of
nodes.public static final Pair<Node> toList(java.lang.Object o)
o - The object, which must be a list of nodes.
java.lang.ClassCastException - Signals that the object is not a list
of nodes.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||