From 02a04731b1b2e68bf1a79f50d036bedd032128f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Wed, 26 Jul 2023 13:04:39 +0000 Subject: [PATCH] 8312445: Array types in annotation elements show square brackets twice Reviewed-by: prappo --- .../formats/html/HtmlDocletWriter.java | 19 +++++++++++-------- .../TestNewLanguageFeatures.java | 19 +++++++++++++------ .../testNewLanguageFeatures/pkg1/A.java | 11 ++++++----- .../testNewLanguageFeatures/pkg1/B.java | 7 ++++--- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java index 8d2a8a02f7d..b74d9663b1f 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java @@ -52,6 +52,7 @@ import javax.lang.model.element.PackageElement; import javax.lang.model.element.QualifiedNameable; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; +import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.SimpleAnnotationValueVisitor9; @@ -90,6 +91,7 @@ import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; import jdk.javadoc.internal.doclets.formats.html.markup.Script; import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; +import jdk.javadoc.internal.doclets.formats.html.markup.TextBuilder; import jdk.javadoc.internal.doclets.formats.html.taglets.Taglet; import jdk.javadoc.internal.doclets.formats.html.taglets.TagletWriter; import jdk.javadoc.internal.doclets.toolkit.Messages; @@ -1868,23 +1870,24 @@ public class HtmlDocletWriter { return new SimpleAnnotationValueVisitor9() { @Override - public Content visitType(TypeMirror t, Void p) { + public Content visitType(TypeMirror type, Void p) { return new SimpleTypeVisitor9() { @Override public Content visitDeclared(DeclaredType t, Void p) { HtmlLinkInfo linkInfo = new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.PLAIN, t); - String name = utils.isIncluded(t.asElement()) - ? t.asElement().getSimpleName().toString() - : utils.getFullyQualifiedName(t.asElement()); - linkInfo.label(name + utils.getDimension(t) + ".class"); return getLink(linkInfo); } @Override - protected Content defaultAction(TypeMirror e, Void p) { - return Text.of(t + utils.getDimension(t) + ".class"); + public Content visitArray(ArrayType t, Void p) { + // render declared base component type as link + return visit(t.getComponentType()).add("[]"); } - }.visit(t); + @Override + protected Content defaultAction(TypeMirror t, Void p) { + return new TextBuilder(t.toString()); + } + }.visit(type).add(".class"); } @Override diff --git a/test/langtools/jdk/javadoc/doclet/testNewLanguageFeatures/TestNewLanguageFeatures.java b/test/langtools/jdk/javadoc/doclet/testNewLanguageFeatures/TestNewLanguageFeatures.java index 0778a22152e..a54fbbcff75 100644 --- a/test/langtools/jdk/javadoc/doclet/testNewLanguageFeatures/TestNewLanguageFeatures.java +++ b/test/langtools/jdk/javadoc/doclet/testNewLanguageFeatures/TestNewLanguageFeatures.java @@ -24,7 +24,7 @@ /* * @test * @bug 4789689 4905985 4927164 4827184 4993906 5004549 7025314 7010344 8025633 8026567 8162363 - * 8175200 8186332 8182765 8196202 8187288 8173730 8215307 + * 8175200 8186332 8182765 8196202 8187288 8173730 8215307 8312445 * @summary Run Javadoc on a set of source files that demonstrate new * language features. Check the output to ensure that the new * language features are properly documented. @@ -675,11 +675,11 @@ public class TestNewLanguageFeatures extends JavadocTester { s="sigh",""", // Class """ - c=Foo.class,""", + c=Foo.class,""", // Bounded Class """ w=TypeParameterSubClass.class,""", + ass in pkg">TypeParameterSubClass.class,""", // Enum """ e=Penny,""", @@ -694,10 +694,17 @@ public class TestNewLanguageFeatures extends JavadocTester { sa={"up","down"},""", // Primitive """ - primitiveClassTest=boolean.class,"""); + primitiveClassTest=boolean.class,""", + // Arrays + """ + arrayClassTest=java.lang.String[][].class,""", + """ + arrayPrimitiveTest=boolean[].class,""", + """ + classArrayTest={TypeParameterSubClass[][].class,java.\ + lang.String.class,long[][][].class})"""); - // XXX: Add array test case after this if fixed: - //5020899: Incorrect internal representation of class-valued annotation elements checkOutput("pkg1/B.html", true, """