1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/FromSpecification.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,122 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 1.28 + 1.29 +/* 1.30 + * @test 1.31 + * @summary Test that the examples from the manual are stored as expected 1.32 + * @compile -g Driver.java ReferenceInfoUtil.java FromSpecification.java 1.33 + * @run main Driver FromSpecification 1.34 + */ 1.35 +public class FromSpecification { 1.36 + 1.37 + @TADescriptions({ 1.38 + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), 1.39 + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 1.40 + genericLocation = {3, 0}, paramIndex = 0), 1.41 + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 1.42 + genericLocation = {3, 0, 2, 0}, paramIndex = 0), 1.43 + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, 1.44 + genericLocation = {3, 1}, paramIndex = 0), 1.45 + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, 1.46 + genericLocation = {3, 1, 3, 0}, paramIndex = 0) 1.47 + }) 1.48 + public String testSpec1() { 1.49 + return "void test(@TA Map<@TB ? extends @TC String, @TD List<@TE Object>> a) { }"; 1.50 + } 1.51 + 1.52 + @TADescriptions({ 1.53 + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), 1.54 + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, 1.55 + genericLocation = {0, 0}, paramIndex = 0), 1.56 + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, 1.57 + genericLocation = {0, 0, 0, 0}, paramIndex = 0), 1.58 + @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, 1.59 + genericLocation = {0, 0, 0, 0, 0, 0}, paramIndex = 0) 1.60 + }) 1.61 + public String testSpec2() { 1.62 + return "void test(@TI String @TF [] @TG [] @TH [] a) { }"; 1.63 + } 1.64 + 1.65 + // Note first "1, 0" for top-level class Test. 1.66 + @TADescriptions({ 1.67 + @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, 1.68 + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0), 1.69 + @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER, 1.70 + genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0), 1.71 + @TADescription(annotation = "TL", type = METHOD_FORMAL_PARAMETER, 1.72 + genericLocation = {1, 0, 1, 0}, paramIndex = 0), 1.73 + @TADescription(annotation = "TM", type = METHOD_FORMAL_PARAMETER, 1.74 + genericLocation = {1, 0}, paramIndex = 0) 1.75 + }) 1.76 + public String testSpec3() { 1.77 + return "class Test { class O1 { class O2 { class O3 { class NestedStatic {} } } }" + 1.78 + "void test(@TM O1.@TL O2.@TK O3.@TJ NestedStatic a) { } }"; 1.79 + } 1.80 + 1.81 + @TADescriptions({ 1.82 + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), 1.83 + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 1.84 + genericLocation = {3, 0}, paramIndex = 0), 1.85 + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 1.86 + genericLocation = {3, 0, 3, 0}, paramIndex = 0), 1.87 + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, 1.88 + genericLocation = {3, 0, 3, 0, 0, 0}, paramIndex = 0), 1.89 + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, 1.90 + genericLocation = {3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0), 1.91 + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, 1.92 + genericLocation = {3, 0, 3, 0, 0, 0, 0, 0, 0, 0}, paramIndex = 0), 1.93 + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, 1.94 + genericLocation = {3, 1}, paramIndex = 0), 1.95 + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, 1.96 + genericLocation = {3, 1, 3, 0}, paramIndex = 0) 1.97 + }) 1.98 + public String testSpec4() { 1.99 + return "void test(@TA Map<@TB Comparable<@TF Object @TC [] @TD [] @TE []>, @TG List<@TH String>> a) { }"; 1.100 + } 1.101 + 1.102 + // Note first "1, 0" for top-level class Test. 1.103 + @TADescriptions({ 1.104 + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, 1.105 + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0), 1.106 + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 1.107 + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0), 1.108 + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 1.109 + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0), 1.110 + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, 1.111 + genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0), 1.112 + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, 1.113 + genericLocation = {1, 0, 1, 0}, paramIndex = 0), 1.114 + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, 1.115 + genericLocation = {1, 0, 1, 0, 3, 0}, paramIndex = 0), 1.116 + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, 1.117 + genericLocation = {1, 0, 1, 0, 3, 1}, paramIndex = 0), 1.118 + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, 1.119 + genericLocation = {1, 0}, paramIndex = 0) 1.120 + }) 1.121 + public String testSpec5() { 1.122 + return "class Test { class O1 { class O2<A, B> { class O3 { class Nested<X, Y> {} } } }" + 1.123 + "void test(@TH O1.@TE O2<@TF String, @TG String>.@TD O3.@TA Nested<@TB String, @TC String> a) { } }"; 1.124 + } 1.125 +}