|
1 /* |
|
2 * Copyright (c) 2018, 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 8207214 |
|
27 * @summary Test serialized forms, with at-see to other members |
|
28 * @library /tools/lib ../lib |
|
29 * @modules jdk.javadoc/jdk.javadoc.internal.tool |
|
30 * @build JavadocTester toolbox.ToolBox |
|
31 * @run main TestSerializedFormWithSee |
|
32 */ |
|
33 |
|
34 import java.io.IOException; |
|
35 import java.nio.file.Path; |
|
36 import java.nio.file.Paths; |
|
37 |
|
38 import toolbox.ToolBox; |
|
39 |
|
40 /** |
|
41 * Test the links generated in source files with combinations |
|
42 * of modules, Serializable, and @see for public and private methods. |
|
43 * |
|
44 * In the various test cases, in addition to the explicit call |
|
45 * to {@code checkExit}, the primary check is the implicit call |
|
46 * to {@code checkLinks}, to verify that there are no broken |
|
47 * links in the generated files. |
|
48 */ |
|
49 public class TestSerializedFormWithSee extends JavadocTester { |
|
50 |
|
51 public static void main(String... args) throws Exception { |
|
52 TestSerializedFormWithSee tester = new TestSerializedFormWithSee(); |
|
53 tester.runTests(m -> new Object[] { Paths.get(m.getName()) }); |
|
54 } |
|
55 |
|
56 private final ToolBox tb; |
|
57 |
|
58 TestSerializedFormWithSee() { |
|
59 tb = new ToolBox(); |
|
60 } |
|
61 |
|
62 @Test |
|
63 public void test_noModule_notSerializable(Path base) throws IOException { |
|
64 Path srcDir = generateSource(base, false, false); |
|
65 |
|
66 Path outDir = base.resolve("out"); |
|
67 javadoc("-d", outDir.toString(), |
|
68 "-sourcepath", srcDir.toString(), |
|
69 "p"); |
|
70 checkExit(Exit.OK); |
|
71 } |
|
72 |
|
73 @Test |
|
74 public void test_noModule_serializable(Path base) throws IOException { |
|
75 Path srcDir = generateSource(base, false, true); |
|
76 |
|
77 Path outDir = base.resolve("out"); |
|
78 javadoc("-d", outDir.toString(), |
|
79 "-sourcepath", srcDir.toString(), |
|
80 "p"); |
|
81 checkExit(Exit.OK); |
|
82 } |
|
83 |
|
84 @Test |
|
85 public void test_module_notSerializable(Path base) throws IOException { |
|
86 Path srcDir = generateSource(base, true, false); |
|
87 |
|
88 Path outDir = base.resolve("out"); |
|
89 javadoc("-d", outDir.toString(), |
|
90 "-sourcepath", srcDir.toString(), |
|
91 "m/p"); |
|
92 checkExit(Exit.OK); |
|
93 } |
|
94 |
|
95 @Test |
|
96 public void test_module_serializable(Path base) throws IOException { |
|
97 Path srcDir = generateSource(base, true, true); |
|
98 |
|
99 Path outDir = base.resolve("out"); |
|
100 javadoc("-d", outDir.toString(), |
|
101 "-sourcepath", srcDir.toString(), |
|
102 "m/p"); |
|
103 checkExit(Exit.OK); |
|
104 } |
|
105 |
|
106 Path generateSource(Path base, boolean module, boolean serializable) throws IOException { |
|
107 Path dir = base.resolve("src"); |
|
108 if (module) { |
|
109 tb.writeJavaFiles(dir, "module m { }"); |
|
110 } |
|
111 StringBuilder sb = new StringBuilder(); |
|
112 sb.append("package p;\n"); |
|
113 sb.append("public class C " + (serializable ? "implements java.io.Serializable " : "") + "{\n"); |
|
114 for (String access : new String[] { "public", "private" }) { |
|
115 sb.append(" /**\n"); |
|
116 sb.append(" * This is a " + access + " " + (serializable ? "serializable " : "") + "field.\n"); |
|
117 sb.append(" * More description.\n"); |
|
118 sb.append(" * " + (serializable ? "@serial This is the serial description." : "") + "\n"); |
|
119 sb.append(" * @see #publicMethod()\n"); |
|
120 sb.append(" * @see #privateMethod()\n"); |
|
121 sb.append(" */\n"); |
|
122 sb.append(" " + access + " int " + access + "Field;\n"); |
|
123 } |
|
124 for (String access : new String[] { "public", "private" }) { |
|
125 sb.append(" /**\n"); |
|
126 sb.append(" * This is a " + access + " method.\n"); |
|
127 sb.append(" * More description.\n"); |
|
128 sb.append(" * @return zero.\n"); |
|
129 sb.append(" */\n"); |
|
130 sb.append(" " + access + " int " + access + "Method() { return 0; }\n"); |
|
131 } |
|
132 sb.append(" }\n"); |
|
133 tb.writeJavaFiles(dir, sb.toString()); |
|
134 return dir; |
|
135 } |
|
136 } |