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

Method storeArgs

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

Source from the content-addressed store, hash-verified

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