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