< prev index next >

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

Print this page




1911                     return null;
1912                 }
1913                 seen = seen.prepend(t.tsym);
1914                 return t.tsym;
1915             }
1916         };
1917     }
1918 
1919     /** Find unqualified method matching given name, type and value arguments.
1920      *  @param env       The current environment.
1921      *  @param name      The method's name.
1922      *  @param argtypes  The method's value arguments.
1923      *  @param typeargtypes  The method's type arguments.
1924      *  @param allowBoxing Allow boxing conversions of arguments.
1925      *  @param useVarargs Box trailing arguments into an array for varargs.
1926      */
1927     Symbol findFun(Env<AttrContext> env, Name name,
1928                    List<Type> argtypes, List<Type> typeargtypes,
1929                    boolean allowBoxing, boolean useVarargs) {
1930         Symbol bestSoFar = methodNotFound;

1931         Env<AttrContext> env1 = env;
1932         boolean staticOnly = false;
1933         while (env1.outer != null) {
1934             if (isStatic(env1)) staticOnly = true;
1935             Assert.check(env1.info.preferredTreeForDiagnostics == null);
1936             env1.info.preferredTreeForDiagnostics = env.tree;
1937             try {
1938                 Symbol sym = findMethod(
1939                     env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
1940                     allowBoxing, useVarargs);
1941                 if (sym.exists()) {
1942                     if (staticOnly &&
1943                         sym.kind == MTH &&
1944                         sym.owner.kind == TYP &&
1945                         (sym.flags() & STATIC) == 0) return new StaticError(sym);
1946                     else return sym;
1947                 } else {
1948                     bestSoFar = bestOf(bestSoFar, sym);
1949                 }
1950             } finally {


2647 
2648     /** Resolve a qualified method identifier
2649      *  @param pos       The position to use for error reporting.
2650      *  @param env       The environment current at the method invocation.
2651      *  @param site      The type of the qualifying expression, in which
2652      *                   identifier is searched.
2653      *  @param name      The identifier's name.
2654      *  @param argtypes  The types of the invocation's value arguments.
2655      *  @param typeargtypes  The types of the invocation's type arguments.
2656      */
2657     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2658                                   Type site, Name name, List<Type> argtypes,
2659                                   List<Type> typeargtypes) {
2660         return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes);
2661     }
2662     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2663                                   Symbol location, Type site, Name name, List<Type> argtypes,
2664                                   List<Type> typeargtypes) {
2665         return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
2666     }
2667     private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
2668                                   DiagnosticPosition pos, Env<AttrContext> env,
2669                                   Symbol location, Type site, Name name, List<Type> argtypes,
2670                                   List<Type> typeargtypes) {
2671         return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
2672             @Override
2673             Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2674                 return findMethod(env, site, name, argtypes, typeargtypes,
2675                         phase.isBoxingRequired(),
2676                         phase.isVarargsRequired());
2677             }
2678             @Override
2679             Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2680                 if (sym.kind.isResolutionError()) {
2681                     sym = super.access(env, pos, location, sym);
2682                 } else {
2683                     MethodSymbol msym = (MethodSymbol)sym;
2684                     if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
2685                         env.info.pendingResolutionPhase = BASIC;
2686                         return findPolymorphicSignatureInstance(env, sym, argtypes);
2687                     }
2688                 }
2689                 return sym;
2690             }
2691         });
2692     }
2693 
2694     /** Find or create an implicit method of exactly the given type (after erasure).
2695      *  Searches in a side table, not the main scope of the site.
2696      *  This emulates the lookup process required by JSR 292 in JVM.
2697      *  @param env       Attribution environment
2698      *  @param spMethod  signature polymorphic method - i.e. MH.invokeExact
2699      *  @param argtypes  The required argument types
2700      */
2701     Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,


4776         }
4777 
4778         public boolean isVarargsRequired() {
4779             return isVarargsRequired;
4780         }
4781 
4782         public Symbol mergeResults(Symbol prev, Symbol sym) {
4783             return sym;
4784         }
4785     }
4786 
4787     final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
4788 
4789     /**
4790      * A resolution context is used to keep track of intermediate results of
4791      * overload resolution, such as list of method that are not applicable
4792      * (used to generate more precise diagnostics) and so on. Resolution contexts
4793      * can be nested - this means that when each overload resolution routine should
4794      * work within the resolution context it created.
4795      */
4796     class MethodResolutionContext {
4797 
4798         private List<Candidate> candidates = List.nil();
4799 
4800         MethodResolutionPhase step = null;
4801 
4802         MethodCheck methodCheck = resolveMethodCheck;
4803 
4804         private boolean internalResolution = false;


4805         private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
4806 
4807         void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
4808             Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
4809             candidates = candidates.append(c);
4810         }
4811 
4812         void addApplicableCandidate(Symbol sym, Type mtype) {
4813             Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype);
4814             candidates = candidates.append(c);
4815         }
4816 
4817         DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) {
4818             DeferredAttrContext parent = (pendingResult == null)
4819                 ? deferredAttr.emptyDeferredAttrContext
4820                 : pendingResult.checkContext.deferredAttrContext();
4821             return deferredAttr.new DeferredAttrContext(attrMode, sym, step,
4822                     inferenceContext, parent, warn);
4823         }
4824 




