8312445: Array types in annotation elements show square brackets twice

Reviewed-by: prappo
This commit is contained in:
Hannes Wallnöfer 2023-07-26 13:04:39 +00:00
parent c22cadf32f
commit 02a04731b1
4 changed files with 34 additions and 22 deletions

View File

@ -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<Content, Void>() {
@Override
public Content visitType(TypeMirror t, Void p) {
public Content visitType(TypeMirror type, Void p) {
return new SimpleTypeVisitor9<Content, Void>() {
@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

View File

@ -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 {
<a href="A.html#s()">s</a>="sigh",""",
// Class
"""
<a href="A.html#c()">c</a>=<a href="../pkg2/Foo.html" title="class in pkg2">Foo.class</a>,""",
<a href="A.html#c()">c</a>=<a href="../pkg2/Foo.html" title="class in pkg2">Foo</a>.class,""",
// Bounded Class
"""
<a href="A.html#w()">w</a>=<a href="../pkg/TypeParameterSubClass.html" title="cl\
ass in pkg">TypeParameterSubClass.class</a>,""",
ass in pkg">TypeParameterSubClass</a>.class,""",
// Enum
"""
<a href="A.html#e()">e</a>=<a href="../pkg/Coin.html#Penny">Penny</a>,""",
@ -694,10 +694,17 @@ public class TestNewLanguageFeatures extends JavadocTester {
<a href="A.html#sa()">sa</a>={"up","down"},""",
// Primitive
"""
<a href="A.html#primitiveClassTest()">primitiveClassTest</a>=boolean.class,""");
<a href="A.html#primitiveClassTest()">primitiveClassTest</a>=boolean.class,""",
// Arrays
"""
<a href="A.html#arrayClassTest()">arrayClassTest</a>=java.lang.String[][].class,""",
"""
<a href="A.html#arrayPrimitiveTest()">arrayPrimitiveTest</a>=boolean[].class,""",
"""
<a href="A.html#classArrayTest()">classArrayTest</a>={<a href="../pkg/TypeParame\
terSubClass.html" title="class in pkg">TypeParameterSubClass</a>[][].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,
"""
<div class="type-signature"><span class="annotations"><a href="A.html" title="an\

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,12 +32,13 @@ import java.lang.annotation.*;
double d();
boolean b();
String s();
Class c();
Class<?> c();
Class<? extends TypeParameterSuperClass> w();
Coin[] e();
AnnotationType a();
String[] sa();
Class primitiveClassTest();
Class arrayClassTest();
Class arrayPrimitiveTest();
Class<?> primitiveClassTest();
Class<?> arrayClassTest();
Class<?> arrayPrimitiveTest();
Class<?>[] classArrayTest();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,8 @@ import pkg2.*;
a = @AnnotationType(optional="foo",required=1994),
sa = {"up", "down"},
primitiveClassTest = boolean.class,
arrayClassTest = String[].class,
arrayPrimitiveTest = boolean[].class)
arrayClassTest = String[][].class,
arrayPrimitiveTest = boolean[].class,
classArrayTest = {TypeParameterSubClass[][].class, String.class, long[][][].class})
public interface B {
}