Top Description Inners Fields Constructors Methods
org.antlr.stringtemplate

public Class StringTemplate

extends Object
Class Inheritance
Imports
java.io.*, java.util.*, java.lang.reflect.Constructor, .InvocationTargetException, org.antlr.stringtemplate.language.*, antlr.*, antlr.collections.AST, .ASTEnumeration

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
StringTemplate.Aggregate

An automatically created aggregate of properties.

public 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

Modifier and TypeField and Description
public static final String
protected Map<K, V>
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 Map<K, V>
attributeRenderers

A Map<class,object> that allows people to register a renderer for a particular kind of object to be displayed in this template.

protected Map<K, V>
attributes

Map an attribute name to its value(s).

protected List<E>
chunks

A list of alternating string and ASTExpr references.

public static StringTemplateGroup
protected StringTemplate
enclosingInstance

Enclosing instance if I'm embedded within another template.

protected LinkedHashMap<K, V>
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?

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>...

pack-priv static boolean
lintMode

track probable issues like setting attribute that is not referenced.

pack-priv StringTemplateErrorListener
listener

Where to report errors

protected String
name

What's the name of this template?

protected StringTemplateGroup
nativeGroup

What group originally defined the prototype for this template?

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 String
pattern

The original, immutable pattern/language (not really used again after initial "compilation", setup/parsing).

protected List<E>
public static final int
public static final int
REGION_EXPLICIT

@t.r() ::= "..." defined manually by coder

public static final int
protected int
regionDefType

If someone refs <@r()> in template t, an implicit @t.r() ::= "" is defined, but you can overwrite this def by defining your own.

protected Set<E>
regions

Set of implicit and embedded regions for this template

private static int
protected int
public static final String

Constructor Summary

AccessConstructor and Description
public
StringTemplate()

Create a blank template with no pattern and no attributes

public
StringTemplate(String template)

Create an anonymous template.

public
StringTemplate(String template, Class<T> lexer)

public
StringTemplate(StringTemplateGroup group, String template)

Create an anonymous template with no name, but with a group

public
StringTemplate(StringTemplateGroup group, String template, HashMap<K, V> attributes)

Method Summary

Modifier and TypeMethod and Description
public void
public void
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, 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.

public boolean
containsRegionName(String name)

Does this template ref or embed region name?

public void
public void
public void
public void
protected void
dup(StringTemplate from, StringTemplate to)

Make the 'to' template look exactly like the 'from' template except for the attributes.

public void
public void
public Object
get(StringTemplate self, String attribute)

Resolve an attribute reference.

public Map<K, V>
public StringTemplateAST
public Object
public AttributeRenderer
getAttributeRenderer(Class<T> attributeClassType)

What renderer is registered for this attributeClassType for this template.

public Map<K, V>
public List<E>
getChunks()

Get a list of the strings and subtemplates and attribute refs in a template.

public void
getDependencyGraph(Map<K, V> edges, boolean showAttributes)

Get a list of n->m edges where template n contains template m.

public StringTemplate
getDOTForDependencyGraph(boolean showAttributes)

Generate a DOT file for displaying the template enclosure graph; e.g., digraph prof { "t1" -> "t2" "t1" -> "t3" "t4" -> "t5" }

public StringTemplate
public 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]".

public String
public StringTemplateErrorListener
public FormalArgument
public Map<K, V>
public StringTemplateGroup
public int
getGroupFileLine()

Return the outermost template's group file line number

public StringTemplate
getInstanceOf()

Make an instance of this template; it contains an exact copy of everything (except the attributes and enclosing instance pointer).

public String
public StringTemplateGroup
private static synchronized int
public StringTemplate
public String
public int
public String
public String
protected String
getTemplateHeaderString(boolean showAttributes)

public int
public static boolean
public 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.

public boolean
public FormalArgument
lookupFormalArgument(String name)

From this template upward in the enclosing template tree, recursively look for the formal parameter.

public ASTExpr
protected String
parseAggregateAttributeSpec(String aggrSpec, List<E> properties)

Split "aggrName.{propName1,propName2}" into list [propName1,propName2] and the aggrName.

public void
protected void
putToMultiValuedMap(Map<K, V> map, Object key, Object value)

Manage a hash table like it has multiple unique values.

public void
rawSetArgumentAttribute(StringTemplate embedded, Map<K, V> attributes, String name, 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(Map<K, V> attributes, String name, Object value)

Map a value to a named attribute.

public void
registerRenderer(Class<T> attributeClassType, AttributeRenderer renderer)

Register a renderer for all objects of a particular type.

public void
public void
public 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.

public void
public void
public void
setAttribute(String name, Object value)

Set an attribute for this template.

public void
setAttribute(String name, int value)

Convenience method to box ints

public void
setAttribute(String aggrSpec, Object v1, Object v2)

Set an aggregate attribute with two values.

public void
setAttribute(String aggrSpec, Object v1, Object v2, Object v3)

public void
setAttribute(String aggrSpec, Object v1, Object v2, Object v3, Object v4)

public void
setAttribute(String aggrSpec, Object v1, Object v2, Object v3, Object v4, Object v5)

protected void
setAttribute(String aggrSpec, Object[] values)

Create an aggregate from the list of properties in aggrSpec and fill with values from values array.

public void
setAttributeRenderers(Map<K, V> renderers)

Specify a complete map of what object classes should map to which renderer objects.

public void
setAttributes(Map<K, V> attributes)

public void
setDefaultArgumentValues()

Set any default argument values that were not set by the invoking template or by setAttribute directly.

public void
public void
public void
public void
public void
setGroupFileLine(int groupFileLine)

public void
setIsRegion(boolean isRegion)

public static void
setLintMode(boolean lint)

Make StringTemplate check your work as it evaluates templates.

public void
public void
public 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.

public void
public void
setRegionDefType(int regionDefType)

public void
setTemplate(String template)

public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public String
toString(int lineWidth)

public String
toStructureString()

Don't print values, just report the nested structure with attribute names.

public String
toStructureString(int indent)

protected void
trackAttributeReference(String name)

Indicates that 'name' has been referenced in this template.

public void
public int
write(StringTemplateWriter out)

Walk the chunks, asking them to write themselves out according to attribute values of 'this.attributes'.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait