diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java index af529ccc24a..7c2171330e5 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java @@ -86,13 +86,8 @@ public class ClassBuilder extends AbstractBuilder { this.writer = writer; this.utils = configuration.utils; switch (typeElement.getKind()) { - case ENUM: - setEnumDocumentation(typeElement); - break; - - case RECORD: - setRecordDocumentation(typeElement); - break; + case ENUM -> setEnumDocumentation(typeElement); + case RECORD -> setRecordDocumentation(typeElement); } } @@ -119,27 +114,15 @@ public class ClassBuilder extends AbstractBuilder { * @throws DocletException if there is a problem while building the documentation */ protected void buildClassDoc() throws DocletException { - String key; - switch (typeElement.getKind()) { - case INTERFACE: - key = "doclet.Interface"; - break; - case ENUM: - key = "doclet.Enum"; - break; - case RECORD: - key = "doclet.RecordClass"; - break; - case ANNOTATION_TYPE: - key = "doclet.AnnotationType"; - break; - case CLASS: - key = "doclet.Class"; - break; - default: - throw new IllegalStateException(typeElement.getKind() + " " + typeElement); - } - Content contentTree = writer.getHeader(resources.getText(key) + " " + String key = switch (typeElement.getKind()) { + case INTERFACE -> "doclet.Interface"; + case ENUM -> "doclet.Enum"; + case RECORD -> "doclet.RecordClass"; + case ANNOTATION_TYPE -> "doclet.AnnotationType"; + case CLASS -> "doclet.Class"; + default -> throw new IllegalStateException(typeElement.getKind() + " " + typeElement); + }; + Content contentTree = writer.getHeader(resources.getText(key) + " " + utils.getSimpleName(typeElement)); Content classContentTree = writer.getClassContentHeader(); @@ -467,7 +450,10 @@ public class ClassBuilder extends AbstractBuilder { } } - for (VariableElement ve : utils.getFields(elem)) { + var fields = utils.isSerializable(elem) + ? utils.getFieldsUnfiltered(elem) + : utils.getFields(elem); + for (VariableElement ve : fields) { // The fields for the record component cannot be declared by the // user and so cannot have any pre-existing comment. Name name = ve.getSimpleName(); diff --git a/test/langtools/jdk/javadoc/doclet/testRecordTypes/TestRecordTypes.java b/test/langtools/jdk/javadoc/doclet/testRecordTypes/TestRecordTypes.java index 01f061ae23a..beaae848b96 100644 --- a/test/langtools/jdk/javadoc/doclet/testRecordTypes/TestRecordTypes.java +++ b/test/langtools/jdk/javadoc/doclet/testRecordTypes/TestRecordTypes.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8225055 8239804 8246774 8258338 8261976 + * @bug 8225055 8239804 8246774 8258338 8261976 8275199 * @summary Record types * @library /tools/lib ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool @@ -51,13 +51,11 @@ public class TestRecordTypes extends JavadocTester { private final ToolBox tb = new ToolBox(); - // The following constants are set up for use with -linkoffline - // (but note: JDK 11 does not include java.lang.Record, so expect - // some 404 broken links until we can update this to a stable version.) + // The following constants are set up for use with -linkoffline. private static final String externalDocs = - "https://docs.oracle.com/en/java/javase/11/docs/api"; + "https://docs.oracle.com/en/java/javase/17/docs/api"; private static final String localDocs = - Path.of(testSrc).resolve("jdk11").toUri().toString(); + Path.of(testSrc).resolve("jdk17").toUri().toString(); @Test public void testRecordKeywordUnnamedPackage(Path base) throws IOException { @@ -391,17 +389,17 @@ public class TestRecordTypes extends JavadocTester { } @Test - public void testExamples(Path base) throws IOException { + public void testExamples(Path base) { javadoc("-d", base.resolve("out-no-link").toString(), "-quiet", "-noindex", - "-sourcepath", testSrc.toString(), + "-sourcepath", testSrc, "-linksource", "examples"); checkExit(Exit.OK); javadoc("-d", base.resolve("out-with-link").toString(), "-quiet", "-noindex", - "-sourcepath", testSrc.toString(), + "-sourcepath", testSrc, "-linksource", "-linkoffline", externalDocs, localDocs, "examples"); @@ -560,4 +558,51 @@ public class TestRecordTypes extends JavadocTester {
"""); } + + @Test + public void testSerializableType(Path base) throws IOException { + Path src = base.resolve("src"); + tb.writeJavaFiles(src, + """ + /** + * A point, + * @param x the x coord + * @param y the y coord + */ + public record Point(int x, int y) implements java.io.Serializable { }"""); + + javadoc("-d", base.resolve("out").toString(), + "-quiet", "-noindex", "--no-platform-links", + src.resolve("Point.java").toString()); + checkExit(Exit.OK); + + checkOutput(Output.OUT, false, + "warning: no comment"); + + checkOutput("serialized-form.html", true, + """ +