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

changeset 267
e2722bd43f3a
parent 229
03bcd66bd8e7
child 303
8ec37cf2b37e
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Apr 16 11:23:02 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon May 04 21:04:04 2009 -0700
     1.3 @@ -118,6 +118,7 @@
     1.4          relax = (options.get("-retrofit") != null ||
     1.5                   options.get("-relax") != null);
     1.6          useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null;
     1.7 +        allowInvokedynamic = options.get("invokedynamic") != null;
     1.8      }
     1.9  
    1.10      /** Switch: relax some constraints for retrofit mode.
    1.11 @@ -149,6 +150,10 @@
    1.12       */
    1.13      boolean allowAnonOuterThis;
    1.14  
    1.15 +    /** Switch: allow invokedynamic syntax
    1.16 +     */
    1.17 +    boolean allowInvokedynamic;
    1.18 +
    1.19      /**
    1.20       * Switch: warn about use of variable before declaration?
    1.21       * RFE: 6425594
    1.22 @@ -438,14 +443,22 @@
    1.23      }
    1.24  
    1.25      /** Attribute a type argument list, returning a list of types.
    1.26 +     *  Caller is responsible for calling checkRefTypes.
    1.27       */
    1.28 -    List<Type> attribTypes(List<JCExpression> trees, Env<AttrContext> env) {
    1.29 +    List<Type> attribAnyTypes(List<JCExpression> trees, Env<AttrContext> env) {
    1.30          ListBuffer<Type> argtypes = new ListBuffer<Type>();
    1.31          for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail)
    1.32 -            argtypes.append(chk.checkRefType(l.head.pos(), attribType(l.head, env)));
    1.33 +            argtypes.append(attribType(l.head, env));
    1.34          return argtypes.toList();
    1.35      }
    1.36  
    1.37 +    /** Attribute a type argument list, returning a list of types.
    1.38 +     *  Check that all the types are references.
    1.39 +     */
    1.40 +    List<Type> attribTypes(List<JCExpression> trees, Env<AttrContext> env) {
    1.41 +        List<Type> types = attribAnyTypes(trees, env);
    1.42 +        return chk.checkRefTypes(trees, types);
    1.43 +    }
    1.44  
    1.45      /**
    1.46       * Attribute type variables (of generic classes or methods).
    1.47 @@ -1194,6 +1207,7 @@
    1.48  
    1.49          // The types of the actual method type arguments.
    1.50          List<Type> typeargtypes = null;
    1.51 +        boolean typeargtypesNonRefOK = false;
    1.52  
    1.53          Name methName = TreeInfo.name(tree.meth);
    1.54  
    1.55 @@ -1281,7 +1295,7 @@
    1.56              // Otherwise, we are seeing a regular method call.
    1.57              // Attribute the arguments, yielding list of argument types, ...
    1.58              argtypes = attribArgs(tree.args, localEnv);
    1.59 -            typeargtypes = attribTypes(tree.typeargs, localEnv);
    1.60 +            typeargtypes = attribAnyTypes(tree.typeargs, localEnv);
    1.61  
    1.62              // ... and attribute the method using as a prototype a methodtype
    1.63              // whose formal argument types is exactly the list of actual
    1.64 @@ -1318,6 +1332,20 @@
    1.65                                restype.tsym);
    1.66              }
    1.67  
    1.68 +            // as a special case, MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc)
    1.69 +            // has type <T>, and T can be a primitive type.
    1.70 +            if (tree.meth.getTag() == JCTree.SELECT && !typeargtypes.isEmpty()) {
    1.71 +              Type selt = ((JCFieldAccess) tree.meth).selected.type;
    1.72 +              if ((selt == syms.methodHandleType && methName == names.invoke) || selt == syms.invokeDynamicType) {
    1.73 +                  assert types.isSameType(restype, typeargtypes.head) : mtype;
    1.74 +                  typeargtypesNonRefOK = true;
    1.75 +              }
    1.76 +            }
    1.77 +
    1.78 +            if (!typeargtypesNonRefOK) {
    1.79 +                chk.checkRefTypes(tree.typeargs, typeargtypes);
    1.80 +            }
    1.81 +
    1.82              // Check that value of resulting type is admissible in the
    1.83              // current context.  Also, capture the return type
    1.84              result = check(tree, capture(restype), VAL, pkind, pt);

mercurial