From 0b704a2279ddc5f2c00e64099310554b8c8529b8 Mon Sep 17 00:00:00 2001 From: Nizar Benalla Date: Wed, 27 Nov 2024 15:33:54 +0000 Subject: [PATCH] 8343239: Javadoc marks non-preview type as preview if it's the subtype of a preview type Reviewed-by: liach, hannesw --- .../internal/doclets/toolkit/util/Utils.java | 1 - .../doclet/testPreview/TestPreview.java | 64 ++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java index c29feec1712..0cdf04fb779 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java @@ -2485,7 +2485,6 @@ public class Utils { usedInDeclaration.addAll(types2Classes(tpe.getBounds())); } usedInDeclaration.addAll(types2Classes(List.of(te.getSuperclass()))); - usedInDeclaration.addAll(types2Classes(te.getInterfaces())); usedInDeclaration.addAll(types2Classes(te.getPermittedSubclasses())); usedInDeclaration.addAll(types2Classes(te.getRecordComponents().stream().map(Element::asType).toList())); //TODO: annotations on record components??? } diff --git a/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java b/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java index 7022b02ee88..df0e0910151 100644 --- a/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java +++ b/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java @@ -24,20 +24,24 @@ /* * @test * @bug 8250768 8261976 8277300 8282452 8287597 8325325 8325874 8297879 - * 8331947 8281533 8318416 + * 8331947 8281533 8343239 8318416 * @summary test generated docs for items declared using preview - * @library ../../lib + * @library /tools/lib ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool * jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.resources:+open - * @build javadoc.tester.* + * @build toolbox.ToolBox javadoc.tester.* * @run main TestPreview */ +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; + import javadoc.tester.JavadocTester; +import toolbox.ToolBox; public class TestPreview extends JavadocTester { + ToolBox tb = new ToolBox(); public static void main(String... args) throws Exception { var tester = new TestPreview(); @@ -185,6 +189,60 @@ public class TestPreview extends JavadocTester { checkOutput("preview-list.html", false, "supportMethod"); } + // 8343239 pre-existing permanent API that is later retrofitted + // to extend a @PreviewFeature interface should not be flagged as a preview feature + @Test + public void nonPreviewExtendsPreview(Path base) throws IOException { + + Path src = base.resolve("src"); + tb.writeJavaFiles(src, """ + package p; + import jdk.internal.javac.PreviewFeature; + + /** + * Preview feature + */ + @PreviewFeature(feature= PreviewFeature.Feature.TEST) + public interface CoreInterface { + } + """, """ + package p; + + /** + * Non preview feature + */ + public interface NonPreviewExtendsPreview extends CoreInterface { + default int getNumber() { + return 0; + } + } + """); + javadoc("-d", "out-non-preview-extends-preview", + "--add-exports", "java.base/jdk.internal.javac=ALL-UNNAMED", + "--source-path", + src.toString(), + "p"); + checkExit(Exit.OK); + checkOutput("p/NonPreviewExtendsPreview.html", false, + """ + NonPreviewExtendsPreview relies on preview features of the Java platform: + """, + """ + NonPreviewExtendsPreview refers to one or more preview APIs: + """); + checkOutput("p/CoreInterface.html", true, + """ +
+
public interface CoreInterface
+
CoreInterface is a preview API of the Java platform. +
Programs can only use CoreInterface when preview features are enabled.
+
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
+
+
Preview feature
+
+ """); + } + @Test public void test8277300() { javadoc("-d", "out-8277300",