src/share/classes/com/sun/tools/javac/code/Types.java

changeset 1510
7873d37f5b37
parent 1497
7aa2025bbb7b
child 1521
71f35e4b93a5
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Jan 21 11:16:28 2013 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Jan 21 20:13:56 2013 +0000
     1.3 @@ -354,8 +354,29 @@
     1.4                  return descSym;
     1.5              }
     1.6  
     1.7 -            public Type getType(Type origin) {
     1.8 -                return memberType(origin, descSym);
     1.9 +            public Type getType(Type site) {
    1.10 +                if (capture(site) != site) {
    1.11 +                    Type formalInterface = site.tsym.type;
    1.12 +                    ListBuffer<Type> typeargs = ListBuffer.lb();
    1.13 +                    List<Type> actualTypeargs = site.getTypeArguments();
    1.14 +                    //simply replace the wildcards with its bound
    1.15 +                    for (Type t : formalInterface.getTypeArguments()) {
    1.16 +                        if (actualTypeargs.head.hasTag(WILDCARD)) {
    1.17 +                            WildcardType wt = (WildcardType)actualTypeargs.head;
    1.18 +                            typeargs.append(wt.type);
    1.19 +                        } else {
    1.20 +                            typeargs.append(actualTypeargs.head);
    1.21 +                        }
    1.22 +                        actualTypeargs = actualTypeargs.tail;
    1.23 +                    }
    1.24 +                    site = subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
    1.25 +                    if (!chk.checkValidGenericType(site)) {
    1.26 +                        //if the inferred functional interface type is not well-formed,
    1.27 +                        //or if it's not a subtype of the original target, issue an error
    1.28 +                        throw failure(diags.fragment("no.suitable.functional.intf.inst", site));
    1.29 +                    }
    1.30 +                }
    1.31 +                return memberType(site, descSym);
    1.32              }
    1.33          }
    1.34  
    1.35 @@ -553,6 +574,15 @@
    1.36              return false;
    1.37          }
    1.38      }
    1.39 +
    1.40 +    public boolean isFunctionalInterface(Type site) {
    1.41 +        try {
    1.42 +            findDescriptorType(site);
    1.43 +            return true;
    1.44 +        } catch (FunctionDescriptorLookupError ex) {
    1.45 +            return false;
    1.46 +        }
    1.47 +    }
    1.48      // </editor-fold>
    1.49  
    1.50     /**

mercurial