org.antlr.stringtemplate.language
Class ASTExpr

java.lang.Object
  extended byorg.antlr.stringtemplate.language.Expr
      extended byorg.antlr.stringtemplate.language.ASTExpr
Direct Known Subclasses:
ConditionalExpr

public class ASTExpr
extends Expr

A single string template expression enclosed in $...; separator=...$ parsed into an AST chunk to be evaluated.


Field Summary
static java.lang.String DEFAULT_ATTRIBUTE_NAME
           
static java.lang.String DEFAULT_ATTRIBUTE_NAME_DEPRECATED
           
static java.lang.String DEFAULT_INDEX_VARIABLE_NAME
           
static java.lang.String DEFAULT_MAP_VALUE_NAME
           
static java.lang.String REFLECTION_ATTRIBUTES
          When lint mode is on, this attribute contains a list of reflection objects that tell you about the attributes set by the user of the template.
 
Fields inherited from class org.antlr.stringtemplate.language.Expr
enclosingTemplate, indentation
 
Constructor Summary
ASTExpr(StringTemplate enclosingTemplate, antlr.collections.AST exprTree, java.util.Map options)
           
 
Method Summary
 java.lang.Object add(java.lang.Object a, java.lang.Object b)
          For now, we can only add two objects as strings; convert objects to Strings then cat.
 java.lang.Object applyListOfAlternatingTemplates(StringTemplate self, java.lang.Object attributeValue, java.util.List templatesToApply)
           
 java.lang.Object applyTemplateToListOfAttributes(StringTemplate self, java.util.List attributes, StringTemplate templateToApply)
          For treat the names, phones as lists to be walked in lock step as n=names[i], p=phones[i].
protected  java.lang.String computeSeparator(StringTemplate self, StringTemplateWriter out, java.lang.Object separator)
          A separator is normally just a string literal, but is still an AST that we must evaluate.
static java.lang.Object convertArrayToList(java.lang.Object value)
          Do a standard conversion of array attributes to Lists.
protected  void evaluateArguments(StringTemplate self)
          Evaluate an argument list within the context of the enclosing template but store the values in the context of self, the new embedded template.
 java.lang.Object first(java.lang.Object attribute)
          Return the first attribute if multiple valued or the attribute itself if single-valued.
 antlr.collections.AST getAST()
          Return the tree interpreted when this template is written out.
 java.lang.Object getObjectProperty(StringTemplate self, java.lang.Object o, java.lang.String propertyName)
          Return o.getPropertyName() given o and propertyName.
 StringTemplate getTemplateInclude(StringTemplate enclosing, java.lang.String templateName, StringTemplateAST argumentsAST)
          Call a string template with args and return result.
static boolean isValidMapInstance(java.lang.Class type)
           
static boolean isValidReturnTypeMapInstance(java.lang.Class type)
          A property can be declared as Map, but the instance must be isValidMapInstance().
 java.lang.Object last(java.lang.Object attribute)
          Return the last attribute if multiple valued or the attribute itself if single-valued.
 java.lang.Object rest(java.lang.Object attribute)
          Return the everything but the first attribute if multiple valued or null if single-valued.
protected  void setSoleFormalArgumentToIthValue(StringTemplate embedded, java.util.Map argumentContext, java.lang.Object ithValue)
           
 boolean testAttributeTrue(java.lang.Object a)
          Normally StringTemplate tests presence or absence of attributes for adherence to my principles of separation, but some people disagree and want to change.
protected  int write(StringTemplate self, java.lang.Object o, StringTemplateWriter out, java.lang.Object separator)
           
 int write(StringTemplate self, StringTemplateWriter out)
          To write out the value of an ASTExpr, invoke the evaluator in eval.g to walk the tree writing out the values.
 int writeAttribute(StringTemplate self, java.lang.Object o, StringTemplateWriter out)
          How to spit out an object.
 
Methods inherited from class org.antlr.stringtemplate.language.Expr
getEnclosingTemplate, getIndentation, setIndentation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ATTRIBUTE_NAME

public static final java.lang.String DEFAULT_ATTRIBUTE_NAME
See Also:
Constant Field Values

DEFAULT_ATTRIBUTE_NAME_DEPRECATED

public static final java.lang.String DEFAULT_ATTRIBUTE_NAME_DEPRECATED
See Also:
Constant Field Values

DEFAULT_INDEX_VARIABLE_NAME

public static final java.lang.String DEFAULT_INDEX_VARIABLE_NAME
See Also:
Constant Field Values

DEFAULT_MAP_VALUE_NAME

public static final java.lang.String DEFAULT_MAP_VALUE_NAME
See Also:
Constant Field Values

REFLECTION_ATTRIBUTES

public static final java.lang.String REFLECTION_ATTRIBUTES
When lint mode is on, this attribute contains a list of reflection objects that tell you about the attributes set by the user of the template.

See Also:
Constant Field Values
Constructor Detail

ASTExpr

