< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java

Print this page




2625 
2626     /** Resolve a qualified method identifier
2627      *  @param pos       The position to use for error reporting.
2628      *  @param env       The environment current at the method invocation.
2629      *  @param site      The type of the qualifying expression, in which
2630      *                   identifier is searched.
2631      *  @param name      The identifier's name.
2632      *  @param argtypes  The types of the invocation's value arguments.
2633      *  @param typeargtypes  The types of the invocation's type arguments.
2634      */
2635     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2636                                   Type site, Name name, List<Type> argtypes,
2637                                   List<Type> typeargtypes) {
2638         return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes);
2639     }
2640     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2641                                   Symbol location, Type site, Name name, List<Type> argtypes,
2642                                   List<Type> typeargtypes) {
2643         return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
2644     }
2645     private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
2646                                   DiagnosticPosition pos, Env<AttrContext> env,
2647                                   Symbol location, Type site, Name name, List<Type> argtypes,
2648                                   List<Type> typeargtypes) {
2649         return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
2650             @Override
2651             Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2652                 return findMethod(env, site, name, argtypes, typeargtypes,
2653                         phase.isBoxingRequired(),
2654                         phase.isVarargsRequired());
2655             }
2656             @Override
2657             Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2658                 if (sym.kind.isResolutionError()) {
2659                     sym = super.access(env, pos, location, sym);
2660                 } else {
2661                     MethodSymbol msym = (MethodSymbol)sym;
2662                     if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
2663                         env.info.pendingResolutionPhase = BASIC;
2664                         return findPolymorphicSignatureInstance(env, sym, argtypes);
2665                     }
2666                 }
2667                 return sym;
2668             }
2669         });
2670     }
2671 
2672     /** Find or create an implicit method of exactly the given type (after erasure).
2673      *  Searches in a side table, not the main scope of the site.
2674      *  This emulates the lookup process required by JSR 292 in JVM.
2675      *  @param env       Attribution environment
2676      *  @param spMethod  signature polymorphic method - i.e. MH.invokeExact
2677      *  @param argtypes  The required argument types
2678      */
2679     Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,


4752         }
4753 
4754         public boolean isVarargsRequired() {
4755             return isVarargsRequired;
4756         }
4757 
4758         public Symbol mergeResults(Symbol prev, Symbol sym) {
4759             return sym;
4760         }
4761     }
4762 
4763     final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
4764 
4765     /**
4766      * A resolution context is used to keep track of intermediate results of
4767      * overload resolution, such as list of method that are not applicable
4768      * (used to generate more precise diagnostics) and so on. Resolution contexts
4769      * can be nested - this means that when each overload resolution routine should
4770      * work within the resolution context it created.
4771      */
4772     class MethodResolutionContext {
4773 
4774         private List<Candidate> candidates = List.nil();
4775 
4776         MethodResolutionPhase step = null;
4777 
4778         MethodCheck methodCheck = resolveMethodCheck;
4779 
4780         private boolean internalResolution = false;


4781         private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
4782 
4783         void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
4784             Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
4785             candidates = candidates.append(c);
4786         }
4787 
4788         void addApplicableCandidate(Symbol sym, Type mtype) {
4789             Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype);
4790             candidates = candidates.append(c);
4791         }
4792 
4793         DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) {
4794             DeferredAttrContext parent = (pendingResult == null)
4795                 ? deferredAttr.emptyDeferredAttrContext
4796                 : pendingResult.checkContext.deferredAttrContext();
4797             return deferredAttr.new DeferredAttrContext(attrMode, sym, step,
4798                     inferenceContext, parent, warn);
4799         }
4800 




2625 
2626     /** Resolve a qualified method identifier
2627      *  @param pos       The position to use for error reporting.
2628      *  @param env       The environment current at the method invocation.
2629      *  @param site      The type of the qualifying expression, in which
2630      *                   identifier is searched.
2631      *  @param name      The identifier's name.
2632      *  @param argtypes  The types of the invocation's value arguments.
2633      *  @param typeargtypes  The types of the invocation's type arguments.
2634      */
2635     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2636                                   Type site, Name name, List<Type> argtypes,
2637                                   List<Type> typeargtypes) {
2638         return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes);
2639     }
2640     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2641                                   Symbol location, Type site, Name name, List<Type> argtypes,
2642                                   List<Type> typeargtypes) {
2643         return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
2644     }
2645     public Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
2646                                   DiagnosticPosition pos, Env<AttrContext> env,
2647                                   Symbol location, Type site, Name name, List<Type> argtypes,
2648                                   List<Type> typeargtypes) {
2649         return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
2650             @Override
2651             Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2652                 return findMethod(env, site, name, argtypes, typeargtypes,
2653                         phase.isBoxingRequired(),
2654                         phase.isVarargsRequired());
2655             }
2656             @Override
2657             Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2658                 if (sym.kind.isResolutionError()) {
2659                     sym = resolveContext.silentFail ? sym : super.access(env, pos, location, sym);
2660                 } else {
2661                     MethodSymbol msym = (MethodSymbol)sym;
2662                     if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
2663                         env.info.pendingResolutionPhase = BASIC;
2664                         return findPolymorphicSignatureInstance(env, sym, argtypes);
2665                     }
2666                 }
2667                 return sym;
2668             }
2669         });
2670     }
2671 
2672     /** Find or create an implicit method of exactly the given type (after erasure).
2673      *  Searches in a side table, not the main scope of the site.
2674      *  This emulates the lookup process required by JSR 292 in JVM.
2675      *  @param env       Attribution environment
2676      *  @param spMethod  signature polymorphic method - i.e. MH.invokeExact
2677      *  @param argtypes  The required argument types
2678      */
2679     Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,


4752         }
4753 
4754         public boolean isVarargsRequired() {
4755             return isVarargsRequired;
4756         }
4757 
4758         public Symbol mergeResults(Symbol prev, Symbol sym) {
4759             return sym;
4760         }
4761     }
4762 
4763     final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
4764 
4765     /**
4766      * A resolution context is used to keep track of intermediate results of
4767      * overload resolution, such as list of method that are not applicable
4768      * (used to generate more precise diagnostics) and so on. Resolution contexts
4769      * can be nested - this means that when each overload resolution routine should
4770      * work within the resolution context it created.
4771      */
4772     public class MethodResolutionContext {
4773 
4774         private List<Candidate> candidates = List.nil();
4775 
4776         MethodResolutionPhase step = null;
4777 
4778         MethodCheck methodCheck = resolveMethodCheck;
4779 
4780         public boolean internalResolution = false;
4781         // in case of failure, don't report the error
4782         public boolean silentFail = false;
4783         private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
4784 
4785         void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
4786             Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
4787             candidates = candidates.append(c);
4788         }
4789 
4790         void addApplicableCandidate(Symbol sym, Type mtype) {
4791             Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype);
4792             candidates = candidates.append(c);
4793         }
4794 
4795         DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) {
4796             DeferredAttrContext parent = (pendingResult == null)
4797                 ? deferredAttr.emptyDeferredAttrContext
4798                 : pendingResult.checkContext.deferredAttrContext();
4799             return deferredAttr.new DeferredAttrContext(attrMode, sym, step,
4800                     inferenceContext, parent, warn);
4801         }
4802 


< prev index next >