MCPcopy Index your code
hub / github.com/antlr/codebuff / storeArgs

Method storeArgs

output/java/1.4.17/Interpreter.java:566–633  ·  view source on GitHub ↗
(InstanceScope scope, Map<String, Object> attrs, ST st)

Source from the content-addressed store, hash-verified

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.

Callers 2

_execMethod · 0.95
super_newMethod · 0.95

Calls 14

entrySetMethod · 0.65
containsKeyMethod · 0.65
getKeyMethod · 0.65
addMethod · 0.65
getValueMethod · 0.65
runTimeErrorMethod · 0.65
sizeMethod · 0.65
iteratorMethod · 0.65
keySetMethod · 0.65
nextMethod · 0.65
cloneMethod · 0.45
rawSetAttributeMethod · 0.45

Tested by

no test coverage detected