MCPcopy Index your code
hub / github.com/antlr/codebuff / setDefaultArguments

Method setDefaultArguments

output/java8/1.4.13/Interpreter.java:1208–1242  ·  view source on GitHub ↗

Set any default argument values that were not set by the invoking template or by ST#add directly. Note that the default values may be templates. The evaluation context is the invokedST template itself so template default arguments can see other arguments.

(STWriter out, InstanceScope scope)

Source from the content-addressed store, hash-verified

1206 */
1207
1208 public void setDefaultArguments(STWriter out, InstanceScope scope) {
1209 final ST invokedST = scope.st;
1210 if ( invokedST.impl.formalArguments==null || invokedST.impl.numberOfArgsWithDefaultValues==0) {
1211 return;
1212 }
1213 for (FormalArgument arg : invokedST.impl.formalArguments.values()) {
1214 // if no value for attribute and default arg, inject default arg into self
1215 if ( invokedST.locals[arg.index] != ST.EMPTY_ATTR || arg.defaultValueToken==null ) {
1216 continue;
1217 }
1218 //System.out.println("setting def arg "+arg.name+" to "+arg.defaultValueToken);
1219 if ( arg.defaultValueToken.getType()==GroupParser.ANONYMOUS_TEMPLATE ) {
1220 CompiledST code = arg.compiledDefaultValue;
1221 if ( code==null ) {
1222 code = new CompiledST();
1223 }
1224 ST defaultArgST = group.createStringTemplateInternally(code);
1225 defaultArgST.groupThatCreatedThisInstance = group;
1226 // If default arg is template with single expression
1227 // wrapped in parens, x={<(...)>}, then eval to string
1228 // rather than setting x to the template for later
1229 // eval.
1230 String defArgTemplate = arg.defaultValueToken.getText();
1231 if ( defArgTemplate.startsWith("{"+group.delimiterStartChar+"(") && defArgTemplate.endsWith(")"+group.delimiterStopChar+"}") ) {
1232 invokedST.rawSetAttribute(arg.name, toString(out, new InstanceScope(scope, invokedST), defaultArgST));
1233 }
1234 else {
1235 invokedST.rawSetAttribute(arg.name, defaultArgST);
1236 }
1237 }
1238 else {
1239 invokedST.rawSetAttribute(arg.name, arg.defaultValue);
1240 }
1241 }
1242 }
1243
1244 /**
1245 * If an instance of <i>x</i> is enclosed in a <i>y</i> which is in a

Callers 1

execMethod · 0.95

Calls 6

rawSetAttributeMethod · 0.95
toStringMethod · 0.95
valuesMethod · 0.65
getTextMethod · 0.65
getTypeMethod · 0.45

Tested by

no test coverage detected