Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.antlr.stringtemplate.language;
 import java.util.Map;
 import java.util.List;
Represents the name of a formal argument defined in a template: group test; test(a,b) : "$a$ $b$" t() : "blort" Each template has a set of these formal arguments or uses a placeholder object: UNKNOWN (indicating that no arguments were specified such as when a template is loaded from a Note: originally, I tracked cardinality as well as the name of an attribute. I'm leaving the code here as I suspect something may come of it later. Currently, though, cardinality is not used.
public class FormalArgument {
    // the following represent bit positions emulating a cardinality bitset.
    public static final int OPTIONAL = 1;     // a?
    public static final int REQUIRED = 2;     // a
    public static final int ZERO_OR_MORE = 4; // a*
    public static final int ONE_OR_MORE = 8;  // a+
    public static final String[] suffixes = {

When template arguments are not available such as when the user uses "new StringTemplate(...)", then the list of formal arguments must be distinguished from the case where a template can specify args and there just aren't any such as the t() template above.
    public static final LinkedHashMap UNKNOWN = new LinkedHashMap();
    public String name;
    //protected int cardinality = REQUIRED;
If they specified name="value", store the template here
	public FormalArgument(String name) {
		this. = name;
	public FormalArgument(String nameStringTemplate defaultValueST) {
		this. = name;
		this. = defaultValueST;
    public static String getCardinalityName(int cardinality) {
        switch (cardinality) {
            case  : return "optional";
            case  : return "exactly one";
            case  : return "zero-or-more";
            case  : return "one-or-more";
            default : return "unknown";
	public boolean equals(Object o) {
		if ( o==null || !(o instanceof FormalArgument) ) {
			return false;
		if ( !this..equals( ) {
			return false;
		// only check if there is a default value; that's all
		if ( (this.!=null && other.defaultValueST==null) ||
			 (this.==null && other.defaultValueST!=null) ) {
			return false;
		return true;
    public String toString() {
		if ( !=null ) {
			return +"="+;
        return ;
New to GrepCode? Check out our FAQ X