changeset 14057 | b4b0377b8dba |
parent 14056 | 0ea78d6e0b7b |
child 14058 | c7ec7facdd20 |
14056:0ea78d6e0b7b | 14057:b4b0377b8dba |
---|---|
29 import com.sun.tools.javac.code.*; |
29 import com.sun.tools.javac.code.*; |
30 import com.sun.tools.javac.code.Symbol.*; |
30 import com.sun.tools.javac.code.Symbol.*; |
31 import com.sun.tools.javac.code.Type.*; |
31 import com.sun.tools.javac.code.Type.*; |
32 import com.sun.tools.javac.comp.Attr.ResultInfo; |
32 import com.sun.tools.javac.comp.Attr.ResultInfo; |
33 import com.sun.tools.javac.comp.Check.CheckContext; |
33 import com.sun.tools.javac.comp.Check.CheckContext; |
34 import com.sun.tools.javac.comp.DeferredAttr.AttrMode; |
|
35 import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext; |
|
36 import com.sun.tools.javac.comp.DeferredAttr.DeferredType; |
|
34 import com.sun.tools.javac.comp.Infer.InferenceContext; |
37 import com.sun.tools.javac.comp.Infer.InferenceContext; |
35 import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; |
38 import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; |
36 import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate; |
39 import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate; |
37 import com.sun.tools.javac.jvm.*; |
40 import com.sun.tools.javac.jvm.*; |
38 import com.sun.tools.javac.tree.*; |
41 import com.sun.tools.javac.tree.*; |
40 import com.sun.tools.javac.util.*; |
43 import com.sun.tools.javac.util.*; |
41 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
44 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
42 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
45 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
46 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
44 |
47 |
45 import java.util.ArrayList; |
|
46 import java.util.Arrays; |
48 import java.util.Arrays; |
47 import java.util.Collection; |
49 import java.util.Collection; |
48 import java.util.EnumMap; |
50 import java.util.EnumMap; |
49 import java.util.EnumSet; |
51 import java.util.EnumSet; |
50 import java.util.HashSet; |
|
51 import java.util.Iterator; |
52 import java.util.Iterator; |
52 import java.util.Map; |
53 import java.util.Map; |
53 import java.util.Set; |
|
54 |
54 |
55 import javax.lang.model.element.ElementVisitor; |
55 import javax.lang.model.element.ElementVisitor; |
56 |
56 |
57 import static com.sun.tools.javac.code.Flags.*; |
57 import static com.sun.tools.javac.code.Flags.*; |
58 import static com.sun.tools.javac.code.Flags.BLOCK; |
58 import static com.sun.tools.javac.code.Flags.BLOCK; |
75 |
75 |
76 Names names; |
76 Names names; |
77 Log log; |
77 Log log; |
78 Symtab syms; |
78 Symtab syms; |
79 Attr attr; |
79 Attr attr; |
80 DeferredAttr deferredAttr; |
|
80 Check chk; |
81 Check chk; |
81 Infer infer; |
82 Infer infer; |
82 ClassReader reader; |
83 ClassReader reader; |
83 TreeInfo treeinfo; |
84 TreeInfo treeinfo; |
84 Types types; |
85 Types types; |
107 SymbolNotFoundError(ABSENT_TYP); |
108 SymbolNotFoundError(ABSENT_TYP); |
108 |
109 |
109 names = Names.instance(context); |
110 names = Names.instance(context); |
110 log = Log.instance(context); |
111 log = Log.instance(context); |
111 attr = Attr.instance(context); |
112 attr = Attr.instance(context); |
113 deferredAttr = DeferredAttr.instance(context); |
|
112 chk = Check.instance(context); |
114 chk = Check.instance(context); |
113 infer = Infer.instance(context); |
115 infer = Infer.instance(context); |
114 reader = ClassReader.instance(context); |
116 reader = ClassReader.instance(context); |
115 treeinfo = TreeInfo.instance(context); |
117 treeinfo = TreeInfo.instance(context); |
116 types = Types.instance(context); |
118 types = Types.instance(context); |
217 mostSpecificPos = pos; |
219 mostSpecificPos = pos; |
218 pos++; |
220 pos++; |
219 } |
221 } |
220 } |
222 } |
221 String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1"; |
223 String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1"; |
224 List<Type> argtypes2 = Type.map(argtypes, |
|
225 deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, bestSoFar, currentResolutionContext.step)); |
|
222 JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, |
226 JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, |
223 site.tsym, mostSpecificPos, currentResolutionContext.step, |
227 site.tsym, mostSpecificPos, currentResolutionContext.step, |
224 methodArguments(argtypes), methodArguments(typeargtypes)); |
228 methodArguments(argtypes2), |
229 methodArguments(typeargtypes)); |
|
225 JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList()); |
230 JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList()); |
226 log.report(d); |
231 log.report(d); |
227 } |
232 } |
228 |
233 |
229 JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) { |
234 JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) { |
499 resultInfo, |
504 resultInfo, |
500 m, |
505 m, |
501 argtypes, |
506 argtypes, |
502 allowBoxing, |
507 allowBoxing, |
503 useVarargs, |
508 useVarargs, |
509 currentResolutionContext, |
|
504 warn); |
510 warn); |
505 |
511 |
506 checkRawArgumentsAcceptable(env, argtypes, mt.getParameterTypes(), |
512 checkRawArgumentsAcceptable(env, m, argtypes, mt.getParameterTypes(), |
507 allowBoxing, useVarargs, warn); |
513 allowBoxing, useVarargs, warn); |
508 return mt; |
514 return mt; |
515 } |
|
516 |
|
517 Type checkMethod(Env<AttrContext> env, |
|
518 Type site, |
|
519 Symbol m, |
|
520 ResultInfo resultInfo, |
|
521 List<Type> argtypes, |
|
522 List<Type> typeargtypes, |
|
523 Warner warn) { |
|
524 MethodResolutionContext prevContext = currentResolutionContext; |
|
525 try { |
|
526 currentResolutionContext = new MethodResolutionContext(); |
|
527 currentResolutionContext.attrMode = DeferredAttr.AttrMode.CHECK; |
|
528 MethodResolutionPhase step = currentResolutionContext.step = env.info.pendingResolutionPhase; |
|
529 return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, |
|
530 step.isBoxingRequired(), step.isVarargsRequired(), warn); |
|
531 } |
|
532 finally { |
|
533 currentResolutionContext = prevContext; |
|
534 } |
|
509 } |
535 } |
510 |
536 |
511 /** Same but returns null instead throwing a NoInstanceException |
537 /** Same but returns null instead throwing a NoInstanceException |
512 */ |
538 */ |
513 Type instantiate(Env<AttrContext> env, |
539 Type instantiate(Env<AttrContext> env, |
528 } |
554 } |
529 |
555 |
530 /** Check if a parameter list accepts a list of args. |
556 /** Check if a parameter list accepts a list of args. |
531 */ |
557 */ |
532 boolean argumentsAcceptable(Env<AttrContext> env, |
558 boolean argumentsAcceptable(Env<AttrContext> env, |
559 Symbol msym, |
|
533 List<Type> argtypes, |
560 List<Type> argtypes, |
534 List<Type> formals, |
561 List<Type> formals, |
535 boolean allowBoxing, |
562 boolean allowBoxing, |
536 boolean useVarargs, |
563 boolean useVarargs, |
537 Warner warn) { |
564 Warner warn) { |
538 try { |
565 try { |
539 checkRawArgumentsAcceptable(env, argtypes, formals, allowBoxing, useVarargs, warn); |
566 checkRawArgumentsAcceptable(env, msym, argtypes, formals, allowBoxing, useVarargs, warn); |
540 return true; |
567 return true; |
541 } catch (InapplicableMethodException ex) { |
568 } catch (InapplicableMethodException ex) { |
542 return false; |
569 return false; |
543 } |
570 } |
544 } |
571 } |
581 expected, Kinds.kindName(location), location); |
608 expected, Kinds.kindName(location), location); |
582 } |
609 } |
583 }; |
610 }; |
584 |
611 |
585 void checkRawArgumentsAcceptable(Env<AttrContext> env, |
612 void checkRawArgumentsAcceptable(Env<AttrContext> env, |
613 Symbol msym, |
|
586 List<Type> argtypes, |
614 List<Type> argtypes, |
587 List<Type> formals, |
615 List<Type> formals, |
588 boolean allowBoxing, |
616 boolean allowBoxing, |
589 boolean useVarargs, |
617 boolean useVarargs, |
590 Warner warn) { |
618 Warner warn) { |
591 checkRawArgumentsAcceptable(env, infer.emptyContext, argtypes, formals, |
619 checkRawArgumentsAcceptable(env, msym, currentResolutionContext.attrMode(), infer.emptyContext, argtypes, formals, |
592 allowBoxing, useVarargs, warn, resolveHandler); |
620 allowBoxing, useVarargs, warn, resolveHandler); |
593 } |
621 } |
594 |
622 |
595 /** |
623 /** |
596 * Main method applicability routine. Given a list of actual types A, |
624 * Main method applicability routine. Given a list of actual types A, |
597 * a list of formal types F, determines whether the types in A are |
625 * a list of formal types F, determines whether the types in A are |
598 * compatible (by method invocation conversion) with the types in F. |
626 * compatible (by method invocation conversion) with the types in F. |
599 * |
627 * |
600 * Since this routine is shared between overload resolution and method |
628 * Since this routine is shared between overload resolution and method |
601 * type-inference, it is crucial that actual types are converted to the |
629 * type-inference, a (possibly empty) inference context is used to convert |
602 * corresponding 'undet' form (i.e. where inference variables are replaced |
630 * formal types to the corresponding 'undet' form ahead of a compatibility |
603 * with undetvars) so that constraints can be propagated and collected. |
631 * check so that constraints can be propagated and collected. |
604 * |
632 * |
605 * Moreover, if one or more types in A is a poly type, this routine calls |
633 * Moreover, if one or more types in A is a deferred type, this routine uses |
606 * Infer.instantiateArg in order to complete the poly type (this might involve |
634 * DeferredAttr in order to perform deferred attribution. If one or more actual |
607 * deferred attribution). |
635 * deferred types are stuck, they are placed in a queue and revisited later |
636 * after the remainder of the arguments have been seen. If this is not sufficient |
|
637 * to 'unstuck' the argument, a cyclic inference error is called out. |
|
608 * |
638 * |
609 * A method check handler (see above) is used in order to report errors. |
639 * A method check handler (see above) is used in order to report errors. |
610 */ |
640 */ |
611 void checkRawArgumentsAcceptable(final Env<AttrContext> env, |
641 void checkRawArgumentsAcceptable(final Env<AttrContext> env, |
642 Symbol msym, |
|
643 DeferredAttr.AttrMode mode, |
|
612 final Infer.InferenceContext inferenceContext, |
644 final Infer.InferenceContext inferenceContext, |
613 List<Type> argtypes, |
645 List<Type> argtypes, |
614 List<Type> formals, |
646 List<Type> formals, |
615 boolean allowBoxing, |
647 boolean allowBoxing, |
616 boolean useVarargs, |
648 boolean useVarargs, |
617 Warner warn, |
649 Warner warn, |
618 MethodCheckHandler handler) { |
650 final MethodCheckHandler handler) { |
619 Type varargsFormal = useVarargs ? formals.last() : null; |
651 Type varargsFormal = useVarargs ? formals.last() : null; |
620 ListBuffer<Type> checkedArgs = ListBuffer.lb(); |
|
621 |
652 |
622 if (varargsFormal == null && |
653 if (varargsFormal == null && |
623 argtypes.size() != formals.size()) { |
654 argtypes.size() != formals.size()) { |
624 throw handler.arityMismatch(); // not enough args |
655 throw handler.arityMismatch(); // not enough args |
625 } |
656 } |
626 |
657 |
658 DeferredAttr.DeferredAttrContext deferredAttrContext = |
|
659 deferredAttr.new DeferredAttrContext(mode, msym, currentResolutionContext.step, inferenceContext); |
|
660 |
|
627 while (argtypes.nonEmpty() && formals.head != varargsFormal) { |
661 while (argtypes.nonEmpty() && formals.head != varargsFormal) { |
628 ResultInfo resultInfo = methodCheckResult(formals.head, allowBoxing, false, inferenceContext, handler, warn); |
662 ResultInfo mresult = methodCheckResult(formals.head, allowBoxing, false, inferenceContext, deferredAttrContext, handler, warn); |
629 checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); |
663 mresult.check(null, argtypes.head); |
630 argtypes = argtypes.tail; |
664 argtypes = argtypes.tail; |
631 formals = formals.tail; |
665 formals = formals.tail; |
632 } |
666 } |
633 |
667 |
634 if (formals.head != varargsFormal) { |
668 if (formals.head != varargsFormal) { |
636 } |
670 } |
637 |
671 |
638 if (useVarargs) { |
672 if (useVarargs) { |
639 //note: if applicability check is triggered by most specific test, |
673 //note: if applicability check is triggered by most specific test, |
640 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) |
674 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) |
641 Type elt = types.elemtype(varargsFormal); |
675 final Type elt = types.elemtype(varargsFormal); |
676 ResultInfo mresult = methodCheckResult(elt, allowBoxing, true, inferenceContext, deferredAttrContext, handler, warn); |
|
642 while (argtypes.nonEmpty()) { |
677 while (argtypes.nonEmpty()) { |
643 ResultInfo resultInfo = methodCheckResult(elt, allowBoxing, true, inferenceContext, handler, warn); |
678 mresult.check(null, argtypes.head); |
644 checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); |
|
645 argtypes = argtypes.tail; |
679 argtypes = argtypes.tail; |
646 } |
680 } |
647 //check varargs element type accessibility |
681 //check varargs element type accessibility |
648 varargsAccessible(env, elt, handler, inferenceContext); |
682 varargsAccessible(env, elt, handler, inferenceContext); |
649 } |
683 } |
684 |
|
685 deferredAttrContext.complete(); |
|
650 } |
686 } |
651 |
687 |
652 void varargsAccessible(final Env<AttrContext> env, final Type t, final Resolve.MethodCheckHandler handler, final InferenceContext inferenceContext) { |
688 void varargsAccessible(final Env<AttrContext> env, final Type t, final Resolve.MethodCheckHandler handler, final InferenceContext inferenceContext) { |
653 if (inferenceContext.free(t)) { |
689 if (inferenceContext.free(t)) { |
654 inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { |
690 inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { |
672 abstract class MethodCheckContext implements CheckContext { |
708 abstract class MethodCheckContext implements CheckContext { |
673 |
709 |
674 MethodCheckHandler handler; |
710 MethodCheckHandler handler; |
675 boolean useVarargs; |
711 boolean useVarargs; |
676 Infer.InferenceContext inferenceContext; |
712 Infer.InferenceContext inferenceContext; |
713 DeferredAttrContext deferredAttrContext; |
|
677 Warner rsWarner; |
714 Warner rsWarner; |
678 |
715 |
679 public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs, Infer.InferenceContext inferenceContext, Warner rsWarner) { |
716 public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs, |
717 Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) { |
|
680 this.handler = handler; |
718 this.handler = handler; |
681 this.useVarargs = useVarargs; |
719 this.useVarargs = useVarargs; |
682 this.inferenceContext = inferenceContext; |
720 this.inferenceContext = inferenceContext; |
721 this.deferredAttrContext = deferredAttrContext; |
|
683 this.rsWarner = rsWarner; |
722 this.rsWarner = rsWarner; |
684 } |
723 } |
685 |
724 |
686 public void report(DiagnosticPosition pos, JCDiagnostic details) { |
725 public void report(DiagnosticPosition pos, JCDiagnostic details) { |
687 throw handler.argumentMismatch(useVarargs, details); |
726 throw handler.argumentMismatch(useVarargs, details); |
691 return rsWarner; |
730 return rsWarner; |
692 } |
731 } |
693 |
732 |
694 public InferenceContext inferenceContext() { |
733 public InferenceContext inferenceContext() { |
695 return inferenceContext; |
734 return inferenceContext; |
735 } |
|
736 |
|
737 public DeferredAttrContext deferredAttrContext() { |
|
738 return deferredAttrContext; |
|
696 } |
739 } |
697 } |
740 } |
698 |
741 |
699 /** |
742 /** |
700 * Subclass of method check context class that implements strict method conversion. |
743 * Subclass of method check context class that implements strict method conversion. |
701 * Strict method conversion checks compatibility between types using subtyping tests. |
744 * Strict method conversion checks compatibility between types using subtyping tests. |
702 */ |
745 */ |
703 class StrictMethodContext extends MethodCheckContext { |
746 class StrictMethodContext extends MethodCheckContext { |
704 |
747 |
705 public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs, Infer.InferenceContext inferenceContext, Warner rsWarner) { |
748 public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs, |
706 super(handler, useVarargs, inferenceContext, rsWarner); |
749 Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) { |
750 super(handler, useVarargs, inferenceContext, deferredAttrContext, rsWarner); |
|
707 } |
751 } |
708 |
752 |
709 public boolean compatible(Type found, Type req, Warner warn) { |
753 public boolean compatible(Type found, Type req, Warner warn) { |
710 return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn); |
754 return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn); |
711 } |
755 } |
715 * Subclass of method check context class that implements loose method conversion. |
759 * Subclass of method check context class that implements loose method conversion. |
716 * Loose method conversion checks compatibility between types using method conversion tests. |
760 * Loose method conversion checks compatibility between types using method conversion tests. |
717 */ |
761 */ |
718 class LooseMethodContext extends MethodCheckContext { |
762 class LooseMethodContext extends MethodCheckContext { |
719 |
763 |
720 public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs, Infer.InferenceContext inferenceContext, Warner rsWarner) { |
764 public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs, |
721 super(handler, useVarargs, inferenceContext, rsWarner); |
765 Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) { |
766 super(handler, useVarargs, inferenceContext, deferredAttrContext, rsWarner); |
|
722 } |
767 } |
723 |
768 |
724 public boolean compatible(Type found, Type req, Warner warn) { |
769 public boolean compatible(Type found, Type req, Warner warn) { |
725 return types.isConvertible(found, inferenceContext.asFree(req, types), warn); |
770 return types.isConvertible(found, inferenceContext.asFree(req, types), warn); |
726 } |
771 } |
728 |
773 |
729 /** |
774 /** |
730 * Create a method check context to be used during method applicability check |
775 * Create a method check context to be used during method applicability check |
731 */ |
776 */ |
732 ResultInfo methodCheckResult(Type to, boolean allowBoxing, boolean useVarargs, |
777 ResultInfo methodCheckResult(Type to, boolean allowBoxing, boolean useVarargs, |
733 Infer.InferenceContext inferenceContext, MethodCheckHandler methodHandler, Warner rsWarner) { |
778 Infer.InferenceContext inferenceContext, DeferredAttr.DeferredAttrContext deferredAttrContext, |
779 MethodCheckHandler methodHandler, Warner rsWarner) { |
|
734 MethodCheckContext checkContext = allowBoxing ? |
780 MethodCheckContext checkContext = allowBoxing ? |
735 new LooseMethodContext(methodHandler, useVarargs, inferenceContext, rsWarner) : |
781 new LooseMethodContext(methodHandler, useVarargs, inferenceContext, deferredAttrContext, rsWarner) : |
736 new StrictMethodContext(methodHandler, useVarargs, inferenceContext, rsWarner); |
782 new StrictMethodContext(methodHandler, useVarargs, inferenceContext, deferredAttrContext, rsWarner); |
737 return attr.new ResultInfo(VAL, to, checkContext) { |
783 return new MethodResultInfo(to, checkContext, deferredAttrContext); |
738 @Override |
784 } |
739 protected Type check(DiagnosticPosition pos, Type found) { |
785 |
786 class MethodResultInfo extends ResultInfo { |
|
787 |
|
788 DeferredAttr.DeferredAttrContext deferredAttrContext; |
|
789 |
|
790 public MethodResultInfo(Type pt, MethodCheckContext checkContext, DeferredAttr.DeferredAttrContext deferredAttrContext) { |
|
791 attr.super(VAL, pt, checkContext); |
|
792 this.deferredAttrContext = deferredAttrContext; |
|
793 } |
|
794 |
|
795 @Override |
|
796 protected Type check(DiagnosticPosition pos, Type found) { |
|
797 if (found.tag == DEFERRED) { |
|
798 DeferredType dt = (DeferredType)found; |
|
799 return dt.check(this); |
|
800 } else { |
|
740 return super.check(pos, chk.checkNonVoid(pos, types.capture(types.upperBound(found.baseType())))); |
801 return super.check(pos, chk.checkNonVoid(pos, types.capture(types.upperBound(found.baseType())))); |
741 } |
802 } |
742 }; |
803 } |
804 |
|
805 @Override |
|
806 protected MethodResultInfo dup(Type newPt) { |
|
807 return new MethodResultInfo(newPt, (MethodCheckContext)checkContext, deferredAttrContext); |
|
808 } |
|
743 } |
809 } |
744 |
810 |
745 public static class InapplicableMethodException extends RuntimeException { |
811 public static class InapplicableMethodException extends RuntimeException { |
746 private static final long serialVersionUID = 0; |
812 private static final long serialVersionUID = 0; |
747 |
813 |
1612 * symbol {@literal (--> flyweight pattern)}. This improves performance since we |
1678 * symbol {@literal (--> flyweight pattern)}. This improves performance since we |
1613 * expect misses to happen frequently. |
1679 * expect misses to happen frequently. |
1614 * |
1680 * |
1615 * @param sym The symbol that was found, or a ResolveError. |
1681 * @param sym The symbol that was found, or a ResolveError. |
1616 * @param pos The position to use for error reporting. |
1682 * @param pos The position to use for error reporting. |
1683 * @param location The symbol the served as a context for this lookup |
|
1617 * @param site The original type from where the selection took place. |
1684 * @param site The original type from where the selection took place. |
1618 * @param name The symbol's name. |
1685 * @param name The symbol's name. |
1686 * @param qualified Did we get here through a qualified expression resolution? |
|
1619 * @param argtypes The invocation's value arguments, |
1687 * @param argtypes The invocation's value arguments, |
1620 * if we looked for a method. |
1688 * if we looked for a method. |
1621 * @param typeargtypes The invocation's type arguments, |
1689 * @param typeargtypes The invocation's type arguments, |
1622 * if we looked for a method. |
1690 * if we looked for a method. |
1623 */ |
1691 * @param logResolveHelper helper class used to log resolve errors |
1624 Symbol access(Symbol sym, |
1692 */ |
1693 Symbol accessInternal(Symbol sym, |
|
1694 DiagnosticPosition pos, |
|
1695 Symbol location, |
|
1696 Type site, |
|
1697 Name name, |
|
1698 boolean qualified, |
|
1699 List<Type> argtypes, |
|
1700 List<Type> typeargtypes, |
|
1701 LogResolveHelper logResolveHelper) { |
|
1702 if (sym.kind >= AMBIGUOUS) { |
|
1703 ResolveError errSym = (ResolveError)sym; |
|
1704 sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); |
|
1705 argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes); |
|
1706 if (logResolveHelper.resolveDiagnosticNeeded(site, argtypes, typeargtypes)) { |
|
1707 logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes); |
|
1708 } |
|
1709 } |
|
1710 return sym; |
|
1711 } |
|
1712 |
|
1713 /** |
|
1714 * Variant of the generalized access routine, to be used for generating method |
|
1715 * resolution diagnostics |
|
1716 */ |
|
1717 Symbol accessMethod(Symbol sym, |
|
1625 DiagnosticPosition pos, |
1718 DiagnosticPosition pos, |
1626 Symbol location, |
1719 Symbol location, |
1627 Type site, |
1720 Type site, |
1628 Name name, |
1721 Name name, |
1629 boolean qualified, |
1722 boolean qualified, |
1630 List<Type> argtypes, |
1723 List<Type> argtypes, |
1631 List<Type> typeargtypes) { |
1724 List<Type> typeargtypes) { |
1632 if (sym.kind >= AMBIGUOUS) { |
1725 return accessInternal(sym, pos, location, site, name, qualified, argtypes, typeargtypes, methodLogResolveHelper); |
1633 ResolveError errSym = (ResolveError)sym; |
1726 } |
1634 if (!site.isErroneous() && |
1727 |
1635 !Type.isErroneous(argtypes) && |
1728 /** Same as original accessMethod(), but without location. |
1636 (typeargtypes==null || !Type.isErroneous(typeargtypes))) |
1729 */ |
1637 logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes); |
1730 Symbol accessMethod(Symbol sym, |
1638 sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); |
|
1639 } |
|
1640 return sym; |
|
1641 } |
|
1642 |
|
1643 /** Same as original access(), but without location. |
|
1644 */ |
|
1645 Symbol access(Symbol sym, |
|
1646 DiagnosticPosition pos, |
1731 DiagnosticPosition pos, |
1647 Type site, |
1732 Type site, |
1648 Name name, |
1733 Name name, |
1649 boolean qualified, |
1734 boolean qualified, |
1650 List<Type> argtypes, |
1735 List<Type> argtypes, |
1651 List<Type> typeargtypes) { |
1736 List<Type> typeargtypes) { |
1652 return access(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes); |
1737 return accessMethod(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes); |
1653 } |
1738 } |
1654 |
1739 |
1655 /** Same as original access(), but without type arguments and arguments. |
1740 /** |
1656 */ |
1741 * Variant of the generalized access routine, to be used for generating variable, |
1657 Symbol access(Symbol sym, |
1742 * type resolution diagnostics |
1743 */ |
|
1744 Symbol accessBase(Symbol sym, |
|
1658 DiagnosticPosition pos, |
1745 DiagnosticPosition pos, |
1659 Symbol location, |
1746 Symbol location, |
1660 Type site, |
1747 Type site, |
1661 Name name, |
1748 Name name, |
1662 boolean qualified) { |
1749 boolean qualified) { |
1663 if (sym.kind >= AMBIGUOUS) |
1750 return accessInternal(sym, pos, location, site, name, qualified, List.<Type>nil(), null, basicLogResolveHelper); |
1664 return access(sym, pos, location, site, name, qualified, List.<Type>nil(), null); |
1751 } |
1665 else |
1752 |
1666 return sym; |
1753 /** Same as original accessBase(), but without location. |
1667 } |
1754 */ |
1668 |
1755 Symbol accessBase(Symbol sym, |
1669 /** Same as original access(), but without location, type arguments and arguments. |
|
1670 */ |
|
1671 Symbol access(Symbol sym, |
|
1672 DiagnosticPosition pos, |
1756 DiagnosticPosition pos, |
1673 Type site, |
1757 Type site, |
1674 Name name, |
1758 Name name, |
1675 boolean qualified) { |
1759 boolean qualified) { |
1676 return access(sym, pos, site.tsym, site, name, qualified); |
1760 return accessBase(sym, pos, site.tsym, site, name, qualified); |
1677 } |
1761 } |
1762 |
|
1763 interface LogResolveHelper { |
|
1764 boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes); |
|
1765 List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes); |
|
1766 } |
|
1767 |
|
1768 LogResolveHelper basicLogResolveHelper = new LogResolveHelper() { |
|
1769 public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) { |
|
1770 return !site.isErroneous(); |
|
1771 } |
|
1772 public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { |
|
1773 return argtypes; |
|
1774 } |
|
1775 }; |
|
1776 |
|
1777 LogResolveHelper methodLogResolveHelper = new LogResolveHelper() { |
|
1778 public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) { |
|
1779 return !site.isErroneous() && |
|
1780 !Type.isErroneous(argtypes) && |
|
1781 (typeargtypes == null || !Type.isErroneous(typeargtypes)); |
|
1782 } |
|
1783 public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { |
|
1784 if (syms.operatorNames.contains(name)) { |
|
1785 return argtypes; |
|
1786 } else { |
|
1787 Symbol msym = errSym.kind == WRONG_MTH ? |
|
1788 ((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym; |
|
1789 |
|
1790 List<Type> argtypes2 = Type.map(argtypes, |
|
1791 deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.firstErroneousResolutionPhase())); |
|
1792 |
|
1793 if (msym != accessedSym) { |
|
1794 //fixup deferred type caches - this 'hack' is required because the symbol |
|
1795 //returned by InapplicableSymbolError.access() will hide the candidate |
|
1796 //method symbol that can be used for lookups in the speculative cache, |
|
1797 //causing problems in Attr.checkId() |
|
1798 for (Type t : argtypes) { |
|
1799 if (t.tag == DEFERRED) { |
|
1800 DeferredType dt = (DeferredType)t; |
|
1801 dt.speculativeCache.dupAllTo(msym, accessedSym); |
|
1802 } |
|
1803 } |
|
1804 } |
|
1805 return argtypes2; |
|
1806 } |
|
1807 } |
|
1808 }; |
|
1678 |
1809 |
1679 /** Check that sym is not an abstract method. |
1810 /** Check that sym is not an abstract method. |
1680 */ |
1811 */ |
1681 void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { |
1812 void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { |
1682 if ((sym.flags() & ABSTRACT) != 0) |
1813 if ((sym.flags() & ABSTRACT) != 0) |
1732 * @param name The identifier's name. |
1863 * @param name The identifier's name. |
1733 * @param kind The set of admissible symbol kinds for the identifier. |
1864 * @param kind The set of admissible symbol kinds for the identifier. |
1734 */ |
1865 */ |
1735 Symbol resolveIdent(DiagnosticPosition pos, Env<AttrContext> env, |
1866 Symbol resolveIdent(DiagnosticPosition pos, Env<AttrContext> env, |
1736 Name name, int kind) { |
1867 Name name, int kind) { |
1737 return access( |
1868 return accessBase( |
1738 findIdent(env, name, kind), |
1869 findIdent(env, name, kind), |
1739 pos, env.enclClass.sym.type, name, false); |
1870 pos, env.enclClass.sym.type, name, false); |
1740 } |
1871 } |
1741 |
1872 |
1742 /** Resolve an unqualified method identifier. |
1873 /** Resolve an unqualified method identifier. |
1757 Symbol sym = methodNotFound; |
1888 Symbol sym = methodNotFound; |
1758 List<MethodResolutionPhase> steps = methodResolutionSteps; |
1889 List<MethodResolutionPhase> steps = methodResolutionSteps; |
1759 while (steps.nonEmpty() && |
1890 while (steps.nonEmpty() && |
1760 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1891 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1761 sym.kind >= ERRONEOUS) { |
1892 sym.kind >= ERRONEOUS) { |
1762 currentResolutionContext.step = steps.head; |
1893 currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; |
1763 sym = findFun(env, name, argtypes, typeargtypes, |
1894 sym = findFun(env, name, argtypes, typeargtypes, |
1764 steps.head.isBoxingRequired, |
1895 steps.head.isBoxingRequired, |
1765 env.info.varArgs = steps.head.isVarargsRequired); |
1896 steps.head.isVarargsRequired); |
1766 currentResolutionContext.resolutionCache.put(steps.head, sym); |
1897 currentResolutionContext.resolutionCache.put(steps.head, sym); |
1767 steps = steps.tail; |
1898 steps = steps.tail; |
1768 } |
1899 } |
1769 if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error |
1900 if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error |
1770 MethodResolutionPhase errPhase = |
1901 MethodResolutionPhase errPhase = |
1771 currentResolutionContext.firstErroneousResolutionPhase(); |
1902 currentResolutionContext.firstErroneousResolutionPhase(); |
1772 sym = access(currentResolutionContext.resolutionCache.get(errPhase), |
1903 sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase), |
1773 pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes); |
1904 pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes); |
1774 env.info.varArgs = errPhase.isVarargsRequired; |
1905 env.info.pendingResolutionPhase = errPhase; |
1775 } |
1906 } |
1776 return sym; |
1907 return sym; |
1777 } |
1908 } |
1778 finally { |
1909 finally { |
1779 currentResolutionContext = prevResolutionContext; |
1910 currentResolutionContext = prevResolutionContext; |
1809 Symbol sym = methodNotFound; |
1940 Symbol sym = methodNotFound; |
1810 List<MethodResolutionPhase> steps = methodResolutionSteps; |
1941 List<MethodResolutionPhase> steps = methodResolutionSteps; |
1811 while (steps.nonEmpty() && |
1942 while (steps.nonEmpty() && |
1812 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1943 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1813 sym.kind >= ERRONEOUS) { |
1944 sym.kind >= ERRONEOUS) { |
1814 currentResolutionContext.step = steps.head; |
1945 currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; |
1815 sym = findMethod(env, site, name, argtypes, typeargtypes, |
1946 sym = findMethod(env, site, name, argtypes, typeargtypes, |
1816 steps.head.isBoxingRequired(), |
1947 steps.head.isBoxingRequired(), |
1817 env.info.varArgs = steps.head.isVarargsRequired(), false); |
1948 steps.head.isVarargsRequired(), false); |
1818 currentResolutionContext.resolutionCache.put(steps.head, sym); |
1949 currentResolutionContext.resolutionCache.put(steps.head, sym); |
1819 steps = steps.tail; |
1950 steps = steps.tail; |
1820 } |
1951 } |
1821 if (sym.kind >= AMBIGUOUS) { |
1952 if (sym.kind >= AMBIGUOUS) { |
1822 //if nothing is found return the 'first' error |
1953 //if nothing is found return the 'first' error |
1823 MethodResolutionPhase errPhase = |
1954 MethodResolutionPhase errPhase = |
1824 currentResolutionContext.firstErroneousResolutionPhase(); |
1955 currentResolutionContext.firstErroneousResolutionPhase(); |
1825 sym = access(currentResolutionContext.resolutionCache.get(errPhase), |
1956 sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase), |
1826 pos, location, site, name, true, argtypes, typeargtypes); |
1957 pos, location, site, name, true, argtypes, typeargtypes); |
1827 env.info.varArgs = errPhase.isVarargsRequired; |
1958 env.info.pendingResolutionPhase = errPhase; |
1828 } else if (allowMethodHandles) { |
1959 } else if (allowMethodHandles) { |
1829 MethodSymbol msym = (MethodSymbol)sym; |
1960 MethodSymbol msym = (MethodSymbol)sym; |
1830 if (msym.isSignaturePolymorphic(types)) { |
1961 if (msym.isSignaturePolymorphic(types)) { |
1831 env.info.varArgs = false; |
1962 env.info.pendingResolutionPhase = BASIC; |
1832 return findPolymorphicSignatureInstance(env, sym, argtypes); |
1963 return findPolymorphicSignatureInstance(env, sym, argtypes); |
1833 } |
1964 } |
1834 } |
1965 } |
1835 return sym; |
1966 return sym; |
1836 } |
1967 } |
1848 */ |
1979 */ |
1849 Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, |
1980 Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, |
1850 Symbol spMethod, |
1981 Symbol spMethod, |
1851 List<Type> argtypes) { |
1982 List<Type> argtypes) { |
1852 Type mtype = infer.instantiatePolymorphicSignatureInstance(env, |
1983 Type mtype = infer.instantiatePolymorphicSignatureInstance(env, |
1853 (MethodSymbol)spMethod, argtypes); |
1984 (MethodSymbol)spMethod, currentResolutionContext, argtypes); |
1854 for (Symbol sym : polymorphicSignatureScope.getElementsByName(spMethod.name)) { |
1985 for (Symbol sym : polymorphicSignatureScope.getElementsByName(spMethod.name)) { |
1855 if (types.isSameType(mtype, sym.type)) { |
1986 if (types.isSameType(mtype, sym.type)) { |
1856 return sym; |
1987 return sym; |
1857 } |
1988 } |
1858 } |
1989 } |
1916 Symbol sym = methodNotFound; |
2047 Symbol sym = methodNotFound; |
1917 List<MethodResolutionPhase> steps = methodResolutionSteps; |
2048 List<MethodResolutionPhase> steps = methodResolutionSteps; |
1918 while (steps.nonEmpty() && |
2049 while (steps.nonEmpty() && |
1919 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
2050 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1920 sym.kind >= ERRONEOUS) { |
2051 sym.kind >= ERRONEOUS) { |
1921 currentResolutionContext.step = steps.head; |
2052 currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; |
1922 sym = findConstructor(pos, env, site, argtypes, typeargtypes, |
2053 sym = findConstructor(pos, env, site, argtypes, typeargtypes, |
1923 steps.head.isBoxingRequired(), |
2054 steps.head.isBoxingRequired(), |
1924 env.info.varArgs = steps.head.isVarargsRequired()); |
2055 steps.head.isVarargsRequired()); |
1925 currentResolutionContext.resolutionCache.put(steps.head, sym); |
2056 currentResolutionContext.resolutionCache.put(steps.head, sym); |
1926 steps = steps.tail; |
2057 steps = steps.tail; |
1927 } |
2058 } |
1928 if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error |
2059 if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error |
1929 MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); |
2060 MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); |
1930 sym = access(currentResolutionContext.resolutionCache.get(errPhase), |
2061 sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase), |
1931 pos, site, names.init, true, argtypes, typeargtypes); |
2062 pos, site, names.init, true, argtypes, typeargtypes); |
1932 env.info.varArgs = errPhase.isVarargsRequired(); |
2063 env.info.pendingResolutionPhase = errPhase; |
1933 } |
2064 } |
1934 return sym; |
2065 return sym; |
1935 } |
2066 } |
1936 finally { |
2067 finally { |
1937 currentResolutionContext = prevResolutionContext; |
2068 currentResolutionContext = prevResolutionContext; |
1959 Symbol sym = methodNotFound; |
2090 Symbol sym = methodNotFound; |
1960 List<MethodResolutionPhase> steps = methodResolutionSteps; |
2091 List<MethodResolutionPhase> steps = methodResolutionSteps; |
1961 while (steps.nonEmpty() && |
2092 while (steps.nonEmpty() && |
1962 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
2093 steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1963 sym.kind >= ERRONEOUS) { |
2094 sym.kind >= ERRONEOUS) { |
1964 currentResolutionContext.step = steps.head; |
2095 currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; |
1965 sym = findDiamond(env, site, argtypes, typeargtypes, |
2096 sym = findDiamond(env, site, argtypes, typeargtypes, |
1966 steps.head.isBoxingRequired(), |
2097 steps.head.isBoxingRequired(), |
1967 env.info.varArgs = steps.head.isVarargsRequired()); |
2098 steps.head.isVarargsRequired()); |
1968 currentResolutionContext.resolutionCache.put(steps.head, sym); |
2099 currentResolutionContext.resolutionCache.put(steps.head, sym); |
1969 steps = steps.tail; |
2100 steps = steps.tail; |
1970 } |
2101 } |
1971 if (sym.kind >= AMBIGUOUS) { |
2102 if (sym.kind >= AMBIGUOUS) { |
1972 Symbol errSym = |
2103 Symbol errSym = |
1984 return diags.create(dkind, log.currentSource(), pos, key, |
2115 return diags.create(dkind, log.currentSource(), pos, key, |
1985 diags.fragment("diamond", site.tsym), details); |
2116 diags.fragment("diamond", site.tsym), details); |
1986 } |
2117 } |
1987 }; |
2118 }; |
1988 MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); |
2119 MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); |
1989 sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes); |
2120 sym = accessMethod(errSym, pos, site, names.init, true, argtypes, typeargtypes); |
1990 env.info.varArgs = errPhase.isVarargsRequired(); |
2121 env.info.pendingResolutionPhase = errPhase; |
1991 } |
2122 } |
1992 return sym; |
2123 return sym; |
1993 } |
2124 } |
1994 finally { |
2125 finally { |
1995 currentResolutionContext = prevResolutionContext; |
2126 currentResolutionContext = prevResolutionContext; |
2113 Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes, |
2244 Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes, |
2114 null, false, false, true); |
2245 null, false, false, true); |
2115 if (boxingEnabled && sym.kind >= WRONG_MTHS) |
2246 if (boxingEnabled && sym.kind >= WRONG_MTHS) |
2116 sym = findMethod(env, syms.predefClass.type, name, argtypes, |
2247 sym = findMethod(env, syms.predefClass.type, name, argtypes, |
2117 null, true, false, true); |
2248 null, true, false, true); |
2118 return access(sym, pos, env.enclClass.sym.type, name, |
2249 return accessMethod(sym, pos, env.enclClass.sym.type, name, |
2119 false, argtypes, null); |
2250 false, argtypes, null); |
2120 } |
2251 } |
2121 finally { |
2252 finally { |
2122 currentResolutionContext = prevResolutionContext; |
2253 currentResolutionContext = prevResolutionContext; |
2123 } |
2254 } |
2165 if (isStatic(env1)) staticOnly = true; |
2296 if (isStatic(env1)) staticOnly = true; |
2166 if (env1.enclClass.sym == c) { |
2297 if (env1.enclClass.sym == c) { |
2167 Symbol sym = env1.info.scope.lookup(name).sym; |
2298 Symbol sym = env1.info.scope.lookup(name).sym; |
2168 if (sym != null) { |
2299 if (sym != null) { |
2169 if (staticOnly) sym = new StaticError(sym); |
2300 if (staticOnly) sym = new StaticError(sym); |
2170 return access(sym, pos, env.enclClass.sym.type, |
2301 return accessBase(sym, pos, env.enclClass.sym.type, |
2171 name, true); |
2302 name, true); |
2172 } |
2303 } |
2173 } |
2304 } |
2174 if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
2305 if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
2175 env1 = env1.outer; |
2306 env1 = env1.outer; |
2197 if (isStatic(env1)) staticOnly = true; |
2328 if (isStatic(env1)) staticOnly = true; |
2198 if (env1.enclClass.sym.isSubClass(member.owner, types)) { |
2329 if (env1.enclClass.sym.isSubClass(member.owner, types)) { |
2199 Symbol sym = env1.info.scope.lookup(name).sym; |
2330 Symbol sym = env1.info.scope.lookup(name).sym; |
2200 if (sym != null) { |
2331 if (sym != null) { |
2201 if (staticOnly) sym = new StaticError(sym); |
2332 if (staticOnly) sym = new StaticError(sym); |
2202 return access(sym, pos, env.enclClass.sym.type, |
2333 return accessBase(sym, pos, env.enclClass.sym.type, |
2203 name, true); |
2334 name, true); |
2204 } |
2335 } |
2205 } |
2336 } |
2206 if ((env1.enclClass.sym.flags() & STATIC) != 0) |
2337 if ((env1.enclClass.sym.flags() & STATIC) != 0) |
2207 staticOnly = true; |
2338 staticOnly = true; |
2320 Symbol location, |
2451 Symbol location, |
2321 Type site, |
2452 Type site, |
2322 Name name, |
2453 Name name, |
2323 List<Type> argtypes, |
2454 List<Type> argtypes, |
2324 List<Type> typeargtypes); |
2455 List<Type> typeargtypes); |
2325 |
|
2326 /** |
|
2327 * A name designates an operator if it consists |
|
2328 * of a non-empty sequence of operator symbols {@literal +-~!/*%&|^<>= } |
|
2329 */ |
|
2330 boolean isOperator(Name name) { |
|
2331 int i = 0; |
|
2332 while (i < name.getByteLength() && |
|
2333 "+-~!*/%&|^<>=".indexOf(name.getByteAt(i)) >= 0) i++; |
|
2334 return i > 0 && i == name.getByteLength(); |
|
2335 } |
|
2336 } |
2456 } |
2337 |
2457 |
2338 /** |
2458 /** |
2339 * This class is the root class of all resolution errors caused by |
2459 * This class is the root class of all resolution errors caused by |
2340 * an invalid symbol being found during resolution. |
2460 * an invalid symbol being found during resolution. |
2391 argtypes = argtypes == null ? List.<Type>nil() : argtypes; |
2511 argtypes = argtypes == null ? List.<Type>nil() : argtypes; |
2392 typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes; |
2512 typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes; |
2393 if (name == names.error) |
2513 if (name == names.error) |
2394 return null; |
2514 return null; |
2395 |
2515 |
2396 if (isOperator(name)) { |
2516 if (syms.operatorNames.contains(name)) { |
2397 boolean isUnaryOp = argtypes.size() == 1; |
2517 boolean isUnaryOp = argtypes.size() == 1; |
2398 String key = argtypes.size() == 1 ? |
2518 String key = argtypes.size() == 1 ? |
2399 "operator.cant.be.applied" : |
2519 "operator.cant.be.applied" : |
2400 "operator.cant.be.applied.1"; |
2520 "operator.cant.be.applied.1"; |
2401 Type first = argtypes.head; |
2521 Type first = argtypes.head; |
2413 "doesnt.exist", location); |
2533 "doesnt.exist", location); |
2414 } |
2534 } |
2415 hasLocation = !location.name.equals(names._this) && |
2535 hasLocation = !location.name.equals(names._this) && |
2416 !location.name.equals(names._super); |
2536 !location.name.equals(names._super); |
2417 } |
2537 } |
2418 boolean isConstructor = kind == ABSENT_MTH && |
2538 boolean isConstructor = kind == ABSENT_MTH && name == names.init; |
2419 name == names.table.names.init; |
|
2420 KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind); |
2539 KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind); |
2421 Name idname = isConstructor ? site.tsym.name : name; |
2540 Name idname = isConstructor ? site.tsym.name : name; |
2422 String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation); |
2541 String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation); |
2423 if (hasLocation) { |
2542 if (hasLocation) { |
2424 return diags.create(dkind, log.currentSource(), pos, |
2543 return diags.create(dkind, log.currentSource(), pos, |
2494 List<Type> argtypes, |
2613 List<Type> argtypes, |
2495 List<Type> typeargtypes) { |
2614 List<Type> typeargtypes) { |
2496 if (name == names.error) |
2615 if (name == names.error) |
2497 return null; |
2616 return null; |
2498 |
2617 |
2499 if (isOperator(name)) { |
2618 if (syms.operatorNames.contains(name)) { |
2500 boolean isUnaryOp = argtypes.size() == 1; |
2619 boolean isUnaryOp = argtypes.size() == 1; |
2501 String key = argtypes.size() == 1 ? |
2620 String key = argtypes.size() == 1 ? |
2502 "operator.cant.be.applied" : |
2621 "operator.cant.be.applied" : |
2503 "operator.cant.be.applied.1"; |
2622 "operator.cant.be.applied.1"; |
2504 Type first = argtypes.head; |
2623 Type first = argtypes.head; |
2772 private List<Candidate> candidates = List.nil(); |
2891 private List<Candidate> candidates = List.nil(); |
2773 |
2892 |
2774 private Map<MethodResolutionPhase, Symbol> resolutionCache = |
2893 private Map<MethodResolutionPhase, Symbol> resolutionCache = |
2775 new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class); |
2894 new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class); |
2776 |
2895 |
2777 private MethodResolutionPhase step = null; |
2896 MethodResolutionPhase step = null; |
2778 |
2897 |
2779 private boolean internalResolution = false; |
2898 private boolean internalResolution = false; |
2899 private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE; |
|
2780 |
2900 |
2781 private MethodResolutionPhase firstErroneousResolutionPhase() { |
2901 private MethodResolutionPhase firstErroneousResolutionPhase() { |
2782 MethodResolutionPhase bestSoFar = BASIC; |
2902 MethodResolutionPhase bestSoFar = BASIC; |
2783 Symbol sym = methodNotFound; |
2903 Symbol sym = methodNotFound; |
2784 List<MethodResolutionPhase> steps = methodResolutionSteps; |
2904 List<MethodResolutionPhase> steps = methodResolutionSteps; |
2840 |
2960 |
2841 boolean isApplicable() { |
2961 boolean isApplicable() { |
2842 return mtype != null; |
2962 return mtype != null; |
2843 } |
2963 } |
2844 } |
2964 } |
2965 |
|
2966 DeferredAttr.AttrMode attrMode() { |
|
2967 return attrMode; |
|
2968 } |
|
2969 |
|
2970 boolean internal() { |
|
2971 return internalResolution; |
|
2972 } |
|
2845 } |
2973 } |
2846 |
2974 |
2847 MethodResolutionContext currentResolutionContext = null; |
2975 MethodResolutionContext currentResolutionContext = null; |
2848 } |
2976 } |