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

changeset 1239
2827076dbf64
parent 1238
e28a06a3c5d9
child 1268
af6a4c24f4e3
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Mar 26 15:28:22 2012 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Mar 26 15:28:49 2012 +0100
     1.3 @@ -399,7 +399,6 @@
     1.4          else {
     1.5              Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
     1.6              return (s2 == null || s2 == sym || sym.owner == s2.owner ||
     1.7 -                    s2.isPolymorphicSignatureGeneric() ||
     1.8                      !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym)));
     1.9          }
    1.10      }
    1.11 @@ -449,7 +448,6 @@
    1.12                          boolean useVarargs,
    1.13                          Warner warn)
    1.14          throws Infer.InferenceException {
    1.15 -        boolean polymorphicSignature = m.isPolymorphicSignatureGeneric() && allowMethodHandles;
    1.16          if (useVarargs && (m.flags() & VARARGS) == 0)
    1.17              throw inapplicableMethodException.setMessage();
    1.18          Type mt = types.memberType(site, m);
    1.19 @@ -490,8 +488,7 @@
    1.20          }
    1.21  
    1.22          // find out whether we need to go the slow route via infer
    1.23 -        boolean instNeeded = tvars.tail != null || /*inlined: tvars.nonEmpty()*/
    1.24 -                polymorphicSignature;
    1.25 +        boolean instNeeded = tvars.tail != null; /*inlined: tvars.nonEmpty()*/
    1.26          for (List<Type> l = argtypes;
    1.27               l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded;
    1.28               l = l.tail) {
    1.29 @@ -499,9 +496,7 @@
    1.30          }
    1.31  
    1.32          if (instNeeded)
    1.33 -            return polymorphicSignature ?
    1.34 -                infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes) :
    1.35 -                infer.instantiateMethod(env,
    1.36 +            return infer.instantiateMethod(env,
    1.37                                      tvars,
    1.38                                      (MethodType)mt,
    1.39                                      m,
    1.40 @@ -1740,25 +1735,18 @@
    1.41                  steps = steps.tail;
    1.42              }
    1.43              if (sym.kind >= AMBIGUOUS) {
    1.44 -                if (site.tsym.isPolymorphicSignatureGeneric()) {
    1.45 -                    //polymorphic receiver - synthesize new method symbol
    1.46 +                //if nothing is found return the 'first' error
    1.47 +                MethodResolutionPhase errPhase =
    1.48 +                        currentResolutionContext.firstErroneousResolutionPhase();
    1.49 +                sym = access(currentResolutionContext.resolutionCache.get(errPhase),
    1.50 +                        pos, location, site, name, true, argtypes, typeargtypes);
    1.51 +                env.info.varArgs = errPhase.isVarargsRequired;
    1.52 +            } else if (allowMethodHandles) {
    1.53 +                MethodSymbol msym = (MethodSymbol)sym;
    1.54 +                if (msym.isSignaturePolymorphic(types)) {
    1.55                      env.info.varArgs = false;
    1.56 -                    sym = findPolymorphicSignatureInstance(env,
    1.57 -                            site, name, null, argtypes);
    1.58 +                    return findPolymorphicSignatureInstance(env, sym, argtypes);
    1.59                  }
    1.60 -                else {
    1.61 -                    //if nothing is found return the 'first' error
    1.62 -                    MethodResolutionPhase errPhase =
    1.63 -                            currentResolutionContext.firstErroneousResolutionPhase();
    1.64 -                    sym = access(currentResolutionContext.resolutionCache.get(errPhase),
    1.65 -                            pos, location, site, name, true, argtypes, typeargtypes);
    1.66 -                    env.info.varArgs = errPhase.isVarargsRequired;
    1.67 -                }
    1.68 -            } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
    1.69 -                //non-instantiated polymorphic signature - synthesize new method symbol
    1.70 -                env.info.varArgs = false;
    1.71 -                sym = findPolymorphicSignatureInstance(env,
    1.72 -                        site, name, (MethodSymbol)sym, argtypes);
    1.73              }
    1.74              return sym;
    1.75          }
    1.76 @@ -1771,40 +1759,25 @@
    1.77       *  Searches in a side table, not the main scope of the site.
    1.78       *  This emulates the lookup process required by JSR 292 in JVM.
    1.79       *  @param env       Attribution environment
    1.80 -     *  @param site      The original type from where the selection takes place.
    1.81 -     *  @param name      The method's name.
    1.82 -     *  @param spMethod  A template for the implicit method, or null.
    1.83 -     *  @param argtypes  The required argument types.
    1.84 -     *  @param typeargtypes  The required type arguments.
    1.85 +     *  @param spMethod  signature polymorphic method - i.e. MH.invokeExact
    1.86 +     *  @param argtypes  The required argument types
    1.87       */
    1.88 -    Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Type site,
    1.89 -                                            Name name,
    1.90 -                                            MethodSymbol spMethod,  // sig. poly. method or null if none
    1.91 +    Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,
    1.92 +                                            Symbol spMethod,
    1.93                                              List<Type> argtypes) {
    1.94          Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
    1.95 -                site, name, spMethod, argtypes);
    1.96 -        long flags = ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE |
    1.97 -                    (spMethod != null ?
    1.98 -                        spMethod.flags() & Flags.AccessFlags :
    1.99 -                        Flags.PUBLIC | Flags.STATIC);
   1.100 -        Symbol m = null;
   1.101 -        for (Scope.Entry e = polymorphicSignatureScope.lookup(name);
   1.102 -             e.scope != null;
   1.103 -             e = e.next()) {
   1.104 -            Symbol sym = e.sym;
   1.105 -            if (types.isSameType(mtype, sym.type) &&
   1.106 -                (sym.flags() & Flags.STATIC) == (flags & Flags.STATIC) &&
   1.107 -                types.isSameType(sym.owner.type, site)) {
   1.108 -               m = sym;
   1.109 -               break;
   1.110 +                (MethodSymbol)spMethod, argtypes);
   1.111 +        for (Symbol sym : polymorphicSignatureScope.getElementsByName(spMethod.name)) {
   1.112 +            if (types.isSameType(mtype, sym.type)) {
   1.113 +               return sym;
   1.114              }
   1.115          }
   1.116 -        if (m == null) {
   1.117 -            // create the desired method
   1.118 -            m = new MethodSymbol(flags, name, mtype, site.tsym);
   1.119 -            polymorphicSignatureScope.enter(m);
   1.120 -        }
   1.121 -        return m;
   1.122 +
   1.123 +        // create the desired method
   1.124 +        long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags;
   1.125 +        Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner);
   1.126 +        polymorphicSignatureScope.enter(msym);
   1.127 +        return msym;
   1.128      }
   1.129  
   1.130      /** Resolve a qualified method identifier, throw a fatal error if not

mercurial