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

Method storeArgs

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

Source from the content-addressed store, hash-verified

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