Methods Summary |
---|
public static void | appendEscapedMultibyteChars(java.lang.String text, java.lang.StringBuffer buf)
char[] chars = text.toCharArray();
for (int i = 0; i < chars.length; i++) {
char aChar = chars[i];
if (aChar > 256) {
buf.append("\\u");
buf.append(Integer.toHexString(aChar));
}
else
buf.append(aChar);
}
|
public static java.lang.String | escapeMultibyteChars(java.lang.String text)
StringBuffer buf = new StringBuffer();
appendEscapedMultibyteChars(text,buf);
return buf.toString();
|
public static java.lang.String | getConstantName(java.lang.Class tokenTypeConstants, int type)Get a single token type name in the specified set of token type constants (interface).
String tokenTypeName = null;
if ( tokenTypeConstants != null ) {
Field[] fields = tokenTypeConstants.getFields();
for ( int i = 0; i < fields.length; i++ ) {
Field field = fields[i];
tokenTypeName = getTokenTypeName( field, type, true );
if ( tokenTypeName != null ) {
break; // Stop if found.
}
} // for
} // if type constants were provided
// Use the integer value if no token type name was found
if ( tokenTypeName == null ) {
tokenTypeName = Integer.toString( type );
}
return tokenTypeName;
|
private static java.lang.String | getTokenTypeName(java.lang.reflect.Field field, int type, boolean checkType)
if ( Modifier.isStatic( field.getModifiers() ) ) {
try {
Object value = field.get( null );
if ( !checkType ) {
return field.getName();
}
else if ( value instanceof Integer ) {
Integer integer = ( Integer ) value;
if ( integer.intValue() == type ) {
return field.getName();
}
} // if value is an integer
} // try
catch ( IllegalArgumentException ignore ) {
}
catch ( IllegalAccessException ignore ) {
}
} // if the field is static
return null;
|
private java.lang.String | getTokenTypeName(int type)Returns the token type name for the given token type.
// If the class with the constants in it was not supplied, just
// use the integer token type as the token type name.
if ( tokenTypeConstants == null ) {
return Integer.toString( type );
}
// Otherwise, create a type id -> name map from the class if it
// hasn't already been created.
if ( tokenTypeNamesByTokenType == null ) {
Field[] fields = tokenTypeConstants.getFields();
tokenTypeNamesByTokenType = new HashMap();
String tokenTypeName = null;
for ( int i = 0; i < fields.length; i++ ) {
Field field = fields[i];
tokenTypeName = getTokenTypeName( field, type, false );
if ( tokenTypeName != null ) {
try {
tokenTypeNamesByTokenType.put( field.get( null ), field.getName() );
}
catch ( IllegalAccessException ignore ) {
}
}
} // for
} // if the map hasn't been created.
return ( String ) tokenTypeNamesByTokenType.get( new Integer( type ) );
|
public boolean | isShowClassNames()Returns true if the node class names will be displayed.
return showClassNames;
|
public java.lang.String | nodeToString(antlr.collections.AST ast, boolean showClassName)
if ( ast == null ) {
return "{null}";
}
StringBuffer buf = new StringBuffer();
buf.append( "[" ).append( getTokenTypeName( ast.getType() ) ).append( "] " );
if ( showClassName ) {
buf.append( StringHelper.unqualify( ast.getClass().getName() ) ).append( ": " );
}
buf.append( "'" );
String text = ast.getText();
appendEscapedMultibyteChars(text, buf);
buf.append( "'" );
if ( ast instanceof DisplayableNode ) {
DisplayableNode displayableNode = ( DisplayableNode ) ast;
// Add a space before the display text.
buf.append( " " ).append( displayableNode.getDisplayText() );
}
String s = buf.toString();
return s;
|
public void | setShowClassNames(boolean showClassNames)Enables or disables AST node class name display.
this.showClassNames = showClassNames;
|
public java.lang.String | showAsString(antlr.collections.AST ast, java.lang.String header)Prints the AST in 'ASCII art' tree form into a string.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream( baos );
ps.println( header );
showAst( ast, ps );
ps.flush();
return new String( baos.toByteArray() );
|
private void | showAst(java.util.ArrayList parents, java.io.PrintWriter pw, antlr.collections.AST ast)
if ( ast == null ) {
pw.println( "AST is null!" );
return;
}
for ( int i = 0; i < parents.size(); i++ ) {
AST parent = ( AST ) parents.get( i );
if ( parent.getNextSibling() == null ) {
pw.print( " " );
}
else {
pw.print( " | " );
}
}
if ( ast.getNextSibling() == null ) {
pw.print( " \\-" );
}
else {
pw.print( " +-" );
}
showNode( pw, ast );
ArrayList newParents = new ArrayList( parents );
newParents.add( ast );
for ( AST child = ast.getFirstChild(); child != null; child = child.getNextSibling() ) {
showAst( newParents, pw, child );
}
newParents.clear();
|
private void | showAst(antlr.collections.AST ast, java.io.PrintStream out)Prints the AST in 'ASCII art' tree form to the specified print stream.
showAst( ast, new PrintWriter( out ) );
|
public void | showAst(antlr.collections.AST ast, java.io.PrintWriter pw)Prints the AST in 'ASCII art' tree form to the specified print writer.
ArrayList parents = new ArrayList();
showAst( parents, pw, ast );
pw.flush();
|
private void | showNode(java.io.PrintWriter pw, antlr.collections.AST ast)
String s = nodeToString( ast, isShowClassNames() );
pw.println( s );
|