(InstanceScope scope, Map<String, Object> attrs, ST st)
| 518 | } |
| 519 | |
| 520 | void storeArgs(InstanceScope scope, Map<String, Object> attrs, ST st) { |
| 521 | boolean noSuchAttributeReported = false; |
| 522 | if ( attrs!=null ) { |
| 523 | for (Map.Entry<String, Object> argument : attrs.entrySet()) { |
| 524 | if ( !st.impl.hasFormalArgs ) { |
| 525 | if ( st.impl.formalArguments==null || !st.impl.formalArguments.containsKey(argument.getKey()) ) { |
| 526 | try { |
| 527 | // we clone the CompiledST to prevent modifying the original |
| 528 | // formalArguments map during interpretation. |
| 529 | st.impl = st.impl.clone(); |
| 530 | st.add(argument.getKey(), argument.getValue()); |
| 531 | } |
| 532 | catch (CloneNotSupportedException ex) { |
| 533 | noSuchAttributeReported = true; |
| 534 | errMgr.runTimeError(this, scope, ErrorType.NO_SUCH_ATTRIBUTE, argument.getKey()); |
| 535 | } |
| 536 | } |
| 537 | else { |
| 538 | st.rawSetAttribute(argument.getKey(), argument.getValue()); |
| 539 | } |
| 540 | } |
| 541 | else { |
| 542 | // don't let it throw an exception in rawSetAttribute |
| 543 | if ( st.impl.formalArguments==null || !st.impl.formalArguments.containsKey(argument.getKey()) ) { |
| 544 | noSuchAttributeReported = true; |
| 545 | errMgr.runTimeError(this, scope, ErrorType.NO_SUCH_ATTRIBUTE, argument.getKey()); |
| 546 | continue; |
| 547 | } |
| 548 | st.rawSetAttribute(argument.getKey(), argument.getValue()); |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | if ( st.impl.hasFormalArgs ) { |
| 553 | boolean argumentCountMismatch = false; |
| 554 | Map<String, FormalArgument> formalArguments = st.impl.formalArguments; |
| 555 | if ( formalArguments==null ) { |
| 556 | formalArguments = Collections.emptyMap(); |
| 557 | } |
| 558 | |
| 559 | // first make sure that all non-default arguments are specified |
| 560 | // ignore this check if a NO_SUCH_ATTRIBUTE error already occurred |
| 561 | if ( !noSuchAttributeReported ) { |
| 562 | for (Map.Entry<String, FormalArgument> formalArgument : formalArguments.entrySet()) { |
| 563 | if ( formalArgument.getValue().defaultValueToken!=null || formalArgument.getValue().defaultValue!=null ) { |
| 564 | // this argument has a default value, so it doesn't need to appear in attrs |
| 565 | continue; |
| 566 | } |
| 567 | if ( attrs==null || !attrs.containsKey(formalArgument.getKey()) ) { |
| 568 | argumentCountMismatch = true; |
| 569 | break; |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | // next make sure there aren't too many arguments. note that the names |
| 575 | // of arguments are checked below as they are applied to the template |
| 576 | // instance, so there's no need to do that here. |
| 577 | if ( attrs!=null && attrs.size()> formalArguments.size() ) { |
no test coverage detected