|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.antlr.stringtemplate.StringTemplate
public class StringTemplate
A StringTemplate is a "document" with holes in it where you can stick values. StringTemplate breaks up your template into chunks of text and attribute expressions. StringTemplate ignores everything outside of attribute expressions, treating it as just text to spit out when you call StringTemplate.toString().
Nested Class Summary | |
---|---|
static class |
StringTemplate.Aggregate
An automatically created aggregate of properties. |
static class |
StringTemplate.STAttributeList
Just an alias for ArrayList, but this way I can track whether a list is something ST created or it's an incoming list. |
Field Summary | |
---|---|
static java.lang.String |
ANONYMOUS_ST_NAME
|
protected java.util.Map |
argumentContext
If this template is an embedded template such as when you apply a template to an attribute, then the arguments passed to this template represent the argument context--a set of values computed by walking the argument assignment list. |
protected StringTemplateAST |
argumentsAST
If this template is embedded in another template, the arguments must be evaluated just before each application when applying template to a list of values. |
protected java.util.Map |
attributeRenderers
A Map |
protected java.util.Map |
attributes
Map an attribute name to its value(s). |
protected java.util.List |
chunks
A list of alternating string and ASTExpr references. |
static StringTemplateGroup |
defaultGroup
|
protected StringTemplate |
enclosingInstance
Enclosing instance if I'm embedded within another template. |
protected java.util.LinkedHashMap |
formalArguments
When templates are defined in a group file format, the attribute list is provided including information about attribute cardinality such as present, optional, ... |
protected StringTemplateGroup |
group
This template was created as part of what group? Even if this template was created from a prototype in a supergroup, its group will be the subgroup. |
protected int |
groupFileLine
If this template is defined within a group file, what line number? |
protected boolean |
isRegion
Does this template come from a <@region>...<@end> embedded in another template? |
protected java.lang.String |
name
What's the name of this template? |
protected StringTemplateGroup |
nativeGroup
What group originally defined the prototype for this template? This affects the set of templates I can refer to. |
protected int |
numberOfDefaultArgumentValues
How many formal arguments to this template have default values specified? |
protected boolean |
passThroughAttributes
Normally, formal parameters hide any attributes inherited from the enclosing template with the same name. |
protected java.lang.String |
pattern
The original, immutable pattern/language (not really used again after initial "compilation", setup/parsing). |
protected java.util.List |
referencedAttributes
|
static int |
REGION_EMBEDDED
<@r>...<@end> |
static int |
REGION_EXPLICIT
|
static int |
REGION_IMPLICIT
<@r()> |
protected int |
regionDefType
If someone refs <@r()> in template t, an implicit |
protected java.util.Set |
regions
Set of implicit and embedded regions for this template |
protected int |
templateID
|
static java.lang.String |
VERSION
|
Constructor Summary | |
---|---|
StringTemplate()
Create a blank template with no pattern and no attributes |
|
StringTemplate(java.lang.String template)
Create an anonymous template. |
|
StringTemplate(java.lang.String template,
java.lang.Class lexer)
|
|
StringTemplate(StringTemplateGroup group,
java.lang.String template)
Create an anonymous template with no name, but with a group |
|
StringTemplate(StringTemplateGroup group,
java.lang.String template,
java.util.HashMap attributes)
|
Method Summary | |
---|---|
void |
addChunk(Expr e)
|
void |
addRegionName(java.lang.String name)
|
protected void |
breakTemplateIntoChunks()
Walk a template, breaking it into a list of chunks: Strings and actions/expressions. |
protected void |
checkForTrouble()
Executed after evaluating a template. |
protected void |
checkNullAttributeAgainstFormalArguments(StringTemplate self,
java.lang.String attribute)
A reference to an attribute with no value, must be compared against the formal parameter to see if it exists; if it exists all is well, but if not, throw an exception. |
boolean |
containsRegionName(java.lang.String name)
Does this template ref or embed region name? |
void |
defineEmptyFormalArgumentList()
|
void |
defineFormalArgument(java.lang.String name)
|
void |
defineFormalArgument(java.lang.String name,
StringTemplate defaultValue)
|
void |
defineFormalArguments(java.util.List names)
|
protected void |
dup(StringTemplate from,
StringTemplate to)
Make the 'to' template look exactly like the 'from' template except for the attributes. |
void |
error(java.lang.String msg)
|
void |
error(java.lang.String msg,
java.lang.Throwable e)
|
java.lang.Object |
get(StringTemplate self,
java.lang.String attribute)
Resolve an attribute reference. |
java.util.Map |
getArgumentContext()
|
StringTemplateAST |
getArgumentsAST()
|
java.lang.Object |
getAttribute(java.lang.String name)
|
AttributeRenderer |
getAttributeRenderer(java.lang.Class attributeClassType)
What renderer is registered for this attributeClassType for this template. |
java.util.Map |
getAttributes()
|
java.util.List |
getChunks()
Get a list of the strings and subtemplates and attribute refs in a template. |
void |
getDependencyGraph(java.util.Map edges,
boolean showAttributes)
Get a list of n->m edges where template n contains template m. |
StringTemplate |
getDOTForDependencyGraph(boolean showAttributes)
Generate a DOT file for displaying the template enclosure graph; e.g., digraph prof { "t1" -> "t2" "t1" -> "t3" "t4" -> "t5" } |
StringTemplate |
getEnclosingInstance()
|
java.lang.String |
getEnclosingInstanceStackString()
If an instance of x is enclosed in a y which is in a z, return a String of these instance names in order from topmost to lowest; here that would be "[z y x]". |
java.lang.String |
getEnclosingInstanceStackTrace()
|
StringTemplateErrorListener |
getErrorListener()
|
FormalArgument |
getFormalArgument(java.lang.String name)
|
java.util.Map |
getFormalArguments()
|
StringTemplateGroup |
getGroup()
|
int |
getGroupFileLine()
Return the outermost template's group file line number |
StringTemplate |
getInstanceOf()
Make an instance of this template; it contains an exact copy of everything (except the attributes and enclosing instance pointer). |
java.lang.String |
getName()
|
StringTemplateGroup |
getNativeGroup()
|
StringTemplate |
getOutermostEnclosingInstance()
|
java.lang.String |
getOutermostName()
|
int |
getRegionDefType()
|
java.lang.String |
getTemplate()
|
java.lang.String |
getTemplateDeclaratorString()
|
protected java.lang.String |
getTemplateHeaderString(boolean showAttributes)
|
int |
getTemplateID()
|
static boolean |
inLintMode()
|
static boolean |
isRecursiveEnclosingInstance(StringTemplate st)
Look up the enclosing instance chain (and include this) to see if st is a template already in the enclosing instance chain. |
boolean |
isRegion()
|
FormalArgument |
lookupFormalArgument(java.lang.String name)
From this template upward in the enclosing template tree, recursively look for the formal parameter. |
ASTExpr |
parseAction(java.lang.String action)
|
protected java.lang.String |
parseAggregateAttributeSpec(java.lang.String aggrSpec,
java.util.List properties)
Split "aggrName.{propName1,propName2}" into list [propName1,propName2] and the aggrName. |
void |
printDebugString()
|
protected void |
putToMultiValuedMap(java.util.Map map,
java.lang.Object key,
java.lang.Object value)
Manage a hash table like it has multiple unique values. |
void |
rawSetArgumentAttribute(StringTemplate embedded,
java.util.Map attributes,
java.lang.String name,
java.lang.Object value)
Argument evaluation such as foo(x=y), x must be checked against foo's argument list not this's (which is the enclosing context). |
protected void |
rawSetAttribute(java.util.Map attributes,
java.lang.String name,
java.lang.Object value)
Map a value to a named attribute. |
void |
registerRenderer(java.lang.Class attributeClassType,
AttributeRenderer renderer)
Register a renderer for all objects of a particular type. |
void |
removeAttribute(java.lang.String name)
|
void |
reset()
|
static void |
resetTemplateCounter()
reset the template ID counter to 0; public so that testing routine can access but not really of interest to the user. |
void |
setArgumentContext(java.util.Map ac)
|
void |
setArgumentsAST(StringTemplateAST argumentsAST)
|
void |
setAttribute(java.lang.String name,
int value)
Convenience method to box ints |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Set an attribute for this template. |
protected void |
setAttribute(java.lang.String aggrSpec,
java.lang.Object[] values)
Create an aggregate from the list of properties in aggrSpec and fill with values from values array. |
void |
setAttribute(java.lang.String aggrSpec,
java.lang.Object v1,
java.lang.Object v2)
Set an aggregate attribute with two values. |
void |
setAttribute(java.lang.String aggrSpec,
java.lang.Object v1,
java.lang.Object v2,
java.lang.Object v3)
|
void |
setAttribute(java.lang.String aggrSpec,
java.lang.Object v1,
java.lang.Object v2,
java.lang.Object v3,
java.lang.Object v4)
|
void |
setAttribute(java.lang.String aggrSpec,
java.lang.Object v1,
java.lang.Object v2,
java.lang.Object v3,
java.lang.Object v4,
java.lang.Object v5)
|
void |
setAttributeRenderers(java.util.Map renderers)
Specify a complete map of what object classes should map to which renderer objects. |
void |
setAttributes(java.util.Map attributes)
|
void |
setDefaultArgumentValues()
Set any default argument values that were not set by the invoking template or by setAttribute directly. |
void |
setEnclosingInstance(StringTemplate enclosingInstance)
|
void |
setErrorListener(StringTemplateErrorListener listener)
|
void |
setFormalArguments(java.util.LinkedHashMap args)
|
void |
setGroup(StringTemplateGroup group)
|
void |
setGroupFileLine(int groupFileLine)
|
void |
setIsRegion(boolean isRegion)
|
static void |
setLintMode(boolean lint)
Make StringTemplate check your work as it evaluates templates. |
void |
setName(java.lang.String name)
|
void |
setNativeGroup(StringTemplateGroup nativeGroup)
|
void |
setPassThroughAttributes(boolean passThroughAttributes)
Normally if you call template y from x, y cannot see any attributes of x that are defined as formal parameters of y. |
void |
setPredefinedAttributes()
|
void |
setRegionDefType(int regionDefType)
|
void |
setTemplate(java.lang.String template)
|
java.lang.String |
toDebugString()
|
java.lang.String |
toString()
|
java.lang.String |
toString(int lineWidth)
|
java.lang.String |
toStructureString()
Don't print values, just report the nested structure with attribute names. |
java.lang.String |
toStructureString(int indent)
|
protected void |
trackAttributeReference(java.lang.String name)
Indicates that 'name' has been referenced in this template. |
void |
warning(java.lang.String msg)
|
int |
write(StringTemplateWriter out)
Walk the chunks, asking them to write themselves out according to attribute values of 'this.attributes'. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String VERSION
public static final int REGION_IMPLICIT
public static final int REGION_EMBEDDED
public static final int REGION_EXPLICIT
public static final java.lang.String ANONYMOUS_ST_NAME
protected java.util.List referencedAttributes
protected java.lang.String name
protected int templateID
protected StringTemplate enclosingInstance
protected java.util.Map argumentContext
protected StringTemplateAST argumentsAST
protected java.util.LinkedHashMap formalArguments
protected int numberOfDefaultArgumentValues
protected boolean passThroughAttributes
protected StringTemplateGroup nativeGroup
protected StringTemplateGroup group
protected int groupFileLine
protected java.lang.String pattern
protected java.util.Map attributes
protected java.util.Map attributeRenderers
protected java.util.List chunks
protected int regionDefType
protected boolean isRegion
protected java.util.Set regions
public static StringTemplateGroup defaultGroup
Constructor Detail |
---|
public StringTemplate()
public StringTemplate(java.lang.String template)
public StringTemplate(java.lang.String template, java.lang.Class lexer)
public StringTemplate(StringTemplateGroup group, java.lang.String template)
public StringTemplate(StringTemplateGroup group, java.lang.String template, java.util.HashMap attributes)
Method Detail |
---|
public static void resetTemplateCounter()
protected void dup(StringTemplate from, StringTemplate to)
public StringTemplate getInstanceOf()
public StringTemplate getEnclosingInstance()
public StringTemplate getOutermostEnclosingInstance()
public void setEnclosingInstance(StringTemplate enclosingInstance)
public java.util.Map getArgumentContext()
public void setArgumentContext(java.util.Map ac)
public StringTemplateAST getArgumentsAST()
public void setArgumentsAST(StringTemplateAST argumentsAST)
public java.lang.String getName()
public java.lang.String getOutermostName()
public void setName(java.lang.String name)
public StringTemplateGroup getGroup()
public void setGroup(StringTemplateGroup group)
public StringTemplateGroup getNativeGroup()
public void setNativeGroup(StringTemplateGroup nativeGroup)
public int getGroupFileLine()
public void setGroupFileLine(int groupFileLine)
public void setTemplate(java.lang.String template)
public java.lang.String getTemplate()
public void setErrorListener(StringTemplateErrorListener listener)
public StringTemplateErrorListener getErrorListener()
public void reset()
public void setPredefinedAttributes()
public void removeAttribute(java.lang.String name)
public void setAttribute(java.lang.String name, java.lang.Object value)
public void setAttribute(java.lang.String name, int value)
public void setAttribute(java.lang.String aggrSpec, java.lang.Object v1, java.lang.Object v2)
public void setAttribute(java.lang.String aggrSpec, java.lang.Object v1, java.lang.Object v2, java.lang.Object v3)
public void setAttribute(java.lang.String aggrSpec, java.lang.Object v1, java.lang.Object v2, java.lang.Object v3, java.lang.Object v4)
public void setAttribute(java.lang.String aggrSpec, java.lang.Object v1, java.lang.Object v2, java.lang.Object v3, java.lang.Object v4, java.lang.Object v5)
protected void setAttribute(java.lang.String aggrSpec, java.lang.Object[] values)
protected java.lang.String parseAggregateAttributeSpec(java.lang.String aggrSpec, java.util.List properties)
protected void rawSetAttribute(java.util.Map attributes, java.lang.String name, java.lang.Object value)
public void rawSetArgumentAttribute(StringTemplate embedded, java.util.Map attributes, java.lang.String name, java.lang.Object value)
public java.lang.Object getAttribute(java.lang.String name)
public int write(StringTemplateWriter out) throws java.io.IOException
java.io.IOException
public java.lang.Object get(StringTemplate self, java.lang.String attribute)
protected void breakTemplateIntoChunks()
public ASTExpr parseAction(java.lang.String action)
public int getTemplateID()
public java.util.Map getAttributes()
public java.util.List getChunks()
public void addChunk(Expr e)
public void setAttributes(java.util.Map attributes)
public java.util.Map getFormalArguments()
public void setFormalArguments(java.util.LinkedHashMap args)
public void setDefaultArgumentValues()
public FormalArgument lookupFormalArgument(java.lang.String name)
public FormalArgument getFormalArgument(java.lang.String name)
public void defineEmptyFormalArgumentList()
public void defineFormalArgument(java.lang.String name)
public void defineFormalArguments(java.util.List names)
public void defineFormalArgument(java.lang.String name, StringTemplate defaultValue)
public void setPassThroughAttributes(boolean passThroughAttributes)
public void setAttributeRenderers(java.util.Map renderers)
public void registerRenderer(java.lang.Class attributeClassType, AttributeRenderer renderer)
public AttributeRenderer getAttributeRenderer(java.lang.Class attributeClassType)
public void error(java.lang.String msg)
public void warning(java.lang.String msg)
public void error(java.lang.String msg, java.lang.Throwable e)
public static void setLintMode(boolean lint)
public static boolean inLintMode()
protected void trackAttributeReference(java.lang.String name)
public static boolean isRecursiveEnclosingInstance(StringTemplate st)
public java.lang.String getEnclosingInstanceStackTrace()
public java.lang.String getTemplateDeclaratorString()
protected java.lang.String getTemplateHeaderString(boolean showAttributes)
protected void checkNullAttributeAgainstFormalArguments(StringTemplate self, java.lang.String attribute)
protected void checkForTrouble()
public java.lang.String getEnclosingInstanceStackString()
public boolean isRegion()
public void setIsRegion(boolean isRegion)
public void addRegionName(java.lang.String name)
public boolean containsRegionName(java.lang.String name)
public int getRegionDefType()
public void setRegionDefType(int regionDefType)
public java.lang.String toDebugString()
public java.lang.String toStructureString()
public java.lang.String toStructureString(int indent)
public StringTemplate getDOTForDependencyGraph(boolean showAttributes)
public void getDependencyGraph(java.util.Map edges, boolean showAttributes)
protected void putToMultiValuedMap(java.util.Map map, java.lang.Object key, java.lang.Object value)
public void printDebugString()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(int lineWidth)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |