MCPcopy Create free account
hub / github.com/antlr/codebuff / storeArgs

Method storeArgs

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

Source from the content-addressed store, hash-verified

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