1911                     return null;
1912                 }
1913                 seen = seen.prepend(t.tsym);
1914                 return t.tsym;
1915             }
1916         };
1917     }
1918 
1919     /** Find unqualified method matching given name, type and value arguments.
1920      *  @param env       The current environment.
1921      *  @param name      The method's name.
1922      *  @param argtypes  The method's value arguments.
1923      *  @param typeargtypes  The method's type arguments.
1924      *  @param allowBoxing Allow boxing conversions of arguments.
1925      *  @param useVarargs Box trailing arguments into an array for varargs.
1926      */
1927     Symbol findFun(Env<AttrContext> env, Name name,
1928                    List<Type> argtypes, List<Type> typeargtypes,
1929                    boolean allowBoxing, boolean useVarargs) {
1930         Symbol bestSoFar = methodNotFound;
1931 
1932         Env<AttrContext> env1 = env;
1933         boolean staticOnly = false;
1934         while (env1.outer != null) {
1935             if (isStatic(env1)) staticOnly = true;
1936             Assert.check(env1.info.preferredTreeForDiagnostics == null);
1937             env1.info.preferredTreeForDiagnostics = env.tree;
1938             try {
1939                 Symbol sym = findMethod(
1940                     env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
1941                     allowBoxing, useVarargs);
1942                 if (sym.exists()) {
1943                     if (staticOnly &&
1944                         sym.kind == MTH &&
1945                         sym.owner.kind == TYP &&
1946                         (sym.flags() & STATIC) == 0) return new StaticError(sym);
1947                     else return sym;
1948                 } else {
1949                     bestSoFar = bestOf(bestSoFar, sym);
1950                 }
1951             } finally {


2648 
2649     /** Resolve a qualified method identifier
2650      *  @param pos       The position to use for error reporting.
2651      *  @param env       The environment current at the method invocation.
2652      *  @param site      The type of the qualifying expression, in which
2653      *                   identifier is searched.
2654      *  @param name      The identifier's name.
2655      *  @param argtypes  The types of the invocation's value arguments.
2656      *  @param typeargtypes  The types of the invocation's type arguments.
2657      */
2658     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2659                                   Type site, Name name, List<Type> argtypes,
2660                                   List<Type> typeargtypes) {
2661         return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes);
2662     }
2663     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2664                                   Symbol location, Type site, Name name, List<Type> argtypes,
2665                                   List<Type> typeargtypes) {
2666         return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
2667     }
2668     public Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
2669                                   DiagnosticPosition pos, Env<AttrContext> env,
2670                                   Symbol location, Type site, Name name, List<Type> argtypes,
2671                                   List<Type> typeargtypes) {
2672         return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
2673             @Override
2674             Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2675                 return findMethod(env, site, name, argtypes, typeargtypes,
2676                         phase.isBoxingRequired(),
2677                         phase.isVarargsRequired());
2678             }
2679             @Override
2680             Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2681                 if (sym.kind.isResolutionError()) {
2682                     sym = resolveContext.silentFail ? sym : super.access(env, pos, location, sym);
2683                 } else {
2684                     MethodSymbol msym = (MethodSymbol)sym;
2685                     if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
2686                         env.info.pendingResolutionPhase = BASIC;
2687                         return findPolymorphicSignatureInstance(env, sym, argtypes);
2688                     }
2689                 }
2690                 return sym;
2691             }
2692         });
2693     }
2694 
2695     /** Find or create an implicit method of exactly the given type (after erasure).
2696      *  Searches in a side table, not the main scope of the site.
2697      *  This emulates the lookup process required by JSR 292 in JVM.
2698      *  @param env       Attribution environment
2699      *  @param spMethod  signature polymorphic method - i.e. MH.invokeExact
2700      *  @param argtypes  The required argument types
2701      */
2702     Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,


4777         }
4778 
4779         public boolean isVarargsRequired() {
4780             return isVarargsRequired;
4781         }
4782 
4783         public Symbol mergeResults(Symbol prev, Symbol sym) {
4784             return sym;
4785         }
4786     }
4787 
4788     final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
4789 
4790     /**
4791      * A resolution context is used to keep track of intermediate results of
4792      * overload resolution, such as list of method that are not applicable
4793      * (used to generate more precise diagnostics) and so on. Resolution contexts
4794      * can be nested - this means that when each overload resolution routine should
4795      * work within the resolution context it created.
4796      */
4797     public class MethodResolutionContext {
4798 
4799         private List<Candidate> candidates = List.nil();
4800 
4801         MethodResolutionPhase step = null;
4802 
4803         MethodCheck methodCheck = resolveMethodCheck;
4804 
4805         public boolean internalResolution = false;
4806         // in case of failure, don't report the error
4807         public boolean silentFail = false;
4808         private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
4809 
4810         void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
4811             Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
4812             candidates = candidates.append(c);
4813         }
4814 
4815         void addApplicableCandidate(Symbol sym, Type mtype) {
4816             Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype);
4817             candidates = candidates.append(c);
4818         }
4819 
4820         DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) {
4821             DeferredAttrContext parent = (pendingResult == null)
4822                 ? deferredAttr.emptyDeferredAttrContext
4823                 : pendingResult.checkContext.deferredAttrContext();
4824             return deferredAttr.new DeferredAttrContext(attrMode, sym, step,
4825                     inferenceContext, parent, warn);
4826         }
4827 


< prev index next >