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