Tue, 12 Feb 2013 17:15:29 -0800
8008077: update reference impl for type-annotations
Reviewed-by: jjg
Contributed-by: wmdietl@cs.washington.edu
1.1 --- a/src/share/classes/com/sun/tools/classfile/ClassWriter.java Tue Feb 12 19:25:09 2013 +0000 1.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java Tue Feb 12 17:15:29 2013 -0800 1.3 @@ -727,12 +727,13 @@ 1.4 private void write(TypeAnnotation.Position p, ClassOutputStream out) { 1.5 out.writeByte(p.type.targetTypeValue()); 1.6 switch (p.type) { 1.7 - // type cast 1.8 - case CAST: 1.9 // instanceof 1.10 case INSTANCEOF: 1.11 // new expression 1.12 case NEW: 1.13 + // constructor/method reference receiver 1.14 + case CONSTRUCTOR_REFERENCE: 1.15 + case METHOD_REFERENCE: 1.16 out.writeShort(p.offset); 1.17 break; 1.18 // local variable 1.19 @@ -779,9 +780,12 @@ 1.20 case METHOD_FORMAL_PARAMETER: 1.21 out.writeByte(p.parameter_index); 1.22 break; 1.23 + // type cast 1.24 + case CAST: 1.25 // method/constructor/reference type argument 1.26 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 1.27 case METHOD_INVOCATION_TYPE_ARGUMENT: 1.28 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 1.29 case METHOD_REFERENCE_TYPE_ARGUMENT: 1.30 out.writeShort(p.offset); 1.31 out.writeByte(p.type_index); 1.32 @@ -790,10 +794,6 @@ 1.33 case METHOD_RETURN: 1.34 case FIELD: 1.35 break; 1.36 - // lambda formal parameter 1.37 - case LAMBDA_FORMAL_PARAMETER: 1.38 - out.writeByte(p.parameter_index); 1.39 - break; 1.40 case UNKNOWN: 1.41 throw new AssertionError("ClassWriter: UNKNOWN target type should never occur!"); 1.42 default:
2.1 --- a/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java Tue Feb 12 19:25:09 2013 +0000 2.2 +++ b/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java Tue Feb 12 17:15:29 2013 -0800 2.3 @@ -86,12 +86,13 @@ 2.4 position.type = type; 2.5 2.6 switch (type) { 2.7 - // type cast 2.8 - case CAST: 2.9 // instanceof 2.10 case INSTANCEOF: 2.11 // new expression 2.12 case NEW: 2.13 + // constructor/method reference receiver 2.14 + case CONSTRUCTOR_REFERENCE: 2.15 + case METHOD_REFERENCE: 2.16 position.offset = cr.readUnsignedShort(); 2.17 break; 2.18 // local variable 2.19 @@ -142,9 +143,12 @@ 2.20 case METHOD_FORMAL_PARAMETER: 2.21 position.parameter_index = cr.readUnsignedByte(); 2.22 break; 2.23 + // type cast 2.24 + case CAST: 2.25 // method/constructor/reference type argument 2.26 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 2.27 case METHOD_INVOCATION_TYPE_ARGUMENT: 2.28 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 2.29 case METHOD_REFERENCE_TYPE_ARGUMENT: 2.30 position.offset = cr.readUnsignedShort(); 2.31 position.type_index = cr.readUnsignedByte(); 2.32 @@ -153,10 +157,6 @@ 2.33 case METHOD_RETURN: 2.34 case FIELD: 2.35 break; 2.36 - // lambda formal parameter 2.37 - case LAMBDA_FORMAL_PARAMETER: 2.38 - position.parameter_index = cr.readUnsignedByte(); 2.39 - break; 2.40 case UNKNOWN: 2.41 throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!"); 2.42 default: 2.43 @@ -177,13 +177,14 @@ 2.44 int n = 0; 2.45 n += 1; // TargetType tag is a byte 2.46 switch (pos.type) { 2.47 - // type cast 2.48 - case CAST: 2.49 // instanceof 2.50 case INSTANCEOF: 2.51 // new expression 2.52 case NEW: 2.53 - n += 2; 2.54 + // constructor/method reference receiver 2.55 + case CONSTRUCTOR_REFERENCE: 2.56 + case METHOD_REFERENCE: 2.57 + n += 2; // offset 2.58 break; 2.59 // local variable 2.60 case LOCAL_VARIABLE: 2.61 @@ -192,7 +193,7 @@ 2.62 n += 2; // table_length; 2.63 int table_length = pos.lvarOffset.length; 2.64 n += 2 * table_length; // offset 2.65 - n += 2 * table_length; // length; 2.66 + n += 2 * table_length; // length 2.67 n += 2 * table_length; // index 2.68 break; 2.69 // exception parameter 2.70 @@ -206,7 +207,7 @@ 2.71 // type parameter 2.72 case CLASS_TYPE_PARAMETER: 2.73 case METHOD_TYPE_PARAMETER: 2.74 - n += 1; // parameter_index; 2.75 + n += 1; // parameter_index 2.76 break; 2.77 // type parameter bound 2.78 case CLASS_TYPE_PARAMETER_BOUND: 2.79 @@ -226,9 +227,12 @@ 2.80 case METHOD_FORMAL_PARAMETER: 2.81 n += 1; // parameter_index 2.82 break; 2.83 + // type cast 2.84 + case CAST: 2.85 // method/constructor/reference type argument 2.86 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 2.87 case METHOD_INVOCATION_TYPE_ARGUMENT: 2.88 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 2.89 case METHOD_REFERENCE_TYPE_ARGUMENT: 2.90 n += 2; // offset 2.91 n += 1; // type index 2.92 @@ -237,10 +241,6 @@ 2.93 case METHOD_RETURN: 2.94 case FIELD: 2.95 break; 2.96 - // lambda formal parameter 2.97 - case LAMBDA_FORMAL_PARAMETER: 2.98 - n += 1; // parameter_index 2.99 - break; 2.100 case UNKNOWN: 2.101 throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!"); 2.102 default: 2.103 @@ -377,12 +377,13 @@ 2.104 sb.append(type); 2.105 2.106 switch (type) { 2.107 - // type cast 2.108 - case CAST: 2.109 // instanceof 2.110 case INSTANCEOF: 2.111 // new expression 2.112 case NEW: 2.113 + // constructor/method reference receiver 2.114 + case CONSTRUCTOR_REFERENCE: 2.115 + case METHOD_REFERENCE: 2.116 sb.append(", offset = "); 2.117 sb.append(offset); 2.118 break; 2.119 @@ -444,9 +445,12 @@ 2.120 sb.append(", param_index = "); 2.121 sb.append(parameter_index); 2.122 break; 2.123 + // type cast 2.124 + case CAST: 2.125 // method/constructor/reference type argument 2.126 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 2.127 case METHOD_INVOCATION_TYPE_ARGUMENT: 2.128 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 2.129 case METHOD_REFERENCE_TYPE_ARGUMENT: 2.130 sb.append(", offset = "); 2.131 sb.append(offset); 2.132 @@ -457,12 +461,6 @@ 2.133 case METHOD_RETURN: 2.134 case FIELD: 2.135 break; 2.136 - // lambda formal parameter 2.137 - case LAMBDA_FORMAL_PARAMETER: 2.138 - // TODO: also needs an offset? 2.139 - sb.append(", param_index = "); 2.140 - sb.append(parameter_index); 2.141 - break; 2.142 case UNKNOWN: 2.143 sb.append(", position UNKNOWN!"); 2.144 break; 2.145 @@ -564,34 +562,37 @@ 2.146 /** For annotations on an exception parameter. */ 2.147 EXCEPTION_PARAMETER(0x42, true), 2.148 2.149 - /** For annotations on a typecast. */ 2.150 - CAST(0x43, true), 2.151 - 2.152 /** For annotations on a type test. */ 2.153 - INSTANCEOF(0x44, true), 2.154 + INSTANCEOF(0x43, true), 2.155 2.156 /** For annotations on an object creation expression. */ 2.157 - NEW(0x45, true), 2.158 + NEW(0x44, true), 2.159 + 2.160 + /** For annotations on a constructor reference receiver. */ 2.161 + CONSTRUCTOR_REFERENCE(0x45, true), 2.162 + 2.163 + /** For annotations on a method reference receiver. */ 2.164 + METHOD_REFERENCE(0x46, true), 2.165 + 2.166 + /** For annotations on a typecast. */ 2.167 + CAST(0x47, true), 2.168 2.169 /** For annotations on a type argument of an object creation expression. */ 2.170 - CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x46, true), 2.171 + CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x48, true), 2.172 2.173 /** For annotations on a type argument of a method call. */ 2.174 - METHOD_INVOCATION_TYPE_ARGUMENT(0x47, true), 2.175 + METHOD_INVOCATION_TYPE_ARGUMENT(0x49, true), 2.176 2.177 - /** For annotations on a lambda parameter type. */ 2.178 - LAMBDA_FORMAL_PARAMETER(0x48, true), 2.179 - 2.180 - /** For annotations on a method reference. */ 2.181 - METHOD_REFERENCE(0x49, true), 2.182 + /** For annotations on a type argument of a constructor reference. */ 2.183 + CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true), 2.184 2.185 /** For annotations on a type argument of a method reference. */ 2.186 - METHOD_REFERENCE_TYPE_ARGUMENT(0x50, true), 2.187 + METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true), 2.188 2.189 /** For annotations with an unknown target. */ 2.190 UNKNOWN(0xFF); 2.191 2.192 - private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x50; 2.193 + private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B; 2.194 2.195 private final int targetTypeValue; 2.196 private final boolean isLocal;
3.1 --- a/src/share/classes/com/sun/tools/javac/code/TargetType.java Tue Feb 12 19:25:09 2013 +0000 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/TargetType.java Tue Feb 12 17:15:29 2013 -0800 3.3 @@ -82,34 +82,37 @@ 3.4 /** For annotations on an exception parameter. */ 3.5 EXCEPTION_PARAMETER(0x42, true), 3.6 3.7 - /** For annotations on a typecast. */ 3.8 - CAST(0x43, true), 3.9 - 3.10 /** For annotations on a type test. */ 3.11 - INSTANCEOF(0x44, true), 3.12 + INSTANCEOF(0x43, true), 3.13 3.14 /** For annotations on an object creation expression. */ 3.15 - NEW(0x45, true), 3.16 + NEW(0x44, true), 3.17 + 3.18 + /** For annotations on a constructor reference receiver. */ 3.19 + CONSTRUCTOR_REFERENCE(0x45, true), 3.20 + 3.21 + /** For annotations on a method reference receiver. */ 3.22 + METHOD_REFERENCE(0x46, true), 3.23 + 3.24 + /** For annotations on a typecast. */ 3.25 + CAST(0x47, true), 3.26 3.27 /** For annotations on a type argument of an object creation expression. */ 3.28 - CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x46, true), 3.29 + CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x48, true), 3.30 3.31 /** For annotations on a type argument of a method call. */ 3.32 - METHOD_INVOCATION_TYPE_ARGUMENT(0x47, true), 3.33 + METHOD_INVOCATION_TYPE_ARGUMENT(0x49, true), 3.34 3.35 - /** For annotations on a lambda parameter type. */ 3.36 - LAMBDA_FORMAL_PARAMETER(0x48, true), 3.37 - 3.38 - /** For annotations on a method reference. */ 3.39 - METHOD_REFERENCE(0x49, true), 3.40 + /** For annotations on a type argument of a constructor reference. */ 3.41 + CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true), 3.42 3.43 /** For annotations on a type argument of a method reference. */ 3.44 - METHOD_REFERENCE_TYPE_ARGUMENT(0x50, true), 3.45 + METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true), 3.46 3.47 /** For annotations with an unknown target. */ 3.48 UNKNOWN(0xFF); 3.49 3.50 - private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x92; 3.51 + private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B; 3.52 3.53 private final int targetTypeValue; 3.54 private final boolean isLocal;
4.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java Tue Feb 12 19:25:09 2013 +0000 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java Tue Feb 12 17:15:29 2013 -0800 4.3 @@ -126,7 +126,8 @@ 4.4 // Tree position. 4.5 public int pos = -1; 4.6 4.7 - // For typecasts, type tests, new (and locals, as start_pc). 4.8 + // For type casts, type tests, new, locals (as start_pc), 4.9 + // and method and constructor reference type arguments. 4.10 public boolean isValidOffset = false; 4.11 public int offset = -1; 4.12 4.13 @@ -156,12 +157,13 @@ 4.14 sb.append(type); 4.15 4.16 switch (type) { 4.17 - // type cast 4.18 - case CAST: 4.19 // instanceof 4.20 case INSTANCEOF: 4.21 // new expression 4.22 case NEW: 4.23 + // constructor/method reference receiver 4.24 + case CONSTRUCTOR_REFERENCE: 4.25 + case METHOD_REFERENCE: 4.26 sb.append(", offset = "); 4.27 sb.append(offset); 4.28 break; 4.29 @@ -223,9 +225,12 @@ 4.30 sb.append(", param_index = "); 4.31 sb.append(parameter_index); 4.32 break; 4.33 + // type cast 4.34 + case CAST: 4.35 // method/constructor/reference type argument 4.36 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 4.37 case METHOD_INVOCATION_TYPE_ARGUMENT: 4.38 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 4.39 case METHOD_REFERENCE_TYPE_ARGUMENT: 4.40 sb.append(", offset = "); 4.41 sb.append(offset); 4.42 @@ -236,12 +241,6 @@ 4.43 case METHOD_RETURN: 4.44 case FIELD: 4.45 break; 4.46 - // lambda formal parameter 4.47 - case LAMBDA_FORMAL_PARAMETER: 4.48 - // TODO: also needs an offset? 4.49 - sb.append(", param_index = "); 4.50 - sb.append(parameter_index); 4.51 - break; 4.52 case UNKNOWN: 4.53 sb.append(", position UNKNOWN!"); 4.54 break;
5.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Tue Feb 12 19:25:09 2013 +0000 5.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Tue Feb 12 17:15:29 2013 -0800 5.3 @@ -217,6 +217,9 @@ 5.4 // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore 5.5 // need to set its position explicitly. 5.6 // The method returns a copy of type that contains these annotations. 5.7 + // 5.8 + // As a side effect the method sets the type annotation position of "annotations". 5.9 + // Note that it is assumed that all annotations share the same position. 5.10 private static Type typeWithAnnotations(final JCTree typetree, final Type type, 5.11 final List<Attribute.TypeCompound> annotations, Log log) { 5.12 // System.out.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s)%n", 5.13 @@ -267,7 +270,9 @@ 5.14 } 5.15 Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, log); 5.16 tomodify.elemtype = arelemType; 5.17 - for (Attribute.TypeCompound a : annotations) { 5.18 + { 5.19 + // All annotations share the same position; modify the first one. 5.20 + Attribute.TypeCompound a = annotations.get(0); 5.21 TypeAnnotationPosition p = a.position; 5.22 p.location = p.location.prependList(depth.toList()); 5.23 } 5.24 @@ -345,10 +350,10 @@ 5.25 if (depth.nonEmpty()) { 5.26 // Only need to change the annotation positions 5.27 // if they are on an enclosed type. 5.28 - for (Attribute.TypeCompound a : annotations) { 5.29 - TypeAnnotationPosition p = a.position; 5.30 - p.location = p.location.appendList(depth.toList()); 5.31 - } 5.32 + // All annotations share the same position; modify the first one. 5.33 + Attribute.TypeCompound a = annotations.get(0); 5.34 + TypeAnnotationPosition p = a.position; 5.35 + p.location = p.location.appendList(depth.toList()); 5.36 } 5.37 5.38 Type ret = typeWithAnnotations(type, enclTy, annotations); 5.39 @@ -463,8 +468,7 @@ 5.40 5.41 @Override 5.42 public Type visitType(Type t, List<TypeCompound> s) { 5.43 - // Error? 5.44 - return t; 5.45 + return new AnnotatedType(s, t); 5.46 } 5.47 }; 5.48 5.49 @@ -575,6 +579,10 @@ 5.50 System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind()); 5.51 System.out.println(" Framing tree: " + frame + " kind: " + frame.getKind()); 5.52 */ 5.53 + 5.54 + // Note that p.offset is set in 5.55 + // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int) 5.56 + 5.57 switch (frame.getKind()) { 5.58 case TYPE_CAST: 5.59 p.type = TargetType.CAST; 5.60 @@ -659,6 +667,45 @@ 5.61 return; 5.62 } 5.63 5.64 + case MEMBER_REFERENCE: { 5.65 + JCMemberReference mrframe = (JCMemberReference) frame; 5.66 + 5.67 + if (mrframe.expr == tree) { 5.68 + switch (mrframe.mode) { 5.69 + case INVOKE: 5.70 + p.type = TargetType.METHOD_REFERENCE; 5.71 + break; 5.72 + case NEW: 5.73 + p.type = TargetType.CONSTRUCTOR_REFERENCE; 5.74 + break; 5.75 + default: 5.76 + Assert.error("Unknown method reference mode " + mrframe.mode + 5.77 + " for tree " + tree + " within frame " + frame); 5.78 + } 5.79 + p.pos = frame.pos; 5.80 + } else if (mrframe.typeargs != null && 5.81 + mrframe.typeargs.contains(tree)) { 5.82 + int arg = mrframe.typeargs.indexOf(tree); 5.83 + p.type_index = arg; 5.84 + switch (mrframe.mode) { 5.85 + case INVOKE: 5.86 + p.type = TargetType.METHOD_REFERENCE_TYPE_ARGUMENT; 5.87 + break; 5.88 + case NEW: 5.89 + p.type = TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT; 5.90 + break; 5.91 + default: 5.92 + Assert.error("Unknown method reference mode " + mrframe.mode + 5.93 + " for tree " + tree + " within frame " + frame); 5.94 + } 5.95 + p.pos = frame.pos; 5.96 + } else { 5.97 + Assert.error("Could not determine type argument position of tree " + tree + 5.98 + " within frame " + frame); 5.99 + } 5.100 + return; 5.101 + } 5.102 + 5.103 case ARRAY_TYPE: { 5.104 ListBuffer<TypePathEntry> index = ListBuffer.lb(); 5.105 index = index.append(TypePathEntry.ARRAY); 5.106 @@ -766,6 +813,14 @@ 5.107 return; 5.108 } 5.109 5.110 + case INTERSECTION_TYPE: { 5.111 + JCTypeIntersection isect = (JCTypeIntersection)frame; 5.112 + p.type_index = isect.bounds.indexOf(tree); 5.113 + List<JCTree> newPath = path.tail; 5.114 + resolveFrame(newPath.head, newPath.tail.head, newPath, p); 5.115 + return; 5.116 + } 5.117 + 5.118 case METHOD_INVOCATION: { 5.119 JCMethodInvocation invocation = (JCMethodInvocation)frame; 5.120 if (!invocation.typeargs.contains(tree)) { 5.121 @@ -911,6 +966,8 @@ 5.122 public void visitVarDef(final JCVariableDecl tree) { 5.123 if (tree.sym == null) { 5.124 // Something is wrong already. Quietly ignore. 5.125 + } else if (tree.sym.getKind() == ElementKind.PARAMETER) { 5.126 + // Parameters are handled in visitMethodDef above. 5.127 } else if (tree.sym.getKind() == ElementKind.FIELD) { 5.128 if (sigOnly) { 5.129 TypeAnnotationPosition pos = new TypeAnnotationPosition(); 5.130 @@ -924,7 +981,6 @@ 5.131 pos.pos = tree.pos; 5.132 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); 5.133 } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { 5.134 - // System.out.println("Found exception param: " + tree); 5.135 TypeAnnotationPosition pos = new TypeAnnotationPosition(); 5.136 pos.type = TargetType.EXCEPTION_PARAMETER; 5.137 pos.pos = tree.pos; 5.138 @@ -934,9 +990,11 @@ 5.139 pos.type = TargetType.RESOURCE_VARIABLE; 5.140 pos.pos = tree.pos; 5.141 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); 5.142 + } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) { 5.143 + // No type annotations can occur here. 5.144 } else { 5.145 // There is nothing else in a variable declaration that needs separation. 5.146 - // System.out.println("We found a: " + tree); 5.147 + Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind()); 5.148 } 5.149 5.150 push(tree);
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Tue Feb 12 19:25:09 2013 +0000 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Tue Feb 12 17:15:29 2013 -0800 6.3 @@ -2068,7 +2068,15 @@ 6.4 6.5 @Override 6.6 public Type visitAnnotatedType(AnnotatedType t, Boolean recurse) { 6.7 - return new AnnotatedType(t.typeAnnotations, erasure(t.underlyingType, recurse)); 6.8 + Type erased = erasure(t.underlyingType, recurse); 6.9 + if (erased.getKind() == TypeKind.ANNOTATED) { 6.10 + // This can only happen when the underlying type is a 6.11 + // type variable and the upper bound of it is annotated. 6.12 + // The annotation on the type variable overrides the one 6.13 + // on the bound. 6.14 + erased = ((AnnotatedType)erased).underlyingType; 6.15 + } 6.16 + return new AnnotatedType(t.typeAnnotations, erased); 6.17 } 6.18 }; 6.19
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Feb 12 19:25:09 2013 +0000 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Feb 12 17:15:29 2013 -0800 7.3 @@ -766,6 +766,8 @@ 7.4 JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); 7.5 7.6 try { 7.7 + memberEnter.typeAnnotate(initializer, env, env.info.enclVar); 7.8 + annotate.flush(); 7.9 Type itype = attribExpr(initializer, env, type); 7.10 if (itype.constValue() != null) 7.11 return coerce(itype, type).constValue(); 7.12 @@ -2539,7 +2541,7 @@ 7.13 7.14 if (exprType.isErroneous()) { 7.15 //if the qualifier expression contains problems, 7.16 - //give up atttribution of method reference 7.17 + //give up attribution of method reference 7.18 result = that.type = exprType; 7.19 return; 7.20 }
8.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Feb 12 19:25:09 2013 +0000 8.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Feb 12 17:15:29 2013 -0800 8.3 @@ -1470,12 +1470,13 @@ 8.4 position.type = type; 8.5 8.6 switch (type) { 8.7 - // type cast 8.8 - case CAST: 8.9 // instanceof 8.10 case INSTANCEOF: 8.11 // new expression 8.12 case NEW: 8.13 + // constructor/method reference receiver 8.14 + case CONSTRUCTOR_REFERENCE: 8.15 + case METHOD_REFERENCE: 8.16 position.offset = nextChar(); 8.17 break; 8.18 // local variable 8.19 @@ -1524,9 +1525,12 @@ 8.20 case METHOD_FORMAL_PARAMETER: 8.21 position.parameter_index = nextByte(); 8.22 break; 8.23 + // type cast 8.24 + case CAST: 8.25 // method/constructor/reference type argument 8.26 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 8.27 case METHOD_INVOCATION_TYPE_ARGUMENT: 8.28 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 8.29 case METHOD_REFERENCE_TYPE_ARGUMENT: 8.30 position.offset = nextChar(); 8.31 position.type_index = nextByte(); 8.32 @@ -1535,10 +1539,6 @@ 8.33 case METHOD_RETURN: 8.34 case FIELD: 8.35 break; 8.36 - // lambda formal parameter 8.37 - case LAMBDA_FORMAL_PARAMETER: 8.38 - position.parameter_index = nextByte(); 8.39 - break; 8.40 case UNKNOWN: 8.41 throw new AssertionError("jvm.ClassReader: UNKNOWN target type should never occur!"); 8.42 default:
9.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Feb 12 19:25:09 2013 +0000 9.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Feb 12 17:15:29 2013 -0800 9.3 @@ -992,12 +992,13 @@ 9.4 void writePosition(TypeAnnotationPosition p) { 9.5 databuf.appendByte(p.type.targetTypeValue()); // TargetType tag is a byte 9.6 switch (p.type) { 9.7 - // type cast 9.8 - case CAST: 9.9 // instanceof 9.10 case INSTANCEOF: 9.11 // new expression 9.12 case NEW: 9.13 + // constructor/method reference receiver 9.14 + case CONSTRUCTOR_REFERENCE: 9.15 + case METHOD_REFERENCE: 9.16 databuf.appendChar(p.offset); 9.17 break; 9.18 // local variable 9.19 @@ -1042,9 +1043,12 @@ 9.20 case METHOD_FORMAL_PARAMETER: 9.21 databuf.appendByte(p.parameter_index); 9.22 break; 9.23 + // type cast 9.24 + case CAST: 9.25 // method/constructor/reference type argument 9.26 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 9.27 case METHOD_INVOCATION_TYPE_ARGUMENT: 9.28 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 9.29 case METHOD_REFERENCE_TYPE_ARGUMENT: 9.30 databuf.appendChar(p.offset); 9.31 databuf.appendByte(p.type_index); 9.32 @@ -1053,10 +1057,6 @@ 9.33 case METHOD_RETURN: 9.34 case FIELD: 9.35 break; 9.36 - // lambda formal parameter 9.37 - case LAMBDA_FORMAL_PARAMETER: 9.38 - databuf.appendByte(p.parameter_index); 9.39 - break; 9.40 case UNKNOWN: 9.41 throw new AssertionError("jvm.ClassWriter: UNKNOWN target type should never occur!"); 9.42 default:
10.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Feb 12 19:25:09 2013 +0000 10.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Feb 12 17:15:29 2013 -0800 10.3 @@ -1164,7 +1164,7 @@ 10.4 } else return illegal(); 10.5 break; 10.6 case MONKEYS_AT: 10.7 - // Only annotated cast types are valid 10.8 + // Only annotated cast types and method references are valid 10.9 List<JCAnnotation> typeAnnos = typeAnnotationsOpt(); 10.10 if (typeAnnos.isEmpty()) { 10.11 // else there would be no '@' 10.12 @@ -1175,17 +1175,27 @@ 10.13 10.14 if ((mode & TYPE) == 0) { 10.15 // Type annotations on class literals no longer legal 10.16 - if (!expr.hasTag(Tag.SELECT)) { 10.17 + switch (expr.getTag()) { 10.18 + case REFERENCE: { 10.19 + JCMemberReference mref = (JCMemberReference) expr; 10.20 + mref.expr = toP(F.at(pos).AnnotatedType(typeAnnos, mref.expr)); 10.21 + t = mref; 10.22 + break; 10.23 + } 10.24 + case SELECT: { 10.25 + JCFieldAccess sel = (JCFieldAccess) expr; 10.26 + 10.27 + if (sel.name != names._class) { 10.28 + return illegal(); 10.29 + } else { 10.30 + log.error(token.pos, "no.annotations.on.dot.class"); 10.31 + return expr; 10.32 + } 10.33 + } 10.34 + default: 10.35 return illegal(typeAnnos.head.pos); 10.36 } 10.37 - JCFieldAccess sel = (JCFieldAccess)expr; 10.38 - 10.39 - if (sel.name != names._class) { 10.40 - return illegal(); 10.41 - } else { 10.42 - log.error(token.pos, "no.annotations.on.dot.class"); 10.43 - return expr; 10.44 - } 10.45 + 10.46 } else { 10.47 // Type annotations targeting a cast 10.48 t = insertAnnotationsToMostInner(expr, typeAnnos, false); 10.49 @@ -1457,18 +1467,40 @@ 10.50 /** 10.51 * If we see an identifier followed by a '<' it could be an unbound 10.52 * method reference or a binary expression. To disambiguate, look for a 10.53 - * matching '>' and see if the subsequent terminal is either '.' or '#'. 10.54 + * matching '>' and see if the subsequent terminal is either '.' or '::'. 10.55 */ 10.56 @SuppressWarnings("fallthrough") 10.57 boolean isUnboundMemberRef() { 10.58 int pos = 0, depth = 0; 10.59 - for (Token t = S.token(pos) ; ; t = S.token(++pos)) { 10.60 + outer: for (Token t = S.token(pos) ; ; t = S.token(++pos)) { 10.61 switch (t.kind) { 10.62 case IDENTIFIER: case UNDERSCORE: case QUES: case EXTENDS: case SUPER: 10.63 case DOT: case RBRACKET: case LBRACKET: case COMMA: 10.64 case BYTE: case SHORT: case INT: case LONG: case FLOAT: 10.65 case DOUBLE: case BOOLEAN: case CHAR: 10.66 + case MONKEYS_AT: 10.67 break; 10.68 + 10.69 + case LPAREN: 10.70 + // skip annotation values 10.71 + int nesting = 0; 10.72 + for (; ; pos++) { 10.73 + TokenKind tk2 = S.token(pos).kind; 10.74 + switch (tk2) { 10.75 + case EOF: 10.76 + return false; 10.77 + case LPAREN: 10.78 + nesting++; 10.79 + break; 10.80 + case RPAREN: 10.81 + nesting--; 10.82 + if (nesting == 0) { 10.83 + continue outer; 10.84 + } 10.85 + break; 10.86 + } 10.87 + } 10.88 + 10.89 case LT: 10.90 depth++; break; 10.91 case GTGTGT: 10.92 @@ -1494,7 +1526,7 @@ 10.93 /** 10.94 * If we see an identifier followed by a '<' it could be an unbound 10.95 * method reference or a binary expression. To disambiguate, look for a 10.96 - * matching '>' and see if the subsequent terminal is either '.' or '#'. 10.97 + * matching '>' and see if the subsequent terminal is either '.' or '::'. 10.98 */ 10.99 @SuppressWarnings("fallthrough") 10.100 ParensResult analyzeParens() {
11.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Tue Feb 12 19:25:09 2013 +0000 11.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Tue Feb 12 17:15:29 2013 -0800 11.3 @@ -235,6 +235,7 @@ 11.4 switch(tree.getTag()) { 11.5 case TYPEAPPLY: return ((JCTypeApply)tree).getTypeArguments().isEmpty(); 11.6 case NEWCLASS: return isDiamond(((JCNewClass)tree).clazz); 11.7 + case ANNOTATED_TYPE: return isDiamond(((JCAnnotatedType)tree).underlyingType); 11.8 default: return false; 11.9 } 11.10 } 11.11 @@ -335,6 +336,8 @@ 11.12 case TYPEAPPLY: 11.13 case TYPEARRAY: 11.14 return true; 11.15 + case ANNOTATED_TYPE: 11.16 + return isStaticSelector(((JCAnnotatedType)base).underlyingType, names); 11.17 default: 11.18 return false; 11.19 }
12.1 --- a/src/share/classes/com/sun/tools/javap/AnnotationWriter.java Tue Feb 12 19:25:09 2013 +0000 12.2 +++ b/src/share/classes/com/sun/tools/javap/AnnotationWriter.java Tue Feb 12 17:15:29 2013 -0800 12.3 @@ -91,12 +91,13 @@ 12.4 print(pos.type); 12.5 12.6 switch (pos.type) { 12.7 - // type cast 12.8 - case CAST: 12.9 // instanceof 12.10 case INSTANCEOF: 12.11 // new expression 12.12 case NEW: 12.13 + // constructor/method reference receiver 12.14 + case CONSTRUCTOR_REFERENCE: 12.15 + case METHOD_REFERENCE: 12.16 if (showOffsets) { 12.17 print(", offset="); 12.18 print(pos.offset); 12.19 @@ -162,9 +163,12 @@ 12.20 print(", param_index="); 12.21 print(pos.parameter_index); 12.22 break; 12.23 + // type cast 12.24 + case CAST: 12.25 // method/constructor/reference type argument 12.26 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 12.27 case METHOD_INVOCATION_TYPE_ARGUMENT: 12.28 + case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 12.29 case METHOD_REFERENCE_TYPE_ARGUMENT: 12.30 if (showOffsets) { 12.31 print(", offset="); 12.32 @@ -177,11 +181,6 @@ 12.33 case METHOD_RETURN: 12.34 case FIELD: 12.35 break; 12.36 - // lambda formal parameter 12.37 - case LAMBDA_FORMAL_PARAMETER: 12.38 - print(", param_index="); 12.39 - print(pos.parameter_index); 12.40 - break; 12.41 case UNKNOWN: 12.42 throw new AssertionError("AnnotationWriter: UNKNOWN target type should never occur!"); 12.43 default:
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java Tue Feb 12 17:15:29 2013 -0800 13.3 @@ -0,0 +1,44 @@ 13.4 +/* 13.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +/* 13.28 + * @test 13.29 + * @bug 8008077 13.30 + * @summary Type annotations in a lazy constant need to be attributed 13.31 + * in the correct order. 13.32 + * @author Werner Dietl 13.33 + * @compile LazyConstantValue.java 13.34 + */ 13.35 + 13.36 +import java.lang.annotation.*; 13.37 + 13.38 +class ClassA { 13.39 + Object o = ClassB.lcv; 13.40 +} 13.41 + 13.42 +class ClassB { 13.43 + static final String[] lcv = new @TA String[0]; 13.44 +} 13.45 + 13.46 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) 13.47 +@interface TA {}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/TypeVariable.java Tue Feb 12 17:15:29 2013 -0800 14.3 @@ -0,0 +1,43 @@ 14.4 +/* 14.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * @test 14.29 + * @bug 8008077 14.30 + * @summary Type annotations on a type variable, where the bound of 14.31 + * the type variable is also annotated, need to be processed correctly. 14.32 + * @author Werner Dietl 14.33 + * @compile TypeVariable.java 14.34 + */ 14.35 + 14.36 +import java.lang.annotation.*; 14.37 + 14.38 +class TypeVariable { 14.39 + <TV extends @TA Object> TV cast(TV p) { 14.40 + return (@TA TV) p; 14.41 + } 14.42 +} 14.43 + 14.44 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) 14.45 +@interface TA {} 14.46 +
15.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/VoidGenericMethod.java Tue Feb 12 19:25:09 2013 +0000 15.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/VoidGenericMethod.java Tue Feb 12 17:15:29 2013 -0800 15.3 @@ -21,6 +21,8 @@ 15.4 * questions. 15.5 */ 15.6 15.7 +import java.lang.annotation.*; 15.8 + 15.9 /* 15.10 * @test 15.11 * @bug 6843077 8006775 15.12 @@ -29,7 +31,8 @@ 15.13 * @compile/fail VoidGenericMethod.java 15.14 */ 15.15 class VoidGenericMethod { 15.16 - public <T> @A void method() { } 15.17 + public @A <T> void method() { } 15.18 } 15.19 15.20 +@Target(ElementType.TYPE_USE) 15.21 @interface A { }
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/Lambda.java Tue Feb 12 17:15:29 2013 -0800 16.3 @@ -0,0 +1,59 @@ 16.4 +/* 16.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +/* 16.28 + * @test 16.29 + * @bug 8008077 16.30 + * @summary new type annotation location: lambda expressions 16.31 + * @compile Lambda.java 16.32 + * @author Werner Dietl 16.33 + */ 16.34 + 16.35 +import java.lang.annotation.*; 16.36 + 16.37 +public class Lambda { 16.38 + 16.39 + interface LambdaInt { 16.40 + <S, T> void generic(S p1, T p2); 16.41 + } 16.42 + 16.43 + static class LambdaImpl implements LambdaInt { 16.44 + <S, T> LambdaImpl(S p1, T p2) {} 16.45 + public <S, T> void generic(S p1, T p2) {} 16.46 + } 16.47 + 16.48 + LambdaInt getMethodRefTA(LambdaImpl r) { 16.49 + return r::<@TA Object, @TB Object>generic; 16.50 + } 16.51 + 16.52 + LambdaInt getConstructorRefTA() { 16.53 + return LambdaImpl::<@TA Object, @TB Object>new; 16.54 + } 16.55 + 16.56 +} 16.57 + 16.58 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) 16.59 +@interface TA { } 16.60 + 16.61 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) 16.62 +@interface TB { }
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java Tue Feb 12 17:15:29 2013 -0800 17.3 @@ -0,0 +1,262 @@ 17.4 +/* 17.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +/* 17.28 + * @test 17.29 + * @bug 8008077 17.30 + * @summary Test population of reference info for lambda expressions 17.31 + * @compile -g Driver.java ReferenceInfoUtil.java Lambda.java 17.32 + * @run main Driver Lambda 17.33 + * @author Werner Dietl 17.34 + */ 17.35 + 17.36 +import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 17.37 + 17.38 +public class Lambda { 17.39 + 17.40 + @TADescriptions({ 17.41 + @TADescription(annotation = "TA", type = METHOD_REFERENCE, 17.42 + offset = ReferenceInfoUtil.IGNORE_VALUE), 17.43 + @TADescription(annotation = "TB", type = METHOD_REFERENCE, 17.44 + offset = ReferenceInfoUtil.IGNORE_VALUE) 17.45 + }) 17.46 + public String returnMethodRef1() { 17.47 + return 17.48 + "class Lambda {" + 17.49 + " public String getName() { return \"Lambda!\"; }" + 17.50 + "}" + 17.51 + 17.52 + "class Test {" + 17.53 + " java.util.function.Function<Lambda, String> lambda() {" + 17.54 + " return @TA @TB Lambda::getName;" + 17.55 + " }" + 17.56 + "}"; 17.57 + } 17.58 + 17.59 + @TADescriptions({ 17.60 + @TADescription(annotation = "TA", type = METHOD_REFERENCE, 17.61 + offset = ReferenceInfoUtil.IGNORE_VALUE), 17.62 + @TADescription(annotation = "TB", type = METHOD_REFERENCE, 17.63 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.64 + genericLocation = { 3, 0 }), 17.65 + @TADescription(annotation = "TC", type = METHOD_REFERENCE, 17.66 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.67 + genericLocation = { 3, 0 }), 17.68 + @TADescription(annotation = "TD", type = METHOD_REFERENCE, 17.69 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.70 + genericLocation = { 3, 1 }), 17.71 + @TADescription(annotation = "TE", type = METHOD_REFERENCE, 17.72 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.73 + genericLocation = { 3, 1 }) 17.74 + }) 17.75 + public String returnMethodRef2() { 17.76 + return 17.77 + "class Lambda<S, T> {" + 17.78 + " public String getName() { return \"Lambda!\"; }" + 17.79 + "}" + 17.80 + 17.81 + "class Test {" + 17.82 + " java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" + 17.83 + " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::getName;" + 17.84 + " }" + 17.85 + "}"; 17.86 + } 17.87 + 17.88 + @TADescriptions({ 17.89 + @TADescription(annotation = "CTA", type = METHOD_REFERENCE, 17.90 + offset = ReferenceInfoUtil.IGNORE_VALUE), 17.91 + @TADescription(annotation = "CTB", type = METHOD_REFERENCE, 17.92 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.93 + genericLocation = { 3, 0 }), 17.94 + @TADescription(annotation = "CTC", type = METHOD_REFERENCE, 17.95 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.96 + genericLocation = { 3, 1 }) 17.97 + }) 17.98 + public String returnMethodRef3() { 17.99 + return 17.100 + "class Lambda<S, T> {" + 17.101 + " public String getName() { return \"Lambda!\"; }" + 17.102 + "}" + 17.103 + 17.104 + "@Target(ElementType.TYPE_USE)" + 17.105 + "@interface CTA {" + 17.106 + " String value();" + 17.107 + "}" + 17.108 + 17.109 + "@Target(ElementType.TYPE_USE)" + 17.110 + "@interface CTB {" + 17.111 + " int age();" + 17.112 + "}" + 17.113 + 17.114 + "@Target(ElementType.TYPE_USE)" + 17.115 + "@interface CTC {" + 17.116 + " String name();" + 17.117 + "}" + 17.118 + 17.119 + "class Test {" + 17.120 + " java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" + 17.121 + " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::getName;" + 17.122 + " }" + 17.123 + "}"; 17.124 + } 17.125 + 17.126 + 17.127 + @TADescriptions({ 17.128 + @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, 17.129 + offset = ReferenceInfoUtil.IGNORE_VALUE), 17.130 + @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, 17.131 + offset = ReferenceInfoUtil.IGNORE_VALUE) 17.132 + }) 17.133 + public String returnConstructorRef1() { 17.134 + return 17.135 + "class Lambda {" + 17.136 + " Lambda() { }" + 17.137 + "}" + 17.138 + 17.139 + "class Test {" + 17.140 + " Runnable lambda() {" + 17.141 + " return @TA @TB Lambda::new;" + 17.142 + " }" + 17.143 + "}"; 17.144 + } 17.145 + 17.146 + @TADescriptions({ 17.147 + @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, 17.148 + offset = ReferenceInfoUtil.IGNORE_VALUE), 17.149 + @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, 17.150 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.151 + genericLocation = { 3, 0 }), 17.152 + @TADescription(annotation = "TC", type = CONSTRUCTOR_REFERENCE, 17.153 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.154 + genericLocation = { 3, 0 }), 17.155 + @TADescription(annotation = "TD", type = CONSTRUCTOR_REFERENCE, 17.156 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.157 + genericLocation = { 3, 1 }), 17.158 + @TADescription(annotation = "TE", type = CONSTRUCTOR_REFERENCE, 17.159 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.160 + genericLocation = { 3, 1 }) 17.161 + }) 17.162 + public String returnConstructorRef2() { 17.163 + return 17.164 + "class Lambda<S, T> {" + 17.165 + " Lambda() { }" + 17.166 + "}" + 17.167 + 17.168 + "class Test {" + 17.169 + " Runnable lambda() {" + 17.170 + " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::new;" + 17.171 + " }" + 17.172 + "}"; 17.173 + } 17.174 + 17.175 + @TADescriptions({ 17.176 + @TADescription(annotation = "CTA", type = CONSTRUCTOR_REFERENCE, 17.177 + offset = ReferenceInfoUtil.IGNORE_VALUE), 17.178 + @TADescription(annotation = "CTB", type = CONSTRUCTOR_REFERENCE, 17.179 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.180 + genericLocation = { 3, 0 }), 17.181 + @TADescription(annotation = "CTC", type = CONSTRUCTOR_REFERENCE, 17.182 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.183 + genericLocation = { 3, 1 }) 17.184 + }) 17.185 + public String returnConstructorRef3() { 17.186 + return 17.187 + "class Lambda<S, T> {" + 17.188 + " Lambda() { }" + 17.189 + "}" + 17.190 + 17.191 + "@Target(ElementType.TYPE_USE)" + 17.192 + "@interface CTA {" + 17.193 + " String value();" + 17.194 + "}" + 17.195 + 17.196 + "@Target(ElementType.TYPE_USE)" + 17.197 + "@interface CTB {" + 17.198 + " int age();" + 17.199 + "}" + 17.200 + 17.201 + "@Target(ElementType.TYPE_USE)" + 17.202 + "@interface CTC {" + 17.203 + " String name();" + 17.204 + "}" + 17.205 + 17.206 + "class Test {" + 17.207 + " Runnable lambda() {" + 17.208 + " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::new;" + 17.209 + " }" + 17.210 + "}"; 17.211 + } 17.212 + 17.213 + 17.214 + @TADescriptions({ 17.215 + @TADescription(annotation = "TA", type = METHOD_REFERENCE_TYPE_ARGUMENT, 17.216 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.217 + typeIndex = 0), 17.218 + @TADescription(annotation = "TB", type = METHOD_REFERENCE_TYPE_ARGUMENT, 17.219 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.220 + typeIndex = 1) 17.221 + }) 17.222 + public String returnMethodRefTA1() { 17.223 + return 17.224 + "interface Lambda {" + 17.225 + " <S, T> void generic(S p1, T p2);" + 17.226 + "}" + 17.227 + 17.228 + "class LambdaImpl implements Lambda {" + 17.229 + " public <S, T> void generic(S p1, T p2) {}" + 17.230 + "}" + 17.231 + 17.232 + "class Test {" + 17.233 + " Lambda lambda(LambdaImpl r) {" + 17.234 + " return r::<@TA Object, @TB Object>generic;" + 17.235 + " }" + 17.236 + "}"; 17.237 + } 17.238 + 17.239 + @TADescriptions({ 17.240 + @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, 17.241 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.242 + typeIndex = 0), 17.243 + @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, 17.244 + offset = ReferenceInfoUtil.IGNORE_VALUE, 17.245 + typeIndex = 1) 17.246 + }) 17.247 + public String returnConstructorRefTA2() { 17.248 + return 17.249 + "interface Lambda {" + 17.250 + " <S, T> void generic(S p1, T p2);" + 17.251 + "}" + 17.252 + 17.253 + "class LambdaImpl implements Lambda {" + 17.254 + " <S, T> LambdaImpl(S p1, T p2) {}" + 17.255 + " public <S, T> void generic(S p1, T p2) {}" + 17.256 + "}" + 17.257 + 17.258 + "class Test {" + 17.259 + " Lambda lambda() {" + 17.260 + " return LambdaImpl::<@TA Object, @TB Object>new;" + 17.261 + " }" + 17.262 + "}"; 17.263 + } 17.264 + 17.265 +}
18.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodParameters.java Tue Feb 12 19:25:09 2013 +0000 18.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodParameters.java Tue Feb 12 17:15:29 2013 -0800 18.3 @@ -93,6 +93,28 @@ 18.4 } 18.5 18.6 @TADescriptions({ 18.7 + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, 18.8 + genericLocation = { 0, 0 }, paramIndex = 1), 18.9 + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 18.10 + genericLocation = { 0, 0 }, paramIndex = 1) 18.11 + }) 18.12 + public String methodParamAsArray2() { 18.13 + return "void test(Object b, @TA @TB String [] a) { }"; 18.14 + } 18.15 + 18.16 + @TADescriptions({ 18.17 + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, 18.18 + genericLocation = { 0, 0 }, paramIndex = 1), 18.19 + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 18.20 + genericLocation = { 0, 0 }, paramIndex = 1), 18.21 + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 18.22 + genericLocation = { 0, 0 }, paramIndex = 1) 18.23 + }) 18.24 + public String methodParamAsArray3() { 18.25 + return "void test(Object b, @TA @TB @TC String [] a) { }"; 18.26 + } 18.27 + 18.28 + @TADescriptions({ 18.29 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1), 18.30 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 18.31 genericLocation = { 0, 0 }, paramIndex = 1),
19.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java Tue Feb 12 19:25:09 2013 +0000 19.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java Tue Feb 12 17:15:29 2013 -0800 19.3 @@ -31,118 +31,170 @@ 19.4 */ 19.5 public class TypeCasts { 19.6 19.7 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.8 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.9 + typeIndex = 0) 19.10 public String returnObject() { 19.11 return "Object returnObject() { return (@TA String)null; }"; 19.12 } 19.13 19.14 @TADescriptions({ 19.15 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.16 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.17 + typeIndex = 0), 19.18 @TADescription(annotation = "TB", type = CAST, 19.19 - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.20 + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.21 + typeIndex = 0), 19.22 @TADescription(annotation = "TC", type = CAST, 19.23 - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.24 + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.25 + typeIndex = 0) 19.26 }) 19.27 public String returnObjectArray() { 19.28 return "Object returnObjectArray() { return (@TC String @TA [] @TB [])null; }"; 19.29 } 19.30 19.31 @TADescriptions({ 19.32 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.33 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.34 + typeIndex = 0), 19.35 @TADescription(annotation = "TB", type = CAST, 19.36 - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.37 + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.38 + typeIndex = 0) 19.39 }) 19.40 public String returnObjectGeneric() { 19.41 return "Object returnObjectGeneric() { return (@TA List<@TB String>)null; }"; 19.42 } 19.43 19.44 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.45 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.46 + typeIndex = 0) 19.47 public String returnPrim() { 19.48 return "Object returnPrim() { return (@TA int)0; }"; 19.49 } 19.50 19.51 @TADescriptions({ 19.52 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.53 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.54 + typeIndex = 0), 19.55 @TADescription(annotation = "TB", type = CAST, 19.56 - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.57 + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.58 + typeIndex = 0) 19.59 }) 19.60 public String returnPrimArray() { 19.61 return "Object returnPrimArray() { return (@TB int @TA [])null; }"; 19.62 } 19.63 19.64 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.65 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.66 + typeIndex = 0) 19.67 public String initObject() { 19.68 return "void initObject() { Object a = (@TA String)null; }"; 19.69 } 19.70 19.71 @TADescriptions({ 19.72 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.73 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.74 + typeIndex = 0), 19.75 @TADescription(annotation = "TB", type = CAST, 19.76 - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.77 + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.78 + typeIndex = 0) 19.79 }) 19.80 public String initObjectArray() { 19.81 return "void initObjectArray() { Object a = (@TB String @TA [])null; }"; 19.82 } 19.83 19.84 @TADescriptions({ 19.85 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.86 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.87 + typeIndex = 0), 19.88 @TADescription(annotation = "TB", type = CAST, 19.89 - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.90 + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.91 + typeIndex = 0) 19.92 }) 19.93 public String initObjectGeneric() { 19.94 return "void initObjectGeneric() { Object a = (@TA List<@TB String>)null; }"; 19.95 } 19.96 19.97 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.98 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.99 + typeIndex = 0) 19.100 public String initPrim() { 19.101 return "void initPrim() { Object a = (@TA int)0; }"; 19.102 } 19.103 19.104 @TADescriptions({ 19.105 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.106 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.107 + typeIndex = 0), 19.108 @TADescription(annotation = "TB", type = CAST, 19.109 - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.110 + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.111 + typeIndex = 0) 19.112 }) 19.113 public String initPrimArray() { 19.114 return "void initPrimArray() { Object a = (@TB int @TA [])null; }"; 19.115 } 19.116 19.117 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.118 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.119 + typeIndex = 0) 19.120 public String eqtestObject() { 19.121 return "void eqtestObject() { if (null == (@TA String)null); }"; 19.122 } 19.123 19.124 @TADescriptions({ 19.125 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.126 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.127 + typeIndex = 0), 19.128 @TADescription(annotation = "TB", type = CAST, 19.129 - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.130 + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.131 + typeIndex = 0) 19.132 }) 19.133 public String eqtestObjectArray() { 19.134 return "void eqtestObjectArray() { if (null == (@TB String @TA [])null); }"; 19.135 } 19.136 19.137 @TADescriptions({ 19.138 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.139 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.140 + typeIndex = 0), 19.141 @TADescription(annotation = "TB", type = CAST, 19.142 - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.143 + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.144 + typeIndex = 0) 19.145 }) 19.146 public String eqtestObjectGeneric() { 19.147 return "void eqtestObjectGeneric() { if (null == (@TA List<@TB String >)null); }"; 19.148 } 19.149 19.150 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.151 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.152 + typeIndex = 0) 19.153 // compiler optimizes away compile time constants casts 19.154 public String eqtestPrim() { 19.155 return "void eqtestPrim(int a) { if (0 == (@TA int)a); }"; 19.156 } 19.157 19.158 @TADescriptions({ 19.159 - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 19.160 + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.161 + typeIndex = 0), 19.162 @TADescription(annotation = "TB", type = CAST, 19.163 - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 19.164 + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, 19.165 + typeIndex = 0) 19.166 }) 19.167 public String eqtestPrimArray() { 19.168 return "void eqtestPrimArray() { if (null == (@TB int @TA [])null); }"; 19.169 } 19.170 19.171 + @TADescriptions({ 19.172 + @TADescription(annotation = "TA", type = CAST, 19.173 + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0), 19.174 + @TADescription(annotation = "TB", type = CAST, 19.175 + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1), 19.176 + @TADescription(annotation = "TC", type = CAST, 19.177 + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, 19.178 + genericLocation = {3, 0}) 19.179 + }) 19.180 + public String intersection1() { 19.181 + return "void intersection() { Object o = (@TA String & @TB Comparable<@TC String>) null; }"; 19.182 + } 19.183 + 19.184 + @TADescriptions({ 19.185 + @TADescription(annotation = "TA", type = CAST, 19.186 + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0), 19.187 + @TADescription(annotation = "TB", type = CAST, 19.188 + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1), 19.189 + @TADescription(annotation = "TC", type = CAST, 19.190 + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, 19.191 + genericLocation = {3, 0}), 19.192 + @TADescription(annotation = "TD", type = CAST, 19.193 + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 2), 19.194 + }) 19.195 + public String intersection2() { 19.196 + return "void intersection() { Object o = (@TA String & @TB Comparable<@TC String> & @TD CharSequence) null; }"; 19.197 + } 19.198 }