TestTypeAnnotations.java revision 3294:9adfb22ff08f
1/* 2 * Copyright (c) 2013, 2016, 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 6469562 27 * @summary Make sure that type annotations are displayed correctly 28 * @author Bhavesh Patel 29 * @library ../lib 30 * @modules jdk.javadoc/jdk.javadoc.internal.tool 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><<a href=\"" 55 + "../typeannos/ClassExtB.html\" title=\"annotation in typeannos\">" 56 + "@ClassExtB</a> java.lang.String>", 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><" 63 + "<a href=\"../typeannos/ClassExtB.html\" title=\"annotation in " 64 + "typeannos\">@ClassExtB</a> java.lang.String></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><<a href=\"../typeannos/ClassExtA.html\" " 71 + "title=\"annotation in typeannos\">@ClassExtA</a> java.lang.String>, " 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<K extends <a " 78 + "href=\"../typeannos/ClassParamA.html\" title=\"annotation in " 79 + "typeannos\">@ClassParamA</a> java.lang.String></span>"); 80 81 checkOutput("typeannos/ExtendsGeneric.html", true, 82 "<pre>class <span class=\"typeNameLabel\">ExtendsGeneric<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><<a href=\"" 86 + "../typeannos/ClassParamB.html\" title=\"annotation in typeannos\">" 87 + "@ClassParamB</a> java.lang.String>></span>"); 88 89 checkOutput("typeannos/TwoBounds.html", true, 90 "<pre>class <span class=\"typeNameLabel\">TwoBounds<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></span>"); 95 96 checkOutput("typeannos/Complex1.html", true, 97 "class <span class=\"typeNameLabel\">Complex1<K extends <a href=\"../" 98 + "typeannos/ClassParamA.html\" title=\"annotation in typeannos\">" 99 + "@ClassParamA</a> java.lang.String & java.lang.Runnable></span>"); 100 101 checkOutput("typeannos/Complex2.html", true, 102 "class <span class=\"typeNameLabel\">Complex2<K extends java.lang." 103 + "String & <a href=\"../typeannos/ClassParamB.html\" title=\"" 104 + "annotation in typeannos\">@ClassParamB</a> java.lang.Runnable></span>"); 105 106 checkOutput("typeannos/ComplexBoth.html", true, 107 "class <span class=\"typeNameLabel\">ComplexBoth<K extends <a href=\"" 108 + "../typeannos/ClassParamA.html\" title=\"annotation in typeannos\"" 109 + ">@ClassParamA</a> java.lang.String & <a href=\"../typeannos/" 110 + "ClassParamA.html\" title=\"annotation in typeannos\">@ClassParamA" 111 + "</a> java.lang.Runnable></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><<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> 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 // When JDK-8068737, we should change the order 130 "<pre><a href=\"../typeannos/FldD.html\" title=\"annotation in typeannos\">" 131 + "@FldD</a> java.lang.String " 132 + "<a href=\"../typeannos/FldC.html\" title=\"annotation in typeannos\">@FldC</a> " 133 + "<a href=\"../typeannos/FldB.html\" title=\"annotation in typeannos\">@FldB</a> [] " 134 + "<a href=\"../typeannos/FldC.html\" title=\"annotation in typeannos\">@FldC</a> " 135 + "<a href=\"../typeannos/FldA.html\" title=\"annotation in typeannos\">@FldA</a> [] " 136 + "array2Deep</pre>"); 137 138 checkOutput("typeannos/ModifiedScoped.html", true, 139 "<pre>public final <a href=\"../typeannos/Parameterized.html\" " 140 + "title=\"class in typeannos\">Parameterized</a><<a href=\"../" 141 + "typeannos/FldA.html\" title=\"annotation in typeannos\">@FldA</a> " 142 + "<a href=\"../typeannos/Parameterized.html\" title=\"class in " 143 + "typeannos\">Parameterized</a><<a href=\"../typeannos/FldA.html\" " 144 + "title=\"annotation in typeannos\">@FldA</a> java.lang.String,<a " 145 + "href=\"../typeannos/FldB.html\" title=\"annotation in typeannos\">" 146 + "@FldB</a> java.lang.String>,<a href=\"../typeannos/FldB.html\" " 147 + "title=\"annotation in typeannos\">@FldB</a> java.lang.String> " 148 + "nestedParameterized</pre>", 149 150 "<pre>public final <a href=\"../typeannos/FldA.html\" " 151 + "title=\"annotation in typeannos\">@FldA</a> java.lang.String[][] " 152 + "array2</pre>"); 153 154 // Test for type annotations on method return types (MethodReturnType.java). 155 checkOutput("typeannos/MtdDefaultScope.html", true, 156 "<pre>public <T> <a href=\"../typeannos/MRtnA.html\" " 157 + "title=\"annotation in typeannos\">@MRtnA</a> java.lang.String" 158 + " method()</pre>", 159 160 // When JDK-8068737 is fixed, we should change the order 161 "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in typeannos\">" 162 + "@MRtnA</a> java.lang.String " 163 + "<a href=\"../typeannos/MRtnB.html\" title=\"annotation in typeannos\">@MRtnB</a> [] " 164 + "<a href=\"../typeannos/MRtnA.html\" title=\"annotation in typeannos\">@MRtnA</a> []" 165 + " array2Deep()</pre>", 166 167 "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in " 168 + "typeannos\">@MRtnA</a> java.lang.String[][] array2()</pre>"); 169 170 checkOutput("typeannos/MtdModifiedScoped.html", true, 171 "<pre>public final <a href=\"../typeannos/MtdParameterized.html\" " 172 + "title=\"class in typeannos\">MtdParameterized</a><<a href=\"../" 173 + "typeannos/MRtnA.html\" title=\"annotation in typeannos\">@MRtnA</a> " 174 + "<a href=\"../typeannos/MtdParameterized.html\" title=\"class in " 175 + "typeannos\">MtdParameterized</a><<a href=\"../typeannos/MRtnA." 176 + "html\" title=\"annotation in typeannos\">@MRtnA</a> java.lang." 177 + "String,<a href=\"../typeannos/MRtnB.html\" title=\"annotation in " 178 + "typeannos\">@MRtnB</a> java.lang.String>,<a href=\"../typeannos/" 179 + "MRtnB.html\" title=\"annotation in typeannos\">@MRtnB</a> java." 180 + "lang.String> nestedMtdParameterized()</pre>"); 181 182 // Test for type annotations on method type parameters (MethodTypeParameters.java). 183 checkOutput("typeannos/UnscopedUnmodified.html", true, 184 "<pre><K extends <a href=\"../typeannos/MTyParamA.html\" title=\"" 185 + "annotation in typeannos\">@MTyParamA</a> java.lang.String>" 186 + " void methodExtends()</pre>", 187 188 "<pre><K extends <a href=\"../typeannos/MTyParamA.html\" title=\"" 189 + "annotation in typeannos\">@MTyParamA</a> <a href=\"../typeannos/" 190 + "MtdTyParameterized.html\" title=\"class in typeannos\">" 191 + "MtdTyParameterized</a><<a href=\"../typeannos/MTyParamB.html\" " 192 + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" 193 + ">> void nestedExtends()</pre>"); 194 195 checkOutput("typeannos/PublicModifiedMethods.html", true, 196 "<pre>public final <K extends <a href=\"../typeannos/" 197 + "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " 198 + "java.lang.String> void methodExtends()</pre>", 199 200 "<pre>public final <K extends <a href=\"../typeannos/" 201 + "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " 202 + "java.lang.String,V extends <a href=\"../typeannos/MTyParamA.html\" " 203 + "title=\"annotation in typeannos\">@MTyParamA</a> <a href=\"../" 204 + "typeannos/MtdTyParameterized.html\" title=\"class in typeannos\">" 205 + "MtdTyParameterized</a><<a href=\"../typeannos/MTyParamB.html\" " 206 + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" 207 + ">> void dual()</pre>"); 208 209 // Test for type annotations on parameters (Parameters.java). 210 checkOutput("typeannos/Parameters.html", true, 211 "<pre>void unannotated(<a href=\"../typeannos/" 212 + "ParaParameterized.html\" title=\"class in typeannos\">" 213 + "ParaParameterized</a><java.lang.String,java.lang.String>" 214 + " a)</pre>", 215 216 "<pre>void nestedParaParameterized(<a href=\"../typeannos/" 217 + "ParaParameterized.html\" title=\"class in typeannos\">" 218 + "ParaParameterized</a><<a href=\"../typeannos/ParamA.html\" " 219 + "title=\"annotation in typeannos\">@ParamA</a> <a href=\"../" 220 + "typeannos/ParaParameterized.html\" title=\"class in typeannos\">" 221 + "ParaParameterized</a><<a href=\"../typeannos/ParamA.html\" " 222 + "title=\"annotation in typeannos\">@ParamA</a> java.lang.String," 223 + "<a href=\"../typeannos/ParamB.html\" title=\"annotation in " 224 + "typeannos\">@ParamB</a> java.lang.String>,<a href=\"../" 225 + "typeannos/ParamB.html\" title=\"annotation in typeannos\">@ParamB" 226 + "</a> java.lang.String> a)</pre>", 227 228 // When JDK-8068737 is fixed, we should change the order 229 "<pre>void array2Deep(<a href=\"../typeannos/ParamA.html\" " 230 + "title=\"annotation in typeannos\">@ParamA</a> java.lang.String " 231 + "<a href=\"../typeannos/ParamB.html\" title=\"annotation in typeannos\">" 232 + "@ParamB</a> [] " 233 + "<a href=\"../typeannos/ParamA.html\" title=\"annotation in typeannos\">" 234 + "@ParamA</a> []" 235 + " a)</pre>"); 236 237 // Test for type annotations on throws (Throws.java). 238 checkOutput("typeannos/ThrDefaultUnmodified.html", true, 239 "<pre>void oneException()\n" 240 + " throws <a href=\"../typeannos/ThrA.html\" title=\"" 241 + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>", 242 243 "<pre>void twoExceptions()\n" 244 + " throws <a href=\"../typeannos/ThrA.html\" title=\"" 245 + "annotation in typeannos\">@ThrA</a> java.lang.RuntimeException,\n" 246 + " <a href=\"../typeannos/ThrA.html\" title=\"" 247 + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"); 248 249 checkOutput("typeannos/ThrPublicModified.html", true, 250 "<pre>public final void oneException(java.lang.String a)\n" 251 + " throws <a href=\"../typeannos/ThrA.html\" " 252 + "title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>", 253 254 "<pre>public final void twoExceptions(java.lang.String a)\n" 255 + " throws <a href=\"../typeannos/ThrA.html\" " 256 + "title=\"annotation in typeannos\">@ThrA</a> java.lang.RuntimeException,\n" 257 + " <a href=\"../typeannos/ThrA.html\" " 258 + "title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"); 259 260 checkOutput("typeannos/ThrWithValue.html", true, 261 "<pre>void oneException()\n" 262 + " throws <a href=\"../typeannos/ThrB.html\" title=\"" 263 + "annotation in typeannos\">@ThrB</a>(" 264 + "\"m\") java.lang.Exception</pre>", 265 266 "<pre>void twoExceptions()\n" 267 + " throws <a href=\"../typeannos/ThrB.html\" title=\"" 268 + "annotation in typeannos\">@ThrB</a>(" 269 + "\"m\") java.lang.RuntimeException,\n" 270 + " <a href=\"../typeannos/ThrA.html\" title=\"" 271 + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"); 272 273 // Test for type annotations on type parameters (TypeParameters.java). 274 checkOutput("typeannos/TestMethods.html", true, 275 "<pre><K,<a href=\"../typeannos/TyParaA.html\" title=\"annotation in typeannos\">" 276 + "@TyParaA</a> V extends <a href=\"../typeannos/TyParaA.html\" " 277 + "title=\"annotation in typeannos\">@TyParaA</a> " 278 + "java.lang.String> void secondAnnotated()</pre>" 279 ); 280 281 // Test for type annotations on wildcard type (Wildcards.java). 282 checkOutput("typeannos/BoundTest.html", true, 283 "<pre>void wcExtends(<a href=\"../typeannos/MyList.html\" " 284 + "title=\"class in typeannos\">MyList</a><? extends <a href=\"" 285 + "../typeannos/WldA.html\" title=\"annotation in typeannos\">@WldA" 286 + "</a> java.lang.String> l)</pre>", 287 288 "<pre><a href=\"../typeannos/MyList.html\" title=\"class in " 289 + "typeannos\">MyList</a><? super <a href=\"../typeannos/WldA.html\" " 290 + "title=\"annotation in typeannos\">@WldA</a> java.lang.String>" 291 + " returnWcSuper()</pre>"); 292 293 checkOutput("typeannos/BoundWithValue.html", true, 294 "<pre>void wcSuper(<a href=\"../typeannos/MyList.html\" title=\"" 295 + "class in typeannos\">MyList</a><? super <a href=\"../typeannos/" 296 + "WldB.html\" title=\"annotation in typeannos\">@WldB</a>(" 297 + "\"m\") java.lang." 298 + "String> l)</pre>", 299 300 "<pre><a href=\"../typeannos/MyList.html\" title=\"class in " 301 + "typeannos\">MyList</a><? extends <a href=\"../typeannos/WldB." 302 + "html\" title=\"annotation in typeannos\">@WldB</a>(" 303 + "\"m\") java.lang.String" 304 + "> returnWcExtends()</pre>"); 305 306 // Test for receiver annotations (Receivers.java). 307 checkOutput("typeannos/DefaultUnmodified.html", true, 308 "<pre>void withException(<a href=\"../typeannos/RcvrA.html\" " 309 + "title=\"annotation in typeannos\">@RcvrA</a> " 310 + "DefaultUnmodified this)\n" 311 + " throws java." 312 + "lang.Exception</pre>", 313 314 "<pre>java.lang.String nonVoid(<a href=\"../typeannos/RcvrA." 315 + "html\" title=\"annotation in typeannos\">@RcvrA</a> <a href=\"../" 316 + "typeannos/RcvrB.html\" title=\"annotation in typeannos\">@RcvrB" 317 + "</a>(\"m\")" 318 + " DefaultUnmodified this)</pre>", 319 320 "<pre><T extends java.lang.Runnable> void accept(" 321 + "<a href=\"../typeannos/RcvrA.html\" title=\"annotation in " 322 + "typeannos\">@RcvrA</a> DefaultUnmodified this,\n" 323 + " T r)\n" 324 + " throws java.lang.Exception</pre>"); 325 326 checkOutput("typeannos/PublicModified.html", true, 327 "<pre>public final java.lang.String nonVoid(<a href=\"" 328 + "../typeannos/RcvrA.html\" title=\"annotation in typeannos\">" 329 + "@RcvrA</a> PublicModified this)</pre>", 330 331 "<pre>public final <T extends java.lang.Runnable> " 332 + "void accept(<a href=\"../typeannos/RcvrA.html\" title=\"" 333 + "annotation in typeannos\">@RcvrA</a> PublicModified this,\n" 334 + " T r)\n" 335 + " throws java.lang.Exception</pre>"); 336 337 checkOutput("typeannos/WithValue.html", true, 338 "<pre><T extends java.lang.Runnable> void accept(" 339 + "<a href=\"../typeannos/RcvrB.html\" title=\"annotation in " 340 + "typeannos\">@RcvrB</a>(" 341 + "\"m\") WithValue this,\n" 342 + " T r)\n" 343 + " throws java.lang.Exception</pre>"); 344 345 checkOutput("typeannos/WithFinal.html", true, 346 "<pre>java.lang.String nonVoid(<a href=\"../typeannos/RcvrB." 347 + "html\" title=\"annotation in typeannos\">@RcvrB</a>(" 348 + "\"m\") WithFinal" 349 + " this)</pre>"); 350 351 checkOutput("typeannos/WithBody.html", true, 352 "<pre>void field(<a href=\"../typeannos/RcvrA.html\" title=\"" 353 + "annotation in typeannos\">@RcvrA</a> WithBody this)</pre>"); 354 355 checkOutput("typeannos/Generic2.html", true, 356 "<pre>void test2(<a href=\"../typeannos/RcvrA.html\" title=\"" 357 + "annotation in typeannos\">@RcvrA</a> Generic2<X> this)</pre>"); 358 } 359} 360