1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,128 @@ 1.4 +/* 1.5 + * Copyright (c) 2009, 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 population of reference info for field 1.32 + * @compile -g Driver.java ReferenceInfoUtil.java Fields.java 1.33 + * @run main Driver Fields 1.34 + */ 1.35 +public class Fields { 1.36 + 1.37 + // field types 1.38 + @TADescription(annotation = "TA", type = FIELD) 1.39 + public String fieldAsPrimitive() { 1.40 + return "@TA int test;"; 1.41 + } 1.42 + 1.43 + @TADescription(annotation = "TA", type = FIELD) 1.44 + public String fieldAsObject() { 1.45 + return "@TA Object test;"; 1.46 + } 1.47 + 1.48 + @TADescriptions({ 1.49 + @TADescription(annotation = "TA", type = FIELD), 1.50 + @TADescription(annotation = "TB", type = FIELD, 1.51 + genericLocation = { 3, 0 }), 1.52 + @TADescription(annotation = "TC", type = FIELD, 1.53 + genericLocation = { 3, 1 }), 1.54 + @TADescription(annotation = "TD", type = FIELD, 1.55 + genericLocation = { 3, 1, 3, 0 }) 1.56 + }) 1.57 + public String fieldAsParametrized() { 1.58 + return "@TA Map<@TB String, @TC List<@TD String>> test;"; 1.59 + } 1.60 + 1.61 + @TADescriptions({ 1.62 + @TADescription(annotation = "TA", type = FIELD), 1.63 + @TADescription(annotation = "TB", type = FIELD, 1.64 + genericLocation = { 0, 0 }), 1.65 + @TADescription(annotation = "TC", type = FIELD, 1.66 + genericLocation = { 0, 0, 0, 0 }) 1.67 + }) 1.68 + public String fieldAsArray() { 1.69 + return "@TC String @TA [] @TB [] test;"; 1.70 + } 1.71 + 1.72 + @TADescriptions({ 1.73 + @TADescription(annotation = "TA", type = FIELD), 1.74 + @TADescription(annotation = "TB", type = FIELD, 1.75 + genericLocation = { 0, 0 }), 1.76 + @TADescription(annotation = "TC", type = FIELD, 1.77 + genericLocation = { 0, 0, 0, 0 }) 1.78 + }) 1.79 + public String fieldAsArrayOld() { 1.80 + return "@TC String test @TA [] @TB [];"; 1.81 + } 1.82 + 1.83 + @TADescriptions({}) 1.84 + public String fieldWithDeclarationAnnotatin() { 1.85 + return "@Decl String test;"; 1.86 + } 1.87 + 1.88 + @TADescriptions({}) 1.89 + public String fieldWithNoTargetAnno() { 1.90 + return "@A String test;"; 1.91 + } 1.92 + 1.93 + // Smoke tests 1.94 + @TADescription(annotation = "TA", type = FIELD) 1.95 + public String interfacefieldAsObject() { 1.96 + return "interface Test { @TA String test = null; }"; 1.97 + } 1.98 + 1.99 + @TADescription(annotation = "TA", type = FIELD) 1.100 + public String abstractfieldAsObject() { 1.101 + return "abstract class Test { @TA String test; }"; 1.102 + } 1.103 + 1.104 + @TADescriptions({ 1.105 + @TADescription(annotation = "TA", type = FIELD), 1.106 + @TADescription(annotation = "TB", type = FIELD, 1.107 + genericLocation = { 3, 0 }), 1.108 + @TADescription(annotation = "TC", type = FIELD, 1.109 + genericLocation = { 3, 1 }), 1.110 + @TADescription(annotation = "TD", type = FIELD, 1.111 + genericLocation = { 3, 1, 3, 0 }) 1.112 + }) 1.113 + public String interfacefieldAsParametrized() { 1.114 + return "interface Test { @TA Map<@TB String, @TC List<@TD String>> test = null; }"; 1.115 + } 1.116 + 1.117 + 1.118 + @TADescriptions({ 1.119 + @TADescription(annotation = "TA", type = FIELD), 1.120 + @TADescription(annotation = "TB", type = FIELD, 1.121 + genericLocation = { 3, 0 }), 1.122 + @TADescription(annotation = "TC", type = FIELD, 1.123 + genericLocation = { 3, 1 }), 1.124 + @TADescription(annotation = "TD", type = FIELD, 1.125 + genericLocation = { 3, 1, 3, 0 }) 1.126 + }) 1.127 + public String staticFieldAsParametrized() { 1.128 + return "static @TA Map<@TB String, @TC List<@TD String>> test;"; 1.129 + } 1.130 + 1.131 +}