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

Method setDefaultArguments

output/java/1.4.12/Interpreter.java:1247–1281  ·  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

1245 */
1246
1247 public void setDefaultArguments(STWriter out, InstanceScope scope) {
1248 final ST invokedST = scope.st;
1249 if ( invokedST.impl.formalArguments==null || invokedST.impl.numberOfArgsWithDefaultValues==0) {
1250 return;
1251 }
1252 for (FormalArgument arg : invokedST.impl.formalArguments.values()) {
1253 // if no value for attribute and default arg, inject default arg into self
1254 if ( invokedST.locals[arg.index] != ST.EMPTY_ATTR || arg.defaultValueToken==null ) {
1255 continue;
1256 }
1257 //System.out.println("setting def arg "+arg.name+" to "+arg.defaultValueToken);
1258 if ( arg.defaultValueToken.getType()== GroupParser.ANONYMOUS_TEMPLATE ) {
1259 CompiledST code = arg.compiledDefaultValue;
1260 if ( code==null ) {
1261 code = new CompiledST();
1262 }
1263 ST defaultArgST = group.createStringTemplateInternally(code);
1264 defaultArgST.groupThatCreatedThisInstance = group;
1265 // If default arg is template with single expression
1266 // wrapped in parens, x={<(...)>}, then eval to string
1267 // rather than setting x to the template for later
1268 // eval.
1269 String defArgTemplate = arg.defaultValueToken.getText();
1270 if ( defArgTemplate.startsWith("{"+group.delimiterStartChar+"(")&& defArgTemplate.endsWith(")"+group.delimiterStopChar+"}") ) {
1271 invokedST.rawSetAttribute(arg.name, toString(out, new InstanceScope(scope, invokedST), defaultArgST));
1272 }
1273 else {
1274 invokedST.rawSetAttribute(arg.name, defaultArgST);
1275 }
1276 }
1277 else {
1278 invokedST.rawSetAttribute(arg.name, arg.defaultValue);
1279 }
1280 }
1281 }
1282
1283 /**
1284 * 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