1/*
2 * Copyright (c) 2013, 2015, 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      8005091 8009686 8025633 8026567
27 * @summary  Make sure that type annotations are displayed correctly
28 * @author   Bhavesh Patel
29 * @library  ../lib
30 * @modules jdk.javadoc
31 * @build    JavadocTester
32 * @run main TestTypeAnnotations
33 */
34
35public class TestTypeAnnotations extends JavadocTester {
36
37    public static void main(String... args) throws Exception {
38        TestTypeAnnotations tester = new TestTypeAnnotations();
39        tester.runTests();
40    }
41
42    @Test
43    void test() {
44        javadoc("-d", "out",
45                "-sourcepath", testSrc,
46                "-private",
47                "typeannos");
48        checkExit(Exit.OK);
49
50        // Test for type annotations on Class Extends (ClassExtends.java).
51        checkOutput("typeannos/MyClass.html", true,
52                "extends <a href=\"../typeannos/ClassExtA.html\" title=\"annotation "
53                + "in typeannos\">@ClassExtA</a> <a href=\"../typeannos/ParameterizedClass.html\" "
54                + "title=\"class in typeannos\">ParameterizedClass</a>&lt;<a href=\""
55                + "../typeannos/ClassExtB.html\" title=\"annotation in typeannos\">"
56                + "@ClassExtB</a> java.lang.String&gt;",
57
58                "implements <a href=\"../typeannos/ClassExtB.html\" title=\""
59                + "annotation in typeannos\">@ClassExtB</a> java.lang.CharSequence, "
60                + "<a href=\"../typeannos/ClassExtA.html\" title=\"annotation in "
61                + "typeannos\">@ClassExtA</a> <a href=\"../typeannos/ParameterizedInterface.html\" "
62                + "title=\"interface in typeannos\">ParameterizedInterface</a>&lt;"
63                + "<a href=\"../typeannos/ClassExtB.html\" title=\"annotation in "
64                + "typeannos\">@ClassExtB</a> java.lang.String&gt;</pre>");
65
66        checkOutput("typeannos/MyInterface.html", true,
67                "extends <a href=\"../typeannos/ClassExtA.html\" title=\"annotation "
68                + "in typeannos\">@ClassExtA</a> <a href=\"../typeannos/"
69                + "ParameterizedInterface.html\" title=\"interface in typeannos\">"
70                + "ParameterizedInterface</a>&lt;<a href=\"../typeannos/ClassExtA.html\" "
71                + "title=\"annotation in typeannos\">@ClassExtA</a> java.lang.String&gt;, "
72                + "<a href=\"../typeannos/ClassExtB.html\" title=\"annotation in "
73                + "typeannos\">@ClassExtB</a> java.lang.CharSequence</pre>");
74
75        // Test for type annotations on Class Parameters (ClassParameters.java).
76        checkOutput("typeannos/ExtendsBound.html", true,
77                "class <span class=\"typeNameLabel\">ExtendsBound&lt;K extends <a "
78                + "href=\"../typeannos/ClassParamA.html\" title=\"annotation in "
79                + "typeannos\">@ClassParamA</a> java.lang.String&gt;</span>");
80
81        checkOutput("typeannos/ExtendsGeneric.html", true,
82                "<pre>class <span class=\"typeNameLabel\">ExtendsGeneric&lt;K extends "
83                + "<a href=\"../typeannos/ClassParamA.html\" title=\"annotation in "
84                + "typeannos\">@ClassParamA</a> <a href=\"../typeannos/Unannotated.html\" "
85                + "title=\"class in typeannos\">Unannotated</a>&lt;<a href=\""
86                + "../typeannos/ClassParamB.html\" title=\"annotation in typeannos\">"
87                + "@ClassParamB</a> java.lang.String&gt;&gt;</span>");
88
89        checkOutput("typeannos/TwoBounds.html", true,
90                "<pre>class <span class=\"typeNameLabel\">TwoBounds&lt;K extends <a href=\""
91                + "../typeannos/ClassParamA.html\" title=\"annotation in typeannos\">"
92                + "@ClassParamA</a> java.lang.String,V extends <a href=\"../typeannos/"
93                + "ClassParamB.html\" title=\"annotation in typeannos\">@ClassParamB"
94                + "</a> java.lang.String&gt;</span>");
95
96        checkOutput("typeannos/Complex1.html", true,
97                "class <span class=\"typeNameLabel\">Complex1&lt;K extends <a href=\"../"
98                + "typeannos/ClassParamA.html\" title=\"annotation in typeannos\">"
99                + "@ClassParamA</a> java.lang.String &amp; java.lang.Runnable&gt;</span>");
100
101        checkOutput("typeannos/Complex2.html", true,
102                "class <span class=\"typeNameLabel\">Complex2&lt;K extends java.lang."
103                + "String &amp; <a href=\"../typeannos/ClassParamB.html\" title=\""
104                + "annotation in typeannos\">@ClassParamB</a> java.lang.Runnable&gt;</span>");
105
106        checkOutput("typeannos/ComplexBoth.html", true,
107                "class <span class=\"typeNameLabel\">ComplexBoth&lt;K extends <a href=\""
108                + "../typeannos/ClassParamA.html\" title=\"annotation in typeannos\""
109                + ">@ClassParamA</a> java.lang.String &amp; <a href=\"../typeannos/"
110                + "ClassParamA.html\" title=\"annotation in typeannos\">@ClassParamA"
111                + "</a> java.lang.Runnable&gt;</span>");
112
113        // Test for type annotations on fields (Fields.java).
114        checkOutput("typeannos/DefaultScope.html", true,
115                "<pre><a href=\"../typeannos/Parameterized.html\" title=\"class in "
116                + "typeannos\">Parameterized</a>&lt;<a href=\"../typeannos/FldA.html\" "
117                + "title=\"annotation in typeannos\">@FldA</a> java.lang.String,<a "
118                + "href=\"../typeannos/FldB.html\" title=\"annotation in typeannos\">"
119                + "@FldB</a> java.lang.String&gt; bothTypeArgs</pre>",
120
121                "<pre><a href=\"../typeannos/FldA.html\" title=\"annotation in "
122                + "typeannos\">@FldA</a> java.lang.String <a href=\"../typeannos/"
123                + "FldB.html\" title=\"annotation in typeannos\">@FldB</a> [] "
124                + "array1Deep</pre>",
125
126                "<pre>java.lang.String[] <a href=\"../typeannos/FldB.html\" "
127                + "title=\"annotation in typeannos\">@FldB</a> [] array2SecondOld</pre>",
128
129                "<pre><a href=\"../typeannos/FldD.html\" title=\"annotation in "
130                + "typeannos\">@FldD</a> java.lang.String <a href=\"../typeannos/"
131                + "FldC.html\" title=\"annotation in typeannos\">@FldC</a> <a href=\""
132                + "../typeannos/FldA.html\" title=\"annotation in typeannos\">@FldA"
133                + "</a> [] <a href=\"../typeannos/FldC.html\" title=\"annotation in "
134                + "typeannos\">@FldC</a> <a href=\"../typeannos/FldB.html\" title=\""
135                + "annotation in typeannos\">@FldB</a> [] array2Deep</pre>");
136
137        checkOutput("typeannos/ModifiedScoped.html", true,
138                "<pre>public final&nbsp;<a href=\"../typeannos/Parameterized.html\" "
139                + "title=\"class in typeannos\">Parameterized</a>&lt;<a href=\"../"
140                + "typeannos/FldA.html\" title=\"annotation in typeannos\">@FldA</a> "
141                + "<a href=\"../typeannos/Parameterized.html\" title=\"class in "
142                + "typeannos\">Parameterized</a>&lt;<a href=\"../typeannos/FldA.html\" "
143                + "title=\"annotation in typeannos\">@FldA</a> java.lang.String,<a "
144                + "href=\"../typeannos/FldB.html\" title=\"annotation in typeannos\">"
145                + "@FldB</a> java.lang.String&gt;,<a href=\"../typeannos/FldB.html\" "
146                + "title=\"annotation in typeannos\">@FldB</a> java.lang.String&gt; "
147                + "nestedParameterized</pre>",
148
149                "<pre>public final&nbsp;<a href=\"../typeannos/FldA.html\" "
150                + "title=\"annotation in typeannos\">@FldA</a> java.lang.String[][] "
151                + "array2</pre>");
152
153        // Test for type annotations on method return types (MethodReturnType.java).
154        checkOutput("typeannos/MtdDefaultScope.html", true,
155                "<pre>public&nbsp;&lt;T&gt;&nbsp;<a href=\"../typeannos/MRtnA.html\" "
156                + "title=\"annotation in typeannos\">@MRtnA</a> java.lang.String"
157                + "&nbsp;method()</pre>",
158
159                "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in "
160                + "typeannos\">@MRtnA</a> java.lang.String <a href=\"../typeannos/"
161                + "MRtnA.html\" title=\"annotation in typeannos\">@MRtnA</a> [] <a "
162                + "href=\"../typeannos/MRtnB.html\" title=\"annotation in typeannos\">"
163                + "@MRtnB</a> []&nbsp;array2Deep()</pre>",
164
165                "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in "
166                + "typeannos\">@MRtnA</a> java.lang.String[][]&nbsp;array2()</pre>");
167
168        checkOutput("typeannos/MtdModifiedScoped.html", true,
169                "<pre>public final&nbsp;<a href=\"../typeannos/MtdParameterized.html\" "
170                + "title=\"class in typeannos\">MtdParameterized</a>&lt;<a href=\"../"
171                + "typeannos/MRtnA.html\" title=\"annotation in typeannos\">@MRtnA</a> "
172                + "<a href=\"../typeannos/MtdParameterized.html\" title=\"class in "
173                + "typeannos\">MtdParameterized</a>&lt;<a href=\"../typeannos/MRtnA."
174                + "html\" title=\"annotation in typeannos\">@MRtnA</a> java.lang."
175                + "String,<a href=\"../typeannos/MRtnB.html\" title=\"annotation in "
176                + "typeannos\">@MRtnB</a> java.lang.String&gt;,<a href=\"../typeannos/"
177                + "MRtnB.html\" title=\"annotation in typeannos\">@MRtnB</a> java."
178                + "lang.String&gt;&nbsp;nestedMtdParameterized()</pre>");
179
180        // Test for type annotations on method type parameters (MethodTypeParameters.java).
181        checkOutput("typeannos/UnscopedUnmodified.html", true,
182                "<pre>&lt;K extends <a href=\"../typeannos/MTyParamA.html\" title=\""
183                + "annotation in typeannos\">@MTyParamA</a> java.lang.String&gt;"
184                + "&nbsp;void&nbsp;methodExtends()</pre>",
185
186                "<pre>&lt;K extends <a href=\"../typeannos/MTyParamA.html\" title=\""
187                + "annotation in typeannos\">@MTyParamA</a> <a href=\"../typeannos/"
188                + "MtdTyParameterized.html\" title=\"class in typeannos\">"
189                + "MtdTyParameterized</a>&lt;<a href=\"../typeannos/MTyParamB.html\" "
190                + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String"
191                + "&gt;&gt;&nbsp;void&nbsp;nestedExtends()</pre>");
192
193        checkOutput("typeannos/PublicModifiedMethods.html", true,
194                "<pre>public final&nbsp;&lt;K extends <a href=\"../typeannos/"
195                + "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> "
196                + "java.lang.String&gt;&nbsp;void&nbsp;methodExtends()</pre>",
197
198                "<pre>public final&nbsp;&lt;K extends <a href=\"../typeannos/"
199                + "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> "
200                + "java.lang.String,V extends <a href=\"../typeannos/MTyParamA.html\" "
201                + "title=\"annotation in typeannos\">@MTyParamA</a> <a href=\"../"
202                + "typeannos/MtdTyParameterized.html\" title=\"class in typeannos\">"
203                + "MtdTyParameterized</a>&lt;<a href=\"../typeannos/MTyParamB.html\" "
204                + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String"
205                + "&gt;&gt;&nbsp;void&nbsp;dual()</pre>");
206
207        // Test for type annotations on parameters (Parameters.java).
208        checkOutput("typeannos/Parameters.html", true,
209                "<pre>void&nbsp;unannotated(<a href=\"../typeannos/"
210                + "ParaParameterized.html\" title=\"class in typeannos\">"
211                + "ParaParameterized</a>&lt;java.lang.String,java.lang.String&gt;"
212                + "&nbsp;a)</pre>",
213
214                "<pre>void&nbsp;nestedParaParameterized(<a href=\"../typeannos/"
215                + "ParaParameterized.html\" title=\"class in typeannos\">"
216                + "ParaParameterized</a>&lt;<a href=\"../typeannos/ParamA.html\" "
217                + "title=\"annotation in typeannos\">@ParamA</a> <a href=\"../"
218                + "typeannos/ParaParameterized.html\" title=\"class in typeannos\">"
219                + "ParaParameterized</a>&lt;<a href=\"../typeannos/ParamA.html\" "
220                + "title=\"annotation in typeannos\">@ParamA</a> java.lang.String,"
221                + "<a href=\"../typeannos/ParamB.html\" title=\"annotation in "
222                + "typeannos\">@ParamB</a> java.lang.String&gt;,<a href=\"../"
223                + "typeannos/ParamB.html\" title=\"annotation in typeannos\">@ParamB"
224                + "</a> java.lang.String&gt;&nbsp;a)</pre>",
225
226                "<pre>void&nbsp;array2Deep(<a href=\"../typeannos/ParamA.html\" "
227                + "title=\"annotation in typeannos\">@ParamA</a> java.lang.String "
228                + "<a href=\"../typeannos/ParamA.html\" title=\"annotation in "
229                + "typeannos\">@ParamA</a> [] <a href=\"../typeannos/ParamB.html\" "
230                + "title=\"annotation in typeannos\">@ParamB</a> []&nbsp;a)</pre>");
231
232        // Test for type annotations on throws (Throws.java).
233        checkOutput("typeannos/ThrDefaultUnmodified.html", true,
234                "<pre>void&nbsp;oneException()\n"
235                + "           throws <a href=\"../typeannos/ThrA.html\" title=\""
236                + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>",
237
238                "<pre>void&nbsp;twoExceptions()\n"
239                + "            throws <a href=\"../typeannos/ThrA.html\" title=\""
240                + "annotation in typeannos\">@ThrA</a> java.lang.RuntimeException,\n"
241                + "                   <a href=\"../typeannos/ThrA.html\" title=\""
242                + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>");
243
244        checkOutput("typeannos/ThrPublicModified.html", true,
245                "<pre>public final&nbsp;void&nbsp;oneException(java.lang.String&nbsp;a)\n"
246                + "                        throws <a href=\"../typeannos/ThrA.html\" "
247                + "title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>",
248
249                "<pre>public final&nbsp;void&nbsp;twoExceptions(java.lang.String&nbsp;a)\n"
250                + "                         throws <a href=\"../typeannos/ThrA.html\" "
251                + "title=\"annotation in typeannos\">@ThrA</a> java.lang.RuntimeException,\n"
252                + "                                <a href=\"../typeannos/ThrA.html\" "
253                + "title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>");
254
255        checkOutput("typeannos/ThrWithValue.html", true,
256                "<pre>void&nbsp;oneException()\n"
257                + "           throws <a href=\"../typeannos/ThrB.html\" title=\""
258                + "annotation in typeannos\">@ThrB</a>(<a href=\"../typeannos/"
259                + "ThrB.html#value--\">value</a>=\"m\") java.lang.Exception</pre>",
260
261                "<pre>void&nbsp;twoExceptions()\n"
262                + "            throws <a href=\"../typeannos/ThrB.html\" title=\""
263                + "annotation in typeannos\">@ThrB</a>(<a href=\"../typeannos/"
264                + "ThrB.html#value--\">value</a>=\"m\") java.lang.RuntimeException,\n"
265                + "                   <a href=\"../typeannos/ThrA.html\" title=\""
266                + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>");
267
268        // Test for type annotations on type parameters (TypeParameters.java).
269        checkOutput("typeannos/TestMethods.html", true,
270                "<pre>&lt;K,V extends <a href=\"../typeannos/TyParaA.html\" title=\""
271                + "annotation in typeannos\">@TyParaA</a> java.lang.String&gt;&nbsp;"
272                + "void&nbsp;secondAnnotated()</pre>");
273
274        // Test for type annotations on wildcard type (Wildcards.java).
275        checkOutput("typeannos/BoundTest.html", true,
276                "<pre>void&nbsp;wcExtends(<a href=\"../typeannos/MyList.html\" "
277                + "title=\"class in typeannos\">MyList</a>&lt;? extends <a href=\""
278                + "../typeannos/WldA.html\" title=\"annotation in typeannos\">@WldA"
279                + "</a> java.lang.String&gt;&nbsp;l)</pre>",
280
281                "<pre><a href=\"../typeannos/MyList.html\" title=\"class in "
282                + "typeannos\">MyList</a>&lt;? super <a href=\"../typeannos/WldA.html\" "
283                + "title=\"annotation in typeannos\">@WldA</a> java.lang.String&gt;"
284                + "&nbsp;returnWcSuper()</pre>");
285
286        checkOutput("typeannos/BoundWithValue.html", true,
287                "<pre>void&nbsp;wcSuper(<a href=\"../typeannos/MyList.html\" title=\""
288                + "class in typeannos\">MyList</a>&lt;? super <a href=\"../typeannos/"
289                + "WldB.html\" title=\"annotation in typeannos\">@WldB</a>(<a href=\""
290                + "../typeannos/WldB.html#value--\">value</a>=\"m\") java.lang."
291                + "String&gt;&nbsp;l)</pre>",
292
293                "<pre><a href=\"../typeannos/MyList.html\" title=\"class in "
294                + "typeannos\">MyList</a>&lt;? extends <a href=\"../typeannos/WldB."
295                + "html\" title=\"annotation in typeannos\">@WldB</a>(<a href=\"../"
296                + "typeannos/WldB.html#value--\">value</a>=\"m\") java.lang.String"
297                + "&gt;&nbsp;returnWcExtends()</pre>");
298
299        // Test for receiver annotations (Receivers.java).
300        checkOutput("typeannos/DefaultUnmodified.html", true,
301                "<pre>void&nbsp;withException(<a href=\"../typeannos/RcvrA.html\" "
302                + "title=\"annotation in typeannos\">@RcvrA</a>&nbsp;"
303                + "DefaultUnmodified&nbsp;this)\n"
304                + "            throws java."
305                + "lang.Exception</pre>",
306
307                "<pre>java.lang.String&nbsp;nonVoid(<a href=\"../typeannos/RcvrA."
308                + "html\" title=\"annotation in typeannos\">@RcvrA</a> <a href=\"../"
309                + "typeannos/RcvrB.html\" title=\"annotation in typeannos\">@RcvrB"
310                + "</a>(<a href=\"../typeannos/RcvrB.html#value--\">value</a>=\"m\")"
311                + "&nbsp;DefaultUnmodified&nbsp;this)</pre>",
312
313                "<pre>&lt;T extends java.lang.Runnable&gt;&nbsp;void&nbsp;accept("
314                + "<a href=\"../typeannos/RcvrA.html\" title=\"annotation in "
315                + "typeannos\">@RcvrA</a>&nbsp;DefaultUnmodified&nbsp;this,\n"
316                + "                                           T&nbsp;r)\n"
317                + "                                    throws java.lang.Exception</pre>");
318
319        checkOutput("typeannos/PublicModified.html", true,
320                "<pre>public final&nbsp;java.lang.String&nbsp;nonVoid(<a href=\""
321                + "../typeannos/RcvrA.html\" title=\"annotation in typeannos\">"
322                + "@RcvrA</a>&nbsp;PublicModified&nbsp;this)</pre>",
323
324                "<pre>public final&nbsp;&lt;T extends java.lang.Runnable&gt;&nbsp;"
325                + "void&nbsp;accept(<a href=\"../typeannos/RcvrA.html\" title=\""
326                + "annotation in typeannos\">@RcvrA</a>&nbsp;PublicModified&nbsp;this,\n"
327                + "                                                        T&nbsp;r)\n"
328                + "                                                 throws java.lang.Exception</pre>");
329
330        checkOutput("typeannos/WithValue.html", true,
331                "<pre>&lt;T extends java.lang.Runnable&gt;&nbsp;void&nbsp;accept("
332                + "<a href=\"../typeannos/RcvrB.html\" title=\"annotation in "
333                + "typeannos\">@RcvrB</a>(<a href=\"../typeannos/RcvrB.html#value--\">"
334                + "value</a>=\"m\")&nbsp;WithValue&nbsp;this,\n"
335                + "                                           T&nbsp;r)\n"
336                + "                                    throws java.lang.Exception</pre>");
337
338        checkOutput("typeannos/WithFinal.html", true,
339                "<pre>java.lang.String&nbsp;nonVoid(<a href=\"../typeannos/RcvrB."
340                + "html\" title=\"annotation in typeannos\">@RcvrB</a>(<a href=\"../"
341                + "typeannos/RcvrB.html#value--\">value</a>=\"m\")&nbsp;WithFinal"
342                + "&nbsp;this)</pre>");
343
344        checkOutput("typeannos/WithBody.html", true,
345                "<pre>void&nbsp;field(<a href=\"../typeannos/RcvrA.html\" title=\""
346                + "annotation in typeannos\">@RcvrA</a>&nbsp;WithBody&nbsp;this)</pre>");
347
348        checkOutput("typeannos/Generic2.html", true,
349                "<pre>void&nbsp;test2(<a href=\"../typeannos/RcvrA.html\" title=\""
350                + "annotation in typeannos\">@RcvrA</a>&nbsp;Generic2&lt;X&gt;&nbsp;this)</pre>");
351    }
352}
353