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

Method storeArgs

output/java8/1.4.13/Interpreter.java:520–586  ·  view source on GitHub ↗
(InstanceScope scope, Map<String, Object> attrs, ST st)

Source from the content-addressed store, hash-verified

518 }
519
520 void storeArgs(InstanceScope scope, Map<String, Object> attrs, ST st) {
521 boolean noSuchAttributeReported = false;
522 if ( attrs!=null ) {
523 for (Map.Entry<String, Object> argument : attrs.entrySet()) {
524 if ( !st.impl.hasFormalArgs ) {
525 if ( st.impl.formalArguments==null || !st.impl.formalArguments.containsKey(argument.getKey()) ) {
526 try {
527 // we clone the CompiledST to prevent modifying the original
528 // formalArguments map during interpretation.
529 st.impl = st.impl.clone();
530 st.add(argument.getKey(), argument.getValue());
531 }
532 catch (CloneNotSupportedException ex) {
533 noSuchAttributeReported = true;
534 errMgr.runTimeError(this, scope, ErrorType.NO_SUCH_ATTRIBUTE, argument.getKey());
535 }
536 }
537 else {
538 st.rawSetAttribute(argument.getKey(), argument.getValue());
539 }
540 }
541 else {
542 // don't let it throw an exception in rawSetAttribute
543 if ( st.impl.formalArguments==null || !st.impl.formalArguments.containsKey(argument.getKey()) ) {
544 noSuchAttributeReported = true;
545 errMgr.runTimeError(this, scope, ErrorType.NO_SUCH_ATTRIBUTE, argument.getKey());
546 continue;
547 }
548 st.rawSetAttribute(argument.getKey(), argument.getValue());
549 }
550 }
551 }
552 if ( st.impl.hasFormalArgs ) {
553 boolean argumentCountMismatch = false;
554 Map<String, FormalArgument> formalArguments = st.impl.formalArguments;
555 if ( formalArguments==null ) {
556 formalArguments = Collections.emptyMap();
557 }
558
559 // first make sure that all non-default arguments are specified
560 // ignore this check if a NO_SUCH_ATTRIBUTE error already occurred
561 if ( !noSuchAttributeReported ) {
562 for (Map.Entry<String, FormalArgument> formalArgument : formalArguments.entrySet()) {
563 if ( formalArgument.getValue().defaultValueToken!=null || formalArgument.getValue().defaultValue!=null ) {
564 // this argument has a default value, so it doesn't need to appear in attrs
565 continue;
566 }
567 if ( attrs==null || !attrs.containsKey(formalArgument.getKey()) ) {
568 argumentCountMismatch = true;
569 break;
570 }
571 }
572 }
573
574 // next make sure there aren't too many arguments. note that the names
575 // of arguments are checked below as they are applied to the template
576 // instance, so there's no need to do that here.
577 if ( attrs!=null && attrs.size()> formalArguments.size() ) {

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