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><<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 "<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 <a href=\"../typeannos/Parameterized.html\" " 139 + "title=\"class in typeannos\">Parameterized</a><<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><<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>,<a href=\"../typeannos/FldB.html\" " 146 + "title=\"annotation in typeannos\">@FldB</a> java.lang.String> " 147 + "nestedParameterized</pre>", 148 149 "<pre>public final <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 <T> <a href=\"../typeannos/MRtnA.html\" " 156 + "title=\"annotation in typeannos\">@MRtnA</a> java.lang.String" 157 + " 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> [] array2Deep()</pre>", 164 165 "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in " 166 + "typeannos\">@MRtnA</a> java.lang.String[][] array2()</pre>"); 167 168 checkOutput("typeannos/MtdModifiedScoped.html", true, 169 "<pre>public final <a href=\"../typeannos/MtdParameterized.html\" " 170 + "title=\"class in typeannos\">MtdParameterized</a><<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><<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>,<a href=\"../typeannos/" 177 + "MRtnB.html\" title=\"annotation in typeannos\">@MRtnB</a> java." 178 + "lang.String> nestedMtdParameterized()</pre>"); 179 180 // Test for type annotations on method type parameters (MethodTypeParameters.java). 181 checkOutput("typeannos/UnscopedUnmodified.html", true, 182 "<pre><K extends <a href=\"../typeannos/MTyParamA.html\" title=\"" 183 + "annotation in typeannos\">@MTyParamA</a> java.lang.String>" 184 + " void methodExtends()</pre>", 185 186 "<pre><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><<a href=\"../typeannos/MTyParamB.html\" " 190 + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" 191 + ">> void nestedExtends()</pre>"); 192 193 checkOutput("typeannos/PublicModifiedMethods.html", true, 194 "<pre>public final <K extends <a href=\"../typeannos/" 195 + "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " 196 + "java.lang.String> void methodExtends()</pre>", 197 198 "<pre>public final <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><<a href=\"../typeannos/MTyParamB.html\" " 204 + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" 205 + ">> void dual()</pre>"); 206 207 // Test for type annotations on parameters (Parameters.java). 208 checkOutput("typeannos/Parameters.html", true, 209 "<pre>void unannotated(<a href=\"../typeannos/" 210 + "ParaParameterized.html\" title=\"class in typeannos\">" 211 + "ParaParameterized</a><java.lang.String,java.lang.String>" 212 + " a)</pre>", 213 214 "<pre>void nestedParaParameterized(<a href=\"../typeannos/" 215 + "ParaParameterized.html\" title=\"class in typeannos\">" 216 + "ParaParameterized</a><<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><<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>,<a href=\"../" 223 + "typeannos/ParamB.html\" title=\"annotation in typeannos\">@ParamB" 224 + "</a> java.lang.String> a)</pre>", 225 226 "<pre>void 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> [] a)</pre>"); 231 232 // Test for type annotations on throws (Throws.java). 233 checkOutput("typeannos/ThrDefaultUnmodified.html", true, 234 "<pre>void oneException()\n" 235 + " throws <a href=\"../typeannos/ThrA.html\" title=\"" 236 + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>", 237 238 "<pre>void 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 void oneException(java.lang.String 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 void twoExceptions(java.lang.String 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 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 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><K,V extends <a href=\"../typeannos/TyParaA.html\" title=\"" 271 + "annotation in typeannos\">@TyParaA</a> java.lang.String> " 272 + "void secondAnnotated()</pre>"); 273 274 // Test for type annotations on wildcard type (Wildcards.java). 275 checkOutput("typeannos/BoundTest.html", true, 276 "<pre>void wcExtends(<a href=\"../typeannos/MyList.html\" " 277 + "title=\"class in typeannos\">MyList</a><? extends <a href=\"" 278 + "../typeannos/WldA.html\" title=\"annotation in typeannos\">@WldA" 279 + "</a> java.lang.String> l)</pre>", 280 281 "<pre><a href=\"../typeannos/MyList.html\" title=\"class in " 282 + "typeannos\">MyList</a><? super <a href=\"../typeannos/WldA.html\" " 283 + "title=\"annotation in typeannos\">@WldA</a> java.lang.String>" 284 + " returnWcSuper()</pre>"); 285 286 checkOutput("typeannos/BoundWithValue.html", true, 287 "<pre>void wcSuper(<a href=\"../typeannos/MyList.html\" title=\"" 288 + "class in typeannos\">MyList</a><? 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> l)</pre>", 292 293 "<pre><a href=\"../typeannos/MyList.html\" title=\"class in " 294 + "typeannos\">MyList</a><? 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 + "> returnWcExtends()</pre>"); 298 299 // Test for receiver annotations (Receivers.java). 300 checkOutput("typeannos/DefaultUnmodified.html", true, 301 "<pre>void withException(<a href=\"../typeannos/RcvrA.html\" " 302 + "title=\"annotation in typeannos\">@RcvrA</a> " 303 + "DefaultUnmodified this)\n" 304 + " throws java." 305 + "lang.Exception</pre>", 306 307 "<pre>java.lang.String 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 + " DefaultUnmodified this)</pre>", 312 313 "<pre><T extends java.lang.Runnable> void accept(" 314 + "<a href=\"../typeannos/RcvrA.html\" title=\"annotation in " 315 + "typeannos\">@RcvrA</a> DefaultUnmodified this,\n" 316 + " T r)\n" 317 + " throws java.lang.Exception</pre>"); 318 319 checkOutput("typeannos/PublicModified.html", true, 320 "<pre>public final java.lang.String nonVoid(<a href=\"" 321 + "../typeannos/RcvrA.html\" title=\"annotation in typeannos\">" 322 + "@RcvrA</a> PublicModified this)</pre>", 323 324 "<pre>public final <T extends java.lang.Runnable> " 325 + "void accept(<a href=\"../typeannos/RcvrA.html\" title=\"" 326 + "annotation in typeannos\">@RcvrA</a> PublicModified this,\n" 327 + " T r)\n" 328 + " throws java.lang.Exception</pre>"); 329 330 checkOutput("typeannos/WithValue.html", true, 331 "<pre><T extends java.lang.Runnable> void accept(" 332 + "<a href=\"../typeannos/RcvrB.html\" title=\"annotation in " 333 + "typeannos\">@RcvrB</a>(<a href=\"../typeannos/RcvrB.html#value--\">" 334 + "value</a>=\"m\") WithValue this,\n" 335 + " T r)\n" 336 + " throws java.lang.Exception</pre>"); 337 338 checkOutput("typeannos/WithFinal.html", true, 339 "<pre>java.lang.String nonVoid(<a href=\"../typeannos/RcvrB." 340 + "html\" title=\"annotation in typeannos\">@RcvrB</a>(<a href=\"../" 341 + "typeannos/RcvrB.html#value--\">value</a>=\"m\") WithFinal" 342 + " this)</pre>"); 343 344 checkOutput("typeannos/WithBody.html", true, 345 "<pre>void field(<a href=\"../typeannos/RcvrA.html\" title=\"" 346 + "annotation in typeannos\">@RcvrA</a> WithBody this)</pre>"); 347 348 checkOutput("typeannos/Generic2.html", true, 349 "<pre>void test2(<a href=\"../typeannos/RcvrA.html\" title=\"" 350 + "annotation in typeannos\">@RcvrA</a> Generic2<X> this)</pre>"); 351 } 352} 353