diff -r b0fcf59be391 src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Fri Jul 20 14:48:41 2018 -0700 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Mon Jul 30 17:39:20 2018 +0200 @@ -424,7 +424,7 @@ } if (type.hasTag(TypeTag.ARRAY)) - return rewriteArrayType((ArrayType)type, annotations, pos); + return rewriteArrayType(typetree, (ArrayType)type, annotations, onlyTypeAnnotations, pos); if (type.hasTag(TypeTag.TYPEVAR)) { return type.annotatedType(onlyTypeAnnotations); @@ -536,57 +536,33 @@ * * SIDE EFFECT: Update position for the annotations to be {@code pos}. */ - private Type rewriteArrayType(ArrayType type, List annotations, TypeAnnotationPosition pos) { - ArrayType tomodify = new ArrayType(type); - ArrayType res = tomodify; - - List loc = List.nil(); - - // peel one and update loc - Type tmpType = type.elemtype; - loc = loc.prepend(TypePathEntry.ARRAY); - - while (tmpType.hasTag(TypeTag.ARRAY)) { - ArrayType arr = (ArrayType)tmpType; - - // Update last type with new element type - ArrayType tmp = new ArrayType(arr); - tomodify.elemtype = tmp; - tomodify = tmp; + private Type rewriteArrayType(JCTree typetree, ArrayType type, List annotations, + List onlyTypeAnnotations, TypeAnnotationPosition pos) { + ArrayType res = new ArrayType(type); - tmpType = arr.elemtype; - loc = loc.prepend(TypePathEntry.ARRAY); - } - - // Fix innermost element type - Type elemType; - if (tmpType.getMetadata() != null) { - List tcs; - if (tmpType.getAnnotationMirrors().isEmpty()) { - tcs = annotations; - } else { - // Special case, lets prepend - tcs = annotations.appendList(tmpType.getAnnotationMirrors()); - } - elemType = tmpType.cloneWithMetadata(tmpType - .getMetadata() - .without(Kind.ANNOTATIONS) - .combine(new TypeMetadata.Annotations(tcs))); - } else { - elemType = tmpType.cloneWithMetadata(new TypeMetadata(new TypeMetadata.Annotations(annotations))); - } - tomodify.elemtype = elemType; - - // Update positions + // Update first position for (TypeCompound tc : annotations) { if (tc.position == null) tc.position = pos; - tc.position.location = loc; + tc.position.location = tc.position.location.prepend(TypePathEntry.ARRAY); + break; } + res.elemtype = typeWithAnnotations(arrayTypeTree(typetree).elemtype, type.elemtype, annotations, onlyTypeAnnotations, pos); return res; } + private JCArrayTypeTree arrayTypeTree(JCTree typetree) { + if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) { + return (JCArrayTypeTree) typetree; + } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) { + return (JCArrayTypeTree) ((JCAnnotatedType) typetree).underlyingType; + } else { + Assert.error("Could not determine array type from type tree: " + typetree); + return null; + } + } + /** Return a copy of the first type that only differs by * inserting the annotations to the left-most/inner-most type * or the type given by stopAt. diff -r b0fcf59be391 test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java --- a/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java Fri Jul 20 14:48:41 2018 -0700 +++ b/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java Mon Jul 30 17:39:20 2018 +0200 @@ -235,8 +235,10 @@ || compact.contains(" class")) && !compact.contains("interface") && !compact.contains("enum"); - if (isSnippet) + if (isSnippet) { sb.append("class %TEST_CLASS_NAME% {\n"); + sb.append("class Nested {}\n"); + } sb.append(compact); sb.append("\n"); diff -r b0fcf59be391 test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java --- a/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java Fri Jul 20 14:48:41 2018 -0700 +++ b/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java Mon Jul 30 17:39:20 2018 +0200 @@ -67,6 +67,26 @@ @TADescription(annotation = "TB", type = FIELD, genericLocation = { 0, 0 }) @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 0, 0, 0, 0, 1, 0}) + public String fieldAsNestedArray1() { + return "@TC Nested @TA [] @TB [] test;"; + } + + @TADescription(annotation = "TA", type = FIELD) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 0, 0 }) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 0, 0, 0, 0 }) + public String fieldAsNestedArray2() { + return "@TD %TEST_CLASS_NAME%. @TC Nested @TA [] @TB [] test;"; + } + + @TADescription(annotation = "TA", type = FIELD) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 0, 0 }) + @TADescription(annotation = "TC", type = FIELD, genericLocation = { 0, 0, 0, 0 }) public String fieldAsArrayOld() { return "@TC String test @TA [] @TB [];"; diff -r b0fcf59be391 test/langtools/tools/javac/warnings/6747671/T6747671.out --- a/test/langtools/tools/javac/warnings/6747671/T6747671.out Fri Jul 20 14:48:41 2018 -0700 +++ b/test/langtools/tools/javac/warnings/6747671/T6747671.out Mon Jul 30 17:39:20 2018 +0200 @@ -7,6 +7,6 @@ T6747671.java:32:9: compiler.warn.raw.class.use: T6747671.A, T6747671.A T6747671.java:32:20: compiler.warn.raw.class.use: T6747671.A, T6747671.A T6747671.java:33:16: compiler.warn.raw.class.use: T6747671.A.Z, T6747671.A.Z -T6747671.java:36:9: compiler.warn.raw.class.use: T6747671.B, T6747671.B +T6747671.java:36:9: compiler.warn.raw.class.use: @T6747671.TA T6747671.B, T6747671.B T6747671.java:36:27: compiler.warn.raw.class.use: T6747671.B, T6747671.B 11 warnings