Fields.java revision 2453:3dfd962149b2
1169689Skan/* 2169689Skan * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. 3169689Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4169689Skan * 5169689Skan * This code is free software; you can redistribute it and/or modify it 6169689Skan * under the terms of the GNU General Public License version 2 only, as 7169689Skan * published by the Free Software Foundation. 8169689Skan * 9169689Skan * This code is distributed in the hope that it will be useful, but WITHOUT 10169689Skan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11169689Skan * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12169689Skan * version 2 for more details (a copy is included in the LICENSE file that 13169689Skan * accompanied this code). 14169689Skan * 15169689Skan * You should have received a copy of the GNU General Public License version 16169689Skan * 2 along with this work; if not, write to the Free Software Foundation, 17169689Skan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18169689Skan * 19169689Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20169689Skan * or visit www.oracle.com if you need additional information or have any 21169689Skan * questions. 22169689Skan */ 23169689Skan 24169689Skanimport static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 25169689Skan 26169689Skan/* 27169689Skan * @test 28169689Skan * @summary Test population of reference info for field 29169689Skan * @compile -g Driver.java ReferenceInfoUtil.java Fields.java 30169689Skan * @run main Driver Fields 31169689Skan */ 32169689Skanpublic class Fields { 33169689Skan // field types 34169689Skan @TADescription(annotation = "TA", type = FIELD) 35169689Skan public String fieldAsPrimitive() { 36169689Skan return "@TA int test;"; 37169689Skan } 38169689Skan 39169689Skan @TADescription(annotation = "TA", type = FIELD) 40169689Skan public String fieldAsObject() { 41169689Skan return "@TA Object test;"; 42169689Skan } 43169689Skan 44169689Skan @TADescriptions({ 45169689Skan @TADescription(annotation = "TA", type = FIELD), 46169689Skan @TADescription(annotation = "TB", type = FIELD, 47 genericLocation = { 3, 0 }), 48 @TADescription(annotation = "TC", type = FIELD, 49 genericLocation = { 3, 1 }), 50 @TADescription(annotation = "TD", type = FIELD, 51 genericLocation = { 3, 1, 3, 0 }) 52 }) 53 public String fieldAsParametrized() { 54 return "@TA Map<@TB String, @TC List<@TD String>> test;"; 55 } 56 57 @TADescriptions({ 58 @TADescription(annotation = "TA", type = FIELD), 59 @TADescription(annotation = "TB", type = FIELD, 60 genericLocation = { 0, 0 }), 61 @TADescription(annotation = "TC", type = FIELD, 62 genericLocation = { 0, 0, 0, 0 }) 63 }) 64 public String fieldAsArray() { 65 return "@TC String @TA [] @TB [] test;"; 66 } 67 68 @TADescriptions({ 69 @TADescription(annotation = "TA", type = FIELD), 70 @TADescription(annotation = "TB", type = FIELD, 71 genericLocation = { 0, 0 }), 72 @TADescription(annotation = "TC", type = FIELD, 73 genericLocation = { 0, 0, 0, 0 }) 74 }) 75 public String fieldAsArrayOld() { 76 return "@TC String test @TA [] @TB [];"; 77 } 78 79 @TADescriptions({}) 80 public String fieldWithDeclarationAnnotatin() { 81 return "@Decl String test;"; 82 } 83 84 @TADescriptions({}) 85 public String fieldWithNoTargetAnno() { 86 return "@A String test;"; 87 } 88 89 // Smoke tests 90 @TADescription(annotation = "TA", type = FIELD) 91 public String interfacefieldAsObject() { 92 return "interface Test { @TA String test = null; }"; 93 } 94 95 @TADescription(annotation = "TA", type = FIELD) 96 public String abstractfieldAsObject() { 97 return "abstract class Test { @TA String test; }"; 98 } 99 100 @TADescriptions({ 101 @TADescription(annotation = "TA", type = FIELD), 102 @TADescription(annotation = "TB", type = FIELD, 103 genericLocation = { 3, 0 }), 104 @TADescription(annotation = "TC", type = FIELD, 105 genericLocation = { 3, 1 }), 106 @TADescription(annotation = "TD", type = FIELD, 107 genericLocation = { 3, 1, 3, 0 }) 108 }) 109 public String interfacefieldAsParametrized() { 110 return "interface Test { @TA Map<@TB String, @TC List<@TD String>> test = null; }"; 111 } 112 113 114 @TADescriptions({ 115 @TADescription(annotation = "TA", type = FIELD), 116 @TADescription(annotation = "TB", type = FIELD, 117 genericLocation = { 3, 0 }), 118 @TADescription(annotation = "TC", type = FIELD, 119 genericLocation = { 3, 1 }), 120 @TADescription(annotation = "TD", type = FIELD, 121 genericLocation = { 3, 1, 3, 0 }) 122 }) 123 public String staticFieldAsParametrized() { 124 return "static @TA Map<@TB String, @TC List<@TD String>> test;"; 125 } 126} 127