Fields.java revision 1533:bec996065c45
1/* 2 * Copyright (c) 2009, 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 24import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 25 26/* 27 * @test 28 * @summary Test population of reference info for field 29 * @compile -g Driver.java ReferenceInfoUtil.java Fields.java 30 * @run main Driver Fields 31 */ 32public class Fields { 33 34 // field types 35 @TADescription(annotation = "TA", type = FIELD) 36 public String fieldAsPrimitive() { 37 return "@TA int test;"; 38 } 39 40 @TADescription(annotation = "TA", type = FIELD) 41 public String fieldAsObject() { 42 return "@TA Object test;"; 43 } 44 45 @TADescriptions({ 46 @TADescription(annotation = "TA", type = FIELD), 47 @TADescription(annotation = "TB", type = FIELD, 48 genericLocation = { 3, 0 }), 49 @TADescription(annotation = "TC", type = FIELD, 50 genericLocation = { 3, 1 }), 51 @TADescription(annotation = "TD", type = FIELD, 52 genericLocation = { 3, 1, 3, 0 }) 53 }) 54 public String fieldAsParametrized() { 55 return "@TA Map<@TB String, @TC List<@TD String>> test;"; 56 } 57 58 @TADescriptions({ 59 @TADescription(annotation = "TA", type = FIELD), 60 @TADescription(annotation = "TB", type = FIELD, 61 genericLocation = { 0, 0 }), 62 @TADescription(annotation = "TC", type = FIELD, 63 genericLocation = { 0, 0, 0, 0 }) 64 }) 65 public String fieldAsArray() { 66 return "@TC String @TA [] @TB [] test;"; 67 } 68 69 @TADescriptions({ 70 @TADescription(annotation = "TA", type = FIELD), 71 @TADescription(annotation = "TB", type = FIELD, 72 genericLocation = { 0, 0 }), 73 @TADescription(annotation = "TC", type = FIELD, 74 genericLocation = { 0, 0, 0, 0 }) 75 }) 76 public String fieldAsArrayOld() { 77 return "@TC String test @TA [] @TB [];"; 78 } 79 80 @TADescriptions({}) 81 public String fieldWithDeclarationAnnotatin() { 82 return "@Decl String test;"; 83 } 84 85 @TADescriptions({}) 86 public String fieldWithNoTargetAnno() { 87 return "@A String test;"; 88 } 89 90 // Smoke tests 91 @TADescription(annotation = "TA", type = FIELD) 92 public String interfacefieldAsObject() { 93 return "interface Test { @TA String test = null; }"; 94 } 95 96 @TADescription(annotation = "TA", type = FIELD) 97 public String abstractfieldAsObject() { 98 return "abstract class Test { @TA String test; }"; 99 } 100 101 @TADescriptions({ 102 @TADescription(annotation = "TA", type = FIELD), 103 @TADescription(annotation = "TB", type = FIELD, 104 genericLocation = { 3, 0 }), 105 @TADescription(annotation = "TC", type = FIELD, 106 genericLocation = { 3, 1 }), 107 @TADescription(annotation = "TD", type = FIELD, 108 genericLocation = { 3, 1, 3, 0 }) 109 }) 110 public String interfacefieldAsParametrized() { 111 return "interface Test { @TA Map<@TB String, @TC List<@TD String>> test = null; }"; 112 } 113 114 115 @TADescriptions({ 116 @TADescription(annotation = "TA", type = FIELD), 117 @TADescription(annotation = "TB", type = FIELD, 118 genericLocation = { 3, 0 }), 119 @TADescription(annotation = "TC", type = FIELD, 120 genericLocation = { 3, 1 }), 121 @TADescription(annotation = "TD", type = FIELD, 122 genericLocation = { 3, 1, 3, 0 }) 123 }) 124 public String staticFieldAsParametrized() { 125 return "static @TA Map<@TB String, @TC List<@TD String>> test;"; 126 } 127 128} 129