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