Methods Summary |
---|
public void | addChild(persistence.antlr.collections.AST node)Add a node to the end of the child list for this node
if (node == null) return;
BaseAST t = this.down;
if (t != null) {
while (t.right != null) {
t = t.right;
}
t.right = (BaseAST)node;
}
else {
this.down = (BaseAST)node;
}
|
public static java.lang.String | decode(java.lang.String text)
char c, c1, c2, c3, c4, c5;
StringBuffer n = new StringBuffer();
for (int i = 0; i < text.length(); i++) {
c = text.charAt(i);
if (c == '&") {
c1 = text.charAt(i + 1);
c2 = text.charAt(i + 2);
c3 = text.charAt(i + 3);
c4 = text.charAt(i + 4);
c5 = text.charAt(i + 5);
if (c1 == 'a" && c2 == 'm" && c3 == 'p" && c4 == ';") {
n.append("&");
i += 5;
}
else if (c1 == 'l" && c2 == 't" && c3 == ';") {
n.append("<");
i += 4;
}
else if (c1 == 'g" && c2 == 't" && c3 == ';") {
n.append(">");
i += 4;
}
else if (c1 == 'q" && c2 == 'u" && c3 == 'o" &&
c4 == 't" && c5 == ';") {
n.append("\"");
i += 6;
}
else if (c1 == 'a" && c2 == 'p" && c3 == 'o" &&
c4 == 's" && c5 == ';") {
n.append("'");
i += 6;
}
else
n.append("&");
}
else
n.append(c);
}
return new String(n);
|
private void | doWorkForFindAll(persistence.antlr.collections.impl.Vector v, persistence.antlr.collections.AST target, boolean partialMatch)
AST sibling;
// Start walking sibling lists, looking for matches.
siblingWalk:
for (sibling = this;
sibling != null;
sibling = sibling.getNextSibling()) {
if ((partialMatch && sibling.equalsTreePartial(target)) ||
(!partialMatch && sibling.equalsTree(target))) {
v.appendElement(sibling);
}
// regardless of match or not, check any children for matches
if (sibling.getFirstChild() != null) {
((BaseAST)sibling.getFirstChild()).doWorkForFindAll(v, target, partialMatch);
}
}
|
public static java.lang.String | encode(java.lang.String text)
char c;
StringBuffer n = new StringBuffer();
for (int i = 0; i < text.length(); i++) {
c = text.charAt(i);
switch (c) {
case '&":
{
n.append("&");
break;
}
case '<":
{
n.append("<");
break;
}
case '>":
{
n.append(">");
break;
}
case '"":
{
n.append(""");
break;
}
case '\'":
{
n.append("'");
break;
}
default :
{
n.append(c);
break;
}
}
}
return new String(n);
|
public boolean | equals(persistence.antlr.collections.AST t)Is node t equal to this in terms of token type and text?
if (t == null) return false;
return this.getText().equals(t.getText()) &&
this.getType() == t.getType();
|
public boolean | equalsList(persistence.antlr.collections.AST t)Is t an exact structural and equals() match of this tree. The
'this' reference is considered the start of a sibling list.
AST sibling;
// the empty tree is not a match of any non-null tree.
if (t == null) {
return false;
}
// Otherwise, start walking sibling lists. First mismatch, return false.
for (sibling = this;
sibling != null && t != null;
sibling = sibling.getNextSibling(), t = t.getNextSibling())
{
// as a quick optimization, check roots first.
if (!sibling.equals(t)) {
return false;
}
// if roots match, do full list match test on children.
if (sibling.getFirstChild() != null) {
if (!sibling.getFirstChild().equalsList(t.getFirstChild())) {
return false;
}
}
// sibling has no kids, make sure t doesn't either
else if (t.getFirstChild() != null) {
return false;
}
}
if (sibling == null && t == null) {
return true;
}
// one sibling list has more than the other
return false;
|
public boolean | equalsListPartial(persistence.antlr.collections.AST sub)Is 'sub' a subtree of this list?
The siblings of the root are NOT ignored.
AST sibling;
// the empty tree is always a subset of any tree.
if (sub == null) {
return true;
}
// Otherwise, start walking sibling lists. First mismatch, return false.
for (sibling = this;
sibling != null && sub != null;
sibling = sibling.getNextSibling(), sub = sub.getNextSibling()) {
// as a quick optimization, check roots first.
if (!sibling.equals(sub)) return false;
// if roots match, do partial list match test on children.
if (sibling.getFirstChild() != null) {
if (!sibling.getFirstChild().equalsListPartial(sub.getFirstChild())) return false;
}
}
if (sibling == null && sub != null) {
// nothing left to match in this tree, but subtree has more
return false;
}
// either both are null or sibling has more, but subtree doesn't
return true;
|
public boolean | equalsTree(persistence.antlr.collections.AST t)Is tree rooted at 'this' equal to 't'? The siblings
of 'this' are ignored.
// check roots first.
if (!this.equals(t)) return false;
// if roots match, do full list match test on children.
if (this.getFirstChild() != null) {
if (!this.getFirstChild().equalsList(t.getFirstChild())) return false;
}
// sibling has no kids, make sure t doesn't either
else if (t.getFirstChild() != null) {
return false;
}
return true;
|
public boolean | equalsTreePartial(persistence.antlr.collections.AST sub)Is 't' a subtree of the tree rooted at 'this'? The siblings
of 'this' are ignored.
// the empty tree is always a subset of any tree.
if (sub == null) {
return true;
}
// check roots first.
if (!this.equals(sub)) return false;
// if roots match, do full list partial match test on children.
if (this.getFirstChild() != null) {
if (!this.getFirstChild().equalsListPartial(sub.getFirstChild())) return false;
}
return true;
|
public persistence.antlr.collections.ASTEnumeration | findAll(persistence.antlr.collections.AST target)Walk the tree looking for all exact subtree matches. Return
an ASTEnumerator that lets the caller walk the list
of subtree roots found herein.
Vector roots = new Vector(10);
AST sibling;
// the empty tree cannot result in an enumeration
if (target == null) {
return null;
}
doWorkForFindAll(roots, target, false); // find all matches recursively
return new ASTEnumerator(roots);
|
public persistence.antlr.collections.ASTEnumeration | findAllPartial(persistence.antlr.collections.AST sub)Walk the tree looking for all subtrees. Return
an ASTEnumerator that lets the caller walk the list
of subtree roots found herein.
Vector roots = new Vector(10);
AST sibling;
// the empty tree cannot result in an enumeration
if (sub == null) {
return null;
}
doWorkForFindAll(roots, sub, true); // find all matches recursively
return new ASTEnumerator(roots);
|
public int | getColumn()
return 0;
|
public persistence.antlr.collections.AST | getFirstChild()Get the first child of this node; null if not children
return down;
|
public int | getLine()
return 0;
|
public persistence.antlr.collections.AST | getNextSibling()Get the next sibling in line after this one
return right;
|
public int | getNumberOfChildren()How many children does this node have?
BaseAST t = this.down;
int n = 0;
if (t != null) {
n = 1;
while (t.right != null) {
t = t.right;
n++;
}
return n;
}
return n;
|
public java.lang.String | getText()Get the token text for this node
return "";
|
public static java.lang.String[] | getTokenNames()Return an array of strings that maps token ID to it's text. @since 2.7.3
return tokenNames;
|
public int | getType()Get the token type for this node
return 0;
|
public abstract void | initialize(int t, java.lang.String txt)
|
public abstract void | initialize(persistence.antlr.collections.AST t)
|
public abstract void | initialize(persistence.antlr.Token t)
|
public void | removeChildren()Remove all children
down = null;
|
public void | setFirstChild(persistence.antlr.collections.AST c)
down = (BaseAST)c;
|
public void | setNextSibling(persistence.antlr.collections.AST n)
right = (BaseAST)n;
|
public void | setText(java.lang.String text)Set the token text for this node
|
public void | setType(int ttype)Set the token type for this node
|
public static void | setVerboseStringConversion(boolean verbose, java.lang.String[] names)
verboseStringConversion = verbose;
tokenNames = names;
|
public java.lang.String | toString()
StringBuffer b = new StringBuffer();
// if verbose and type name not same as text (keyword probably)
if (verboseStringConversion &&
!getText().equalsIgnoreCase(tokenNames[getType()]) &&
!getText().equalsIgnoreCase(StringUtils.stripFrontBack(tokenNames[getType()], "\"", "\""))) {
b.append('[");
b.append(getText());
b.append(",<");
b.append(tokenNames[getType()]);
b.append(">]");
return b.toString();
}
return getText();
|
public java.lang.String | toStringList()Print out a child-sibling tree in LISP notation
AST t = this;
String ts = "";
if (t.getFirstChild() != null) ts += " (";
ts += " " + this.toString();
if (t.getFirstChild() != null) {
ts += ((BaseAST)t.getFirstChild()).toStringList();
}
if (t.getFirstChild() != null) ts += " )";
if (t.getNextSibling() != null) {
ts += ((BaseAST)t.getNextSibling()).toStringList();
}
return ts;
|
public java.lang.String | toStringTree()
AST t = this;
String ts = "";
if (t.getFirstChild() != null) ts += " (";
ts += " " + this.toString();
if (t.getFirstChild() != null) {
ts += ((BaseAST)t.getFirstChild()).toStringList();
}
if (t.getFirstChild() != null) ts += " )";
return ts;
|
public void | xmlSerialize(java.io.Writer out)
// print out this node and all siblings
for (AST node = this;
node != null;
node = node.getNextSibling()) {
if (node.getFirstChild() == null) {
// print guts (class name, attributes)
((BaseAST)node).xmlSerializeNode(out);
}
else {
((BaseAST)node).xmlSerializeRootOpen(out);
// print children
((BaseAST)node.getFirstChild()).xmlSerialize(out);
// print end tag
((BaseAST)node).xmlSerializeRootClose(out);
}
}
|
public void | xmlSerializeNode(java.io.Writer out)
StringBuffer buf = new StringBuffer(100);
buf.append("<");
buf.append(getClass().getName() + " ");
buf.append("text=\"" + encode(getText()) + "\" type=\"" +
getType() + "\"/>");
out.write(buf.toString());
|
public void | xmlSerializeRootClose(java.io.Writer out)
out.write("</" + getClass().getName() + ">\n");
|
public void | xmlSerializeRootOpen(java.io.Writer out)
StringBuffer buf = new StringBuffer(100);
buf.append("<");
buf.append(getClass().getName() + " ");
buf.append("text=\"" + encode(getText()) + "\" type=\"" +
getType() + "\">\n");
out.write(buf.toString());
|