Represents the name of a formal argument defined in a template: test(a,b,x=defaultvalue) ::= "<a> <n> <x>" Each template has a set of these formal arguments or sets CompiledST#hasFormalArgs to false (indicating that no arguments were specified such as
| 46 | |
| 47 | |
| 48 | public class FormalArgument { |
| 49 | /* |
| 50 | // the following represent bit positions emulating a cardinality bitset. |
| 51 | public static final int OPTIONAL = 1; // a? |
| 52 | public static final int REQUIRED = 2; // a |
| 53 | public static final int ZERO_OR_MORE = 4; // a* |
| 54 | public static final int ONE_OR_MORE = 8; // a+ |
| 55 | public static final String[] suffixes = { |
| 56 | null, |
| 57 | "?", |
| 58 | "", |
| 59 | null, |
| 60 | "*", |
| 61 | null, |
| 62 | null, |
| 63 | null, |
| 64 | "+" |
| 65 | }; |
| 66 | protected int cardinality = REQUIRED; |
| 67 | */ |
| 68 | public String name; |
| 69 | public int index; // which argument is it? from 0..n-1 |
| 70 | |
| 71 | /** If they specified default value {@code x=y}, store the token here */ |
| 72 | public Token defaultValueToken; |
| 73 | public Object defaultValue; // x="str", x=true, x=false |
| 74 | public CompiledST compiledDefaultValue; // x={...} |
| 75 | |
| 76 | public FormalArgument(String name) { |
| 77 | this.name = name; |
| 78 | } |
| 79 | public FormalArgument(String name, Token defaultValueToken) { |
| 80 | this.name = name; |
| 81 | this.defaultValueToken = defaultValueToken; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | public static String getCardinalityName(int cardinality) { |
| 86 | switch (cardinality) { |
| 87 | case OPTIONAL : return "optional"; |
| 88 | case REQUIRED : return "exactly one"; |
| 89 | case ZERO_OR_MORE : return "zero-or-more"; |
| 90 | case ONE_OR_MORE : return "one-or-more"; |
| 91 | default : return "unknown"; |
| 92 | } |
| 93 | } |
| 94 | */ |
| 95 | |
| 96 | @Override |
| 97 | public int hashCode() { |
| 98 | return name.hashCode()+defaultValueToken.hashCode(); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public boolean equals(Object o) { |
| 103 | if ( o==null || !(o instanceof FormalArgument) ) { |
| 104 | return false; |
| 105 | } |
nothing calls this directly
no outgoing calls
no test coverage detected