public ASTExpr(StringTemplate enclosingTemplate,
               antlr.collections.AST exprTree,
               java.util.Map options)
Method Detail

getAST

public antlr.collections.AST getAST()
Return the tree interpreted when this template is written out.


write

public int write(StringTemplate self,
                 StringTemplateWriter out)
          throws java.io.IOException
To write out the value of an ASTExpr, invoke the evaluator in eval.g to walk the tree writing out the values. For efficiency, don't compute a bunch of strings and then pack them together. Write out directly.

Specified by:
write in class Expr
Throws:
java.io.IOException

applyTemplateToListOfAttributes

public java.lang.Object applyTemplateToListOfAttributes(StringTemplate self,
                                                        java.util.List attributes,
                                                        StringTemplate templateToApply)
For treat the names, phones as lists to be walked in lock step as n=names[i], p=phones[i].


applyListOfAlternatingTemplates

public java.lang.Object applyListOfAlternatingTemplates(StringTemplate self,
                                                        java.lang.Object attributeValue,
                                                        java.util.List templatesToApply)

setSoleFormalArgumentToIthValue

protected void setSoleFormalArgumentToIthValue(StringTemplate embedded,
                                               java.util.Map argumentContext,
                                               java.lang.Object ithValue)

getObjectProperty

public java.lang.Object getObjectProperty(StringTemplate self,
                                          java.lang.Object o,
                                          java.lang.String propertyName)
Return o.getPropertyName() given o and propertyName. If o is a stringtemplate then access it's attributes looking for propertyName instead (don't check any of the enclosing scopes; look directly into that object). Also try isXXX() for booleans. Allow HashMap, Hashtable as special case (grab value for key).


testAttributeTrue

public boolean testAttributeTrue(java.lang.Object a)
Normally StringTemplate tests presence or absence of attributes for adherence to my principles of separation, but some people disagree and want to change. For 2.0, if the object is a boolean, do something special. $if(boolean)$ will actually test the value. Now, this breaks my rules of entanglement listed in my paper, but it truly surprises programmers to have booleans always true. Further, the key to isolating logic in the model is avoiding operators (for which you need attribute values). But, no operator is needed to use boolean values. Well, actually I guess "!" (not) is an operator. Regardless, for practical reasons, I'm going to technically violate my rules as I currently have them defined. Perhaps for a future version of the paper I will refine the rules. Post 2.1, I added a check for non-null Iterators, Collections, ... with size==0 to return false. TJP 5/1/2005


add

public java.lang.Object add(java.lang.Object a,
                            java.lang.Object b)
For now, we can only add two objects as strings; convert objects to Strings then cat.


getTemplateInclude

public StringTemplate getTemplateInclude(StringTemplate enclosing,
                                         java.lang.String templateName,
                                         StringTemplateAST argumentsAST)
Call a string template with args and return result. Do not convert to a string yet. It may need attributes that will be available after this is inserted into another template.


writeAttribute

public int writeAttribute(StringTemplate self,
                          java.lang.Object o,
                          StringTemplateWriter out)
How to spit out an object. If it's not a StringTemplate nor a List, just do o.toString(). If it's a StringTemplate, do o.write(out). If it's a Vector, do a write(out, o.elementAt(i)) for all elements. Note that if you do something weird like set the values of a multivalued tag to be vectors, it will effectively flatten it. If self is an embedded template, you might have specified a separator arg; used when is a vector.


write

protected int write(StringTemplate self,
                    java.lang.Object o,
                    StringTemplateWriter out,
                    java.lang.Object separator)

computeSeparator

protected java.lang.String computeSeparator(StringTemplate self,
                                            StringTemplateWriter out,
                                            java.lang.Object separator)
A separator is normally just a string literal, but is still an AST that we must evaluate. The separator can be any expression such as a template include or string cat expression etc...


evaluateArguments

protected void evaluateArguments(StringTemplate self)
Evaluate an argument list within the context of the enclosing template but store the values in the context of self, the new embedded template. For example, bold(item=item) means that bold.item should get the value of enclosing.item.


convertArrayToList

public static java.lang.Object convertArrayToList(java.lang.Object value)
Do a standard conversion of array attributes to Lists.


first

public java.lang.Object first(java.lang.Object attribute)
Return the first attribute if multiple valued or the attribute itself if single-valued. Used in


rest

public java.lang.Object rest(java.lang.Object attribute)
Return the everything but the first attribute if multiple valued or null if single-valued. Used in .


last

public java.lang.Object last(java.lang.Object attribute)
Return the last attribute if multiple valued or the attribute itself if single-valued. Used in . This is pretty slow as it iterates until the last element. Ultimately, I could make a special case for a List or Vector.


isValidMapInstance

public static boolean isValidMapInstance(java.lang.Class type)

isValidReturnTypeMapInstance

public static boolean isValidReturnTypeMapInstance(java.lang.Class type)
A property can be declared as Map, but the instance must be isValidMapInstance().