1.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Mon Feb 04 18:08:53 2013 -0500 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Sun Feb 17 16:44:55 2013 -0500 1.3 @@ -217,6 +217,9 @@ 1.4 // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore 1.5 // need to set its position explicitly. 1.6 // The method returns a copy of type that contains these annotations. 1.7 + // 1.8 + // As a side effect the method sets the type annotation position of "annotations". 1.9 + // Note that it is assumed that all annotations share the same position. 1.10 private static Type typeWithAnnotations(final JCTree typetree, final Type type, 1.11 final List<Attribute.TypeCompound> annotations, Log log) { 1.12 // System.out.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s)%n", 1.13 @@ -267,7 +270,9 @@ 1.14 } 1.15 Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, log); 1.16 tomodify.elemtype = arelemType; 1.17 - for (Attribute.TypeCompound a : annotations) { 1.18 + { 1.19 + // All annotations share the same position; modify the first one. 1.20 + Attribute.TypeCompound a = annotations.get(0); 1.21 TypeAnnotationPosition p = a.position; 1.22 p.location = p.location.prependList(depth.toList()); 1.23 } 1.24 @@ -345,10 +350,10 @@ 1.25 if (depth.nonEmpty()) { 1.26 // Only need to change the annotation positions 1.27 // if they are on an enclosed type. 1.28 - for (Attribute.TypeCompound a : annotations) { 1.29 - TypeAnnotationPosition p = a.position; 1.30 - p.location = p.location.appendList(depth.toList()); 1.31 - } 1.32 + // All annotations share the same position; modify the first one. 1.33 + Attribute.TypeCompound a = annotations.get(0); 1.34 + TypeAnnotationPosition p = a.position; 1.35 + p.location = p.location.appendList(depth.toList()); 1.36 } 1.37 1.38 Type ret = typeWithAnnotations(type, enclTy, annotations); 1.39 @@ -463,8 +468,7 @@ 1.40 1.41 @Override 1.42 public Type visitType(Type t, List<TypeCompound> s) { 1.43 - // Error? 1.44 - return t; 1.45 + return new AnnotatedType(s, t); 1.46 } 1.47 }; 1.48 1.49 @@ -575,6 +579,10 @@ 1.50 System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind()); 1.51 System.out.println(" Framing tree: " + frame + " kind: " + frame.getKind()); 1.52 */ 1.53 + 1.54 + // Note that p.offset is set in 1.55 + // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int) 1.56 + 1.57 switch (frame.getKind()) { 1.58 case TYPE_CAST: 1.59 p.type = TargetType.CAST; 1.60 @@ -659,6 +667,45 @@ 1.61 return; 1.62 } 1.63 1.64 + case MEMBER_REFERENCE: { 1.65 + JCMemberReference mrframe = (JCMemberReference) frame; 1.66 + 1.67 + if (mrframe.expr == tree) { 1.68 + switch (mrframe.mode) { 1.69 + case INVOKE: 1.70 + p.type = TargetType.METHOD_REFERENCE; 1.71 + break; 1.72 + case NEW: 1.73 + p.type = TargetType.CONSTRUCTOR_REFERENCE; 1.74 + break; 1.75 + default: 1.76 + Assert.error("Unknown method reference mode " + mrframe.mode + 1.77 + " for tree " + tree + " within frame " + frame); 1.78 + } 1.79 + p.pos = frame.pos; 1.80 + } else if (mrframe.typeargs != null && 1.81 + mrframe.typeargs.contains(tree)) { 1.82 + int arg = mrframe.typeargs.indexOf(tree); 1.83 + p.type_index = arg; 1.84 + switch (mrframe.mode) { 1.85 + case INVOKE: 1.86 + p.type = TargetType.METHOD_REFERENCE_TYPE_ARGUMENT; 1.87 + break; 1.88 + case NEW: 1.89 + p.type = TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT; 1.90 + break; 1.91 + default: 1.92 + Assert.error("Unknown method reference mode " + mrframe.mode + 1.93 + " for tree " + tree + " within frame " + frame); 1.94 + } 1.95 + p.pos = frame.pos; 1.96 + } else { 1.97 + Assert.error("Could not determine type argument position of tree " + tree + 1.98 + " within frame " + frame); 1.99 + } 1.100 + return; 1.101 + } 1.102 + 1.103 case ARRAY_TYPE: { 1.104 ListBuffer<TypePathEntry> index = ListBuffer.lb(); 1.105 index = index.append(TypePathEntry.ARRAY); 1.106 @@ -766,6 +813,14 @@ 1.107 return; 1.108 } 1.109 1.110 + case INTERSECTION_TYPE: { 1.111 + JCTypeIntersection isect = (JCTypeIntersection)frame; 1.112 + p.type_index = isect.bounds.indexOf(tree); 1.113 + List<JCTree> newPath = path.tail; 1.114 + resolveFrame(newPath.head, newPath.tail.head, newPath, p); 1.115 + return; 1.116 + } 1.117 + 1.118 case METHOD_INVOCATION: { 1.119 JCMethodInvocation invocation = (JCMethodInvocation)frame; 1.120 if (!invocation.typeargs.contains(tree)) { 1.121 @@ -911,6 +966,8 @@ 1.122 public void visitVarDef(final JCVariableDecl tree) { 1.123 if (tree.sym == null) { 1.124 // Something is wrong already. Quietly ignore. 1.125 + } else if (tree.sym.getKind() == ElementKind.PARAMETER) { 1.126 + // Parameters are handled in visitMethodDef above. 1.127 } else if (tree.sym.getKind() == ElementKind.FIELD) { 1.128 if (sigOnly) { 1.129 TypeAnnotationPosition pos = new TypeAnnotationPosition(); 1.130 @@ -924,7 +981,6 @@ 1.131 pos.pos = tree.pos; 1.132 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); 1.133 } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { 1.134 - // System.out.println("Found exception param: " + tree); 1.135 TypeAnnotationPosition pos = new TypeAnnotationPosition(); 1.136 pos.type = TargetType.EXCEPTION_PARAMETER; 1.137 pos.pos = tree.pos; 1.138 @@ -934,9 +990,11 @@ 1.139 pos.type = TargetType.RESOURCE_VARIABLE; 1.140 pos.pos = tree.pos; 1.141 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); 1.142 + } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) { 1.143 + // No type annotations can occur here. 1.144 } else { 1.145 // There is nothing else in a variable declaration that needs separation. 1.146 - // System.out.println("We found a: " + tree); 1.147 + Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind()); 1.148 } 1.149 1.150 push(tree);