org.antlr.stringtemplate.language
Class AttributeReflectionController

java.lang.Object
  extended byorg.antlr.stringtemplate.language.AttributeReflectionController

public class AttributeReflectionController
extends java.lang.Object

This class knows how to recursively walk a StringTemplate and all of its attributes to dump a type tree out. STs contain attributes which can contain multiple values. Those values could be other STs or have types that are aggregates (have properties). Those types could have properties etc... I am not using ST itself to print out the text for $attributes$ because it kept getting into nasty self-recursive loops that made my head really hurt. Pretty hard to get ST to print itselt out. Oh well, it was a cool thought while I had it. I just dump raw text to an output buffer now. Easier to understand also.


Field Summary
protected  int indentation
          Can't use ST to output so must do our own indentation
protected  java.util.Stack itemIndexStack
          If in a list, itemIndex=1..n; used to print ordered list in indent().
protected  java.lang.StringBuffer output
          Build up a string buffer as you walk the nested data structures
protected  StringTemplate st
           
protected  java.util.Set typesVisited
          To avoid infinite loops with cyclic type refs, track the types
 
Constructor Summary
AttributeReflectionController(StringTemplate st)
           
 
Method Summary
protected  java.lang.Object getRawValue(java.lang.Object value, java.lang.reflect.Method method)
          Normally we don't actually get the value of properties since we can use normal reflection to get the list of properties of the return type.
protected  void incItemIndex()
           
protected  void indent()
           
 boolean isAtomicType(java.lang.Class type)
          For now, assume only java.lang stuff is atomic as long as it's not a valid map.
protected  void restoreItemIndex()
           
protected  void saveItemIndex()
           
static java.lang.String terseType(java.lang.String typeName)
           
 java.lang.String toString()
           
 void walkAtomicType(java.lang.Class type)
           
 void walkAttributes(StringTemplate st)
          Walk all the attributes in this template, spitting them out.
 void walkAttributeValues(java.lang.Object attributeValue)
           
 void walkMap(java.util.Map map)
          Walk all the attributes in this template, spitting them out.
 void walkPropertiesList(java.lang.Object aggregateValue, java.lang.Class type)
          Get the list of properties by looking for get/isXXX methods.
 void walkStringTemplate(StringTemplate st)
           
 void walkValue(java.lang.Object value, java.lang.Class type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

typesVisited

protected java.util.Set typesVisited
To avoid infinite loops with cyclic type refs, track the types


output

protected java.lang.StringBuffer output
Build up a string buffer as you walk the nested data structures


indentation

protected int indentation
Can't use ST to output so must do our own indentation


itemIndexStack

protected java.util.Stack itemIndexStack
If in a list, itemIndex=1..n; used to print ordered list in indent(). Use a stack since we have nested lists.


st

protected StringTemplate st
Constructor Detail

AttributeReflectionController

public AttributeReflectionController(StringTemplate st)
Method Detail

toString

public java.lang.String toString()

walkStringTemplate

public void walkStringTemplate(StringTemplate st)

walkAttributes

public void walkAttributes(StringTemplate st)
Walk all the attributes in this template, spitting them out.


walkAttributeValues

public void walkAttributeValues(java.lang.Object attributeValue)

walkPropertiesList

public void walkPropertiesList(java.lang.Object aggregateValue,
                               java.lang.Class type)
Get the list of properties by looking for get/isXXX methods. The value is the instance of "type" we are concerned with. Return null if no properties


walkValue

public void walkValue(java.lang.Object value,
                      java.lang.Class type)

walkAtomicType

public void walkAtomicType(java.lang.Class type)

walkMap

public void walkMap(java.util.Map map)
Walk all the attributes in this template, spitting them out.


isAtomicType

public boolean isAtomicType(java.lang.Class type)
For now, assume only java.lang stuff is atomic as long as it's not a valid map.


terseType

public static java.lang.String terseType(java.lang.String typeName)

getRawValue

protected java.lang.Object getRawValue(java.lang.Object value,
                                       java.lang.reflect.Method method)
Normally we don't actually get the value of properties since we can use normal reflection to get the list of properties of the return type. If they as for a value, though, go get it. Need it for string template return types of properties so we can get the attribute lists.


indent

protected void indent()

incItemIndex

protected void incItemIndex()

saveItemIndex

protected void saveItemIndex()

restoreItemIndex

protected void restoreItemIndex()