MCPcopy Create free account
hub / github.com/antlr/codebuff / setDefaultArguments

Method setDefaultArguments

output/java/1.4.17/Interpreter.java:1264–1299  ·  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

1262 */
1263
1264 public void setDefaultArguments(STWriter out, InstanceScope scope) {
1265 final ST invokedST = scope.st;
1266 if ( invokedST.impl.formalArguments==null || invokedST.impl.numberOfArgsWithDefaultValues==0) {
1267 return;
1268 }
1269 for (FormalArgument arg : invokedST.impl.formalArguments.values()) {
1270 // if no value for attribute and default arg, inject default arg into self
1271 if ( invokedST.locals[arg.index]!= ST.EMPTY_ATTR || arg.defaultValueToken==null ) {
1272 continue;
1273 }
1274 //System.out.println("setting def arg "+arg.name+" to "+arg.defaultValueToken);
1275 if ( arg.defaultValueToken.getType()== GroupParser.ANONYMOUS_TEMPLATE ) {
1276 CompiledST code = arg.compiledDefaultValue;
1277 if ( code==null ) {
1278 code = new CompiledST();
1279 }
1280 ST defaultArgST = group.createStringTemplateInternally(code);
1281 defaultArgST.groupThatCreatedThisInstance = group;
1282 // If default arg is template with single expression
1283 // wrapped in parens, x={<(...)>}, then eval to string
1284 // rather than setting x to the template for later
1285 // eval.
1286 String defArgTemplate = arg.defaultValueToken.getText();
1287 if ( defArgTemplate.startsWith("{"+group.delimiterStartChar+"(") && defArgTemplate.endsWith(")"+group.delimiterStopChar+"}") ) {
1288 invokedST.rawSetAttribute(arg.name,
1289 toString(out, new InstanceScope(scope, invokedST), defaultArgST));
1290 }
1291 else {
1292 invokedST.rawSetAttribute(arg.name, defaultArgST);
1293 }
1294 }
1295 else {
1296 invokedST.rawSetAttribute(arg.name, arg.defaultValue);
1297 }
1298 }
1299 }
1300
1301 /**
1302 * 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