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

Method storeArgs

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

Source from the content-addressed store, hash-verified

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