xtc.tree
Class Token

java.lang.Object
  extended by xtc.tree.Node
      extended by xtc.tree.Token
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, Locatable

public abstract class Token
extends Node

A token. A token is an immutable tree node containing a source file symbol.

Version:
$Revision: 1.8 $
Author:
Robert Grimm

Constructor Summary
Token()
          Create a new token.
 
Method Summary
static java.lang.String cast(java.lang.Object o)
          Cast the specified object to a string.
 java.lang.Object get(int index)
          Get the child at the specified index.
abstract  java.lang.String getTokenText()
          Treat this node as a token and get its text.
 boolean hasTraversal()
          Determine whether this node supports generic traversal of its children.
 boolean isToken()
          Determine whether this node is a token.
 java.lang.Object set(int index, java.lang.Object value)
          Set the child at the specified index to the specified value.
 int size()
          Get the number of children.
static boolean test(java.lang.Object o)
          Determine whether the specified object represents a string.
 Token toToken()
          Get this node as a token.
 
Methods inherited from class xtc.tree.Node
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, getBoolean, getBooleanProperty, getGeneric, getList, getLocation, getName, getNode, getProperty, getString, getStringProperty, hasLocation, hasName, hasProperty, hasVariable, indexOf, isAnnotation, isEmpty, isGeneric, isList, iterator, lastIndexOf, properties, remove, removeProperty, setLocation, setLocation, setProperty, strip, toAnnotation, toList, toString, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Token

public Token()
Create a new token.

Method Detail

isToken

public boolean isToken()
Description copied from class: Node
Determine whether this node is a token. User-specified classes must not override this method.

Overrides:
isToken in class Node
Returns:
true if this node is a token.
See Also:
Token

toToken

public Token toToken()
Description copied from class: Node
Get this node as a token. User-specified classes must not override this method.

Overrides:
toToken in class Node
Returns:
This node as a token.

getTokenText

public abstract java.lang.String getTokenText()
Description copied from class: Node
Treat this node as a token and get its text. This method strips away any annotations, treats the resulting node as a token, and returns its text. User-specified classes must not override this method.

Overrides:
getTokenText in class Node
Returns:
The token's text.
See Also:
Node.strip()

hasTraversal

public boolean hasTraversal()
Description copied from class: Node
Determine whether this node supports generic traversal of its children. The default implementation returns false.

Overrides:
hasTraversal in class Node
Returns:
true if this node supports generic traversal of its children.

size

public int size()
Description copied from class: Node
Get the number of children. The default implementation signals an unsupported operation exception.

Overrides:
size in class Node
Returns:
The number of children.

get

public java.lang.Object get(int index)
Description copied from class: Node
Get the child at the specified index. The default implementation signals an unsupported operation exception.

Note that instance tests on the returned object may not behave as expected. Notably, any node may be wrapped in annotations. Furthermore, any string may be wrapped in a token (and, recursively, in annotations).

Overrides:
get in class Node
Parameters:
index - The index.
Returns:
The child at that positioin.
See Also:
test(Object), cast(Object), GNode.test(Object), GNode.cast(Object)

set

public java.lang.Object set(int index,
                            java.lang.Object value)
Description copied from class: Node
Set the child at the specified index to the specified value. The default implementation signals an unsupported operation exception.

Overrides:
set in class Node
Parameters:
index - The index.
value - The new value.
Returns:
The old value.

test

public static final boolean test(java.lang.Object o)
Determine whether the specified object represents a string.

Parameters:
o - The object.
Returns:
true if the specifed object is a string or a possibly annotated token.

cast

public static final java.lang.String cast(java.lang.Object o)
Cast the specified object to a string. If the specified object is a string, this method simply returns the string. Otherwise, it casts the object to a node, strips all annotations, and then returns the resulting token's text.

Parameters:
o - The object.
Returns:
The corresponding string.
Throws:
java.lang.ClassCastException - Signals that the object does not describe a string.
See Also:
test(Object)


Copyright © 2012. All Rights Reserved.