(InstanceScope scope, Map<String, Object> attrs, ST st)
| 564 | } |
| 565 | |
| 566 | void storeArgs(InstanceScope scope, Map<String, Object> attrs, ST st) { |
| 567 | boolean noSuchAttributeReported = false; |
| 568 | if ( attrs !=null ) { |
| 569 | for (Map.Entry<String, Object> argument : attrs.entrySet()) { |
| 570 | if ( !st.impl.hasFormalArgs ) { |
| 571 | if ( st.impl.formalArguments==null || !st.impl.formalArguments.containsKey(argument.getKey()) ) { |
| 572 | try { |
| 573 | // we clone the CompiledST to prevent modifying the original |
| 574 | // formalArguments map during interpretation. |
| 575 | st.impl = st.impl.clone(); |
| 576 | st.add(argument.getKey(), argument.getValue()); |
| 577 | } |
| 578 | catch (CloneNotSupportedException ex) { |
| 579 | noSuchAttributeReported = true; |
| 580 | errMgr.runTimeError(this, scope, ErrorType.NO_SUCH_ATTRIBUTE, argument.getKey()); |
| 581 | } |
| 582 | } |
| 583 | else { |
| 584 | st.rawSetAttribute(argument.getKey(), argument.getValue()); |
| 585 | } |
| 586 | } |
| 587 | else { |
| 588 | // don't let it throw an exception in rawSetAttribute |
| 589 | if ( st.impl.formalArguments==null || !st.impl.formalArguments.containsKey(argument.getKey()) ) { |
| 590 | noSuchAttributeReported = true; |
| 591 | errMgr.runTimeError(this, scope, ErrorType.NO_SUCH_ATTRIBUTE, argument.getKey()); |
| 592 | continue; |
| 593 | } |
| 594 | st.rawSetAttribute(argument.getKey(), argument.getValue()); |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | if ( st.impl.hasFormalArgs) { |
| 599 | boolean argumentCountMismatch = false; |
| 600 | Map<String, FormalArgument> formalArguments = st.impl.formalArguments; |
| 601 | if ( formalArguments==null ) { |
| 602 | formalArguments = Collections.emptyMap(); |
| 603 | } |
| 604 | |
| 605 | // first make sure that all non-default arguments are specified |
| 606 | // ignore this check if a NO_SUCH_ATTRIBUTE error already occurred |
| 607 | if ( !noSuchAttributeReported ) { |
| 608 | for (Map.Entry<String, FormalArgument> formalArgument : formalArguments.entrySet()) { |
| 609 | if ( formalArgument.getValue().defaultValueToken!=null || formalArgument.getValue().defaultValue!=null ) { |
| 610 | // this argument has a default value, so it doesn't need to appear in attrs |
| 611 | continue; |
| 612 | } |
| 613 | if ( attrs==null || |
| 614 | !attrs.containsKey(formalArgument.getKey()) ) { |
| 615 | argumentCountMismatch = true; |
| 616 | break; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | // next make sure there aren't too many arguments. note that the names |
| 622 | // of arguments are checked below as they are applied to the template |
| 623 | // instance, so there's no need to do that here. |
no test coverage detected