1 /*
  2  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @bug      8308590
 27  * @summary  value classes
 28  * @library  /tools/lib ../../lib
 29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
 30  * @build    toolbox.ToolBox javadoc.tester.*
 31  * @run main TestValueClasses
 32  */
 33 
 34 import java.io.IOException;
 35 import java.nio.file.Path;
 36 
 37 import javadoc.tester.JavadocTester;
 38 import toolbox.ToolBox;
 39 
 40 public class TestValueClasses extends JavadocTester {
 41 
 42     public static void main(String... args) throws Exception {
 43         var tester = new TestValueClasses();
 44         tester.runTests();
 45     }
 46 
 47     private final ToolBox tb = new ToolBox();
 48 
 49     @Test
 50     public void testConcreteValueClass(Path base) throws IOException {
 51         Path src = base.resolve("src");
 52         tb.writeJavaFiles(src,
 53                 "package p; public value class ValueClass {}");
 54 
 55         javadoc("-d", base.resolve("out").toString(),
 56                 "--enable-preview", "-source", String.valueOf(Runtime.version().feature()),
 57                 "-sourcepath", src.toString(),
 58                 "p");
 59         checkExit(Exit.OK);
 60 
 61         checkOutput("p/ValueClass.html", true,
 62                 """
 63                 <div class="type-signature"><span class="modifiers">public value final class </span><span class="element-name type-name-label">ValueClass</span>
 64                 """);
 65     }
 66 
 67     @Test
 68     public void testAbstractValueClass(Path base) throws IOException {
 69         Path src = base.resolve("src");
 70         tb.writeJavaFiles(src,
 71                 "package p; public abstract value class ValueClass {}");
 72 
 73         javadoc("-d", base.resolve("out").toString(),
 74                 "--enable-preview", "-source", String.valueOf(Runtime.version().feature()),
 75                 "-sourcepath", src.toString(),
 76                 "p");
 77         checkExit(Exit.OK);
 78 
 79         checkOutput("p/ValueClass.html", true,
 80                 """
 81                 <div class="type-signature"><span class="modifiers">public abstract value class </span><span class="element-name type-name-label">ValueClass</span>
 82                 """);
 83     }
 84 
 85     @Test
 86     public void testValueRecord(Path base) throws IOException {
 87         Path src = base.resolve("src");
 88         tb.writeJavaFiles(src,
 89                 "package p; public value record ValueRecord() {}");
 90 
 91         javadoc("-d", base.resolve("out").toString(),
 92                 "--enable-preview", "-source", String.valueOf(Runtime.version().feature()),
 93                 "-sourcepath", src.toString(),
 94                 "p");
 95         checkExit(Exit.OK);
 96 
 97         checkOutput("p/ValueRecord.html", true,
 98                 """
 99                 <div class="type-signature"><span class="modifiers">public value record </span><span class="element-name type-name-label">ValueRecord</span>()
100                 """);
101     }
102 }