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

Method setDefaultArguments

output/java8/1.4.14/Interpreter.java:1230–1265  ·  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

1228 */
1229
1230 public void setDefaultArguments(STWriter out, InstanceScope scope) {
1231 final ST invokedST = scope.st;
1232 if ( invokedST.impl.formalArguments==null || invokedST.impl.numberOfArgsWithDefaultValues==0) {
1233 return;
1234 }
1235 for (FormalArgument arg : invokedST.impl.formalArguments.values()) {
1236 // if no value for attribute and default arg, inject default arg into self
1237 if ( invokedST.locals[arg.index] != ST.EMPTY_ATTR || arg.defaultValueToken==null ) {
1238 continue;
1239 }
1240 //System.out.println("setting def arg "+arg.name+" to "+arg.defaultValueToken);
1241 if ( arg.defaultValueToken.getType()==GroupParser.ANONYMOUS_TEMPLATE ) {
1242 CompiledST code = arg.compiledDefaultValue;
1243 if ( code==null ) {
1244 code = new CompiledST();
1245 }
1246 ST defaultArgST = group.createStringTemplateInternally(code);
1247 defaultArgST.groupThatCreatedThisInstance = group;
1248 // If default arg is template with single expression
1249 // wrapped in parens, x={<(...)>}, then eval to string
1250 // rather than setting x to the template for later
1251 // eval.
1252 String defArgTemplate = arg.defaultValueToken.getText();
1253 if ( defArgTemplate.startsWith("{"+group.delimiterStartChar+"(") && defArgTemplate.endsWith(")"+group.delimiterStopChar+"}") ) {
1254 invokedST.rawSetAttribute(arg.name,
1255 toString(out, new InstanceScope(scope, invokedST), defaultArgST));
1256 }
1257 else {
1258 invokedST.rawSetAttribute(arg.name, defaultArgST);
1259 }
1260 }
1261 else {
1262 invokedST.rawSetAttribute(arg.name, arg.defaultValue);
1263 }
1264 }
1265 }
1266
1267 /**
1268 * 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