< prev index next >

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

Print this page




  83  *
  84  *  <p><b>This is NOT part of any supported API.
  85  *  If you write code that depends on this, you do so at your own risk.
  86  *  This code and its internal interfaces are subject to change or
  87  *  deletion without notice.</b>
  88  */
  89 public class Resolve {
  90     protected static final Context.Key<Resolve> resolveKey = new Context.Key<>();
  91 
  92     Names names;
  93     Log log;
  94     Symtab syms;
  95     Attr attr;
  96     DeferredAttr deferredAttr;
  97     Check chk;
  98     Infer infer;
  99     ClassFinder finder;
 100     ModuleFinder moduleFinder;
 101     Types types;
 102     JCDiagnostic.Factory diags;
 103     public final boolean allowMethodHandles;
 104     public final boolean allowFunctionalInterfaceMostSpecific;
 105     public final boolean allowModules;
 106     public final boolean checkVarargsAccessAfterResolution;
 107     private final boolean compactMethodDiags;
 108     private final boolean allowLocalVariableTypeInference;
 109     final EnumSet<VerboseResolutionMode> verboseResolutionMode;
 110 
 111     WriteableScope polymorphicSignatureScope;
 112 
 113     protected Resolve(Context context) {
 114         context.put(resolveKey, this);
 115         syms = Symtab.instance(context);
 116 
 117         varNotFound = new SymbolNotFoundError(ABSENT_VAR);
 118         methodNotFound = new SymbolNotFoundError(ABSENT_MTH);
 119         typeNotFound = new SymbolNotFoundError(ABSENT_TYP);
 120         referenceNotFound = ReferenceLookupResult.error(methodNotFound);
 121 
 122         names = Names.instance(context);
 123         log = Log.instance(context);
 124         attr = Attr.instance(context);
 125         deferredAttr = DeferredAttr.instance(context);
 126         chk = Check.instance(context);
 127         infer = Infer.instance(context);
 128         finder = ClassFinder.instance(context);
 129         moduleFinder = ModuleFinder.instance(context);
 130         types = Types.instance(context);
 131         diags = JCDiagnostic.Factory.instance(context);
 132         Source source = Source.instance(context);
 133         Options options = Options.instance(context);
 134         compactMethodDiags = options.isSet(Option.XDIAGS, "compact") ||
 135                 options.isUnset(Option.XDIAGS) && options.isUnset("rawDiagnostics");
 136         verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
 137         Target target = Target.instance(context);
 138         allowMethodHandles = target.hasMethodHandles();
 139         allowFunctionalInterfaceMostSpecific = Feature.FUNCTIONAL_INTERFACE_MOST_SPECIFIC.allowedInSource(source);
 140         allowLocalVariableTypeInference = Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source);
 141         checkVarargsAccessAfterResolution =
 142                 Feature.POST_APPLICABILITY_VARARGS_ACCESS_CHECK.allowedInSource(source);
 143         polymorphicSignatureScope = WriteableScope.create(syms.noSymbol);
 144         allowModules = Feature.MODULES.allowedInSource(source);
 145     }
 146 
 147     /** error symbols, which are returned when resolution fails
 148      */
 149     private final SymbolNotFoundError varNotFound;
 150     private final SymbolNotFoundError methodNotFound;
 151     private final SymbolNotFoundError typeNotFound;
 152 
 153     /** empty reference lookup result */
 154     private final ReferenceLookupResult referenceNotFound;
 155 
 156     public static Resolve instance(Context context) {
 157         Resolve instance = context.get(resolveKey);
 158         if (instance == null)


2642     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
2643                                   Symbol location, Type site, Name name, List<Type> argtypes,
2644                                   List<Type> typeargtypes) {
2645         return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
2646     }
2647     private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
2648                                   DiagnosticPosition pos, Env<AttrContext> env,
2649                                   Symbol location, Type site, Name name, List<Type> argtypes,
2650                                   List<Type> typeargtypes) {
2651         return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
2652             @Override
2653             Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2654                 return findMethod(env, site, name, argtypes, typeargtypes,
2655                         phase.isBoxingRequired(),
2656                         phase.isVarargsRequired());
2657             }
2658             @Override
2659             Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2660                 if (sym.kind.isResolutionError()) {
2661                     sym = super.access(env, pos, location, sym);
2662                 } else if (allowMethodHandles) {
2663                     MethodSymbol msym = (MethodSymbol)sym;
2664                     if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
2665                         env.info.pendingResolutionPhase = BASIC;
2666                         return findPolymorphicSignatureInstance(env, sym, argtypes);
2667                     }
2668                 }
2669                 return sym;
2670             }
2671         });
2672     }
2673 
2674     /** Find or create an implicit method of exactly the given type (after erasure).
2675      *  Searches in a side table, not the main scope of the site.
2676      *  This emulates the lookup process required by JSR 292 in JVM.
2677      *  @param env       Attribution environment
2678      *  @param spMethod  signature polymorphic method - i.e. MH.invokeExact
2679      *  @param argtypes  The required argument types
2680      */
2681     Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,
2682                                             final Symbol spMethod,




  83  *
  84  *  <p><b>This is NOT part of any supported API.
  85  *  If you write code that depends on this, you do so at your own risk.
  86  *  This code and its internal interfaces are subject to change or
  87  *  deletion without notice.</b>
  88  */
  89 public class Resolve {
  90     protected static final Context.Key<Resolve> resolveKey = new Context.Key<>();
  91 
  92     Names names;
  93     Log log;
  94     Symtab syms;
  95     Attr attr;
  96     DeferredAttr deferredAttr;
  97     Check chk;
  98     Infer infer;
  99     ClassFinder finder;
 100     ModuleFinder moduleFinder;
 101     Types types;
 102     JCDiagnostic.Factory diags;

 103     public final boolean allowFunctionalInterfaceMostSpecific;
 104     public final boolean allowModules;
 105     public final boolean checkVarargsAccessAfterResolution;
 106     private final boolean compactMethodDiags;
 107     private final boolean allowLocalVariableTypeInference;
 108     final EnumSet<VerboseResolutionMode> verboseResolutionMode;
 109 
 110     WriteableScope polymorphicSignatureScope;
 111 
 112     protected Resolve(Context context) {
 113         context.put(resolveKey, this);
 114         syms = Symtab.instance(context);
 115 
 116         varNotFound = new SymbolNotFoundError(ABSENT_VAR);
 117         methodNotFound = new SymbolNotFoundError(ABSENT_MTH);
 118         typeNotFound = new SymbolNotFoundError(ABSENT_TYP);
 119         referenceNotFound = ReferenceLookupResult.error(methodNotFound);
 120 
 121         names = Names.instance(context);
 122         log = Log.instance(context);
 123         attr = Attr.instance(context);
 124         deferredAttr = DeferredAttr.instance(context);
 125         chk = Check.instance(context);
 126         infer = Infer.instance(context);
 127         finder = ClassFinder.instance(context);
 128         moduleFinder = ModuleFinder.instance(context);
 129         types = Types.instance(context);
 130         diags = JCDiagnostic.Factory.instance(context);
 131         Source source = Source.instance(context);
 132         Options options = Options.instance(context);
 133         compactMethodDiags = options.isSet(Option.XDIAGS, "compact") ||
 134                 options.isUnset(Option.XDIAGS) && options.isUnset("rawDiagnostics");
 135         verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
 136         Target target = Target.instance(context);

 137         allowFunctionalInterfaceMostSpecific = Feature.FUNCTIONAL_INTERFACE_MOST_SPECIFIC.allowedInSource(source);
 138         allowLocalVariableTypeInference = Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source);
 139         checkVarargsAccessAfterResolution =
 140                 Feature.POST_APPLICABILITY_VARARGS_ACCESS_CHECK.allowedInSource(source);
 141         polymorphicSignatureScope = WriteableScope.create(syms.noSymbol);
 142         allowModules = Feature.MODULES.allowedInSource(source);
 143     }
 144 
 145     /** error symbols, which are returned when resolution fails
 146      */
 147     private final SymbolNotFoundError varNotFound;
 148     private final SymbolNotFoundError methodNotFound;
 149     private final SymbolNotFoundError typeNotFound;
 150 
 151     /** empty reference lookup result */
 152     private final ReferenceLookupResult referenceNotFound;
 153 
 154     public static Resolve instance(Context context) {
 155         Resolve instance = context.get(resolveKey);
 156         if (instance == null)


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,
2680                                             final Symbol spMethod,


< prev index next >