1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/apt/mirror/declaration/AnnoVal.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,200 @@ 1.4 +/* 1.5 + * Copyright 2004-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 + 1.28 +/* 1.29 + * @test 1.30 + * @bug 4853450 5014539 5034991 1.31 + * @summary Tests AnnotationValue methods. 1.32 + * @library ../../lib 1.33 + * @compile -source 1.5 AnnoVal.java 1.34 + * @run main AnnoVal 1.35 + */ 1.36 + 1.37 + 1.38 +import java.util.*; 1.39 +import com.sun.mirror.declaration.*; 1.40 +import com.sun.mirror.type.*; 1.41 + 1.42 + 1.43 +public class AnnoVal extends Tester { 1.44 + 1.45 + public static void main(String[] args) { 1.46 + (new AnnoVal()).run(); 1.47 + } 1.48 + 1.49 + @Test(result={ 1.50 + "i Integer 2", 1.51 + "l Long 4294967296", 1.52 + "d Double 3.14", 1.53 + "b Boolean true", 1.54 + "c Character @", 1.55 + "s String sigh", 1.56 + // The following results reflect some implementation details. 1.57 + "k ClassTypeImpl java.lang.Boolean", 1.58 + "kb PrimitiveTypeImpl boolean", 1.59 + "ka ArrayTypeImpl java.lang.Boolean[]", 1.60 + "kab ArrayTypeImpl int[][]", 1.61 + "w ClassTypeImpl java.lang.Long", 1.62 + "e EnumConstantDeclarationImpl TYPE", 1.63 + "sa ArrayList [\"up\", \"down\"]", 1.64 + "a AnnotationMirrorImpl @AT1"}) 1.65 + @AT2(i = 1 + 1, 1.66 + l = 1024 * 1024 * 1024 * 4L, 1.67 + d = 3.14, 1.68 + b = true, 1.69 + c = '@', 1.70 + s = "sigh", 1.71 + k = Boolean.class, 1.72 + kb = boolean.class, 1.73 + ka = Boolean[].class, // bugid 5020899 1.74 + kab = int[][].class, // " 1.75 + w = Long.class, 1.76 + e = java.lang.annotation.ElementType.TYPE, 1.77 + sa = {"up", "down"}, 1.78 + a = @AT1) 1.79 + Collection<String> getValue() { 1.80 + Collection<String> res = new ArrayList<String>(); 1.81 + AnnotationMirror anno = getAnno("getValue", "AT2"); 1.82 + 1.83 + for (Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> e : 1.84 + anno.getElementValues().entrySet()) { 1.85 + Object val = e.getValue().getValue(); 1.86 + res.add(String.format("%s %s %s", 1.87 + e.getKey().getSimpleName(), 1.88 + simpleClassName(val), 1.89 + val)); 1.90 + } 1.91 + return res; 1.92 + } 1.93 + 1.94 + @Test(result={ 1.95 + "int i 2", 1.96 + "long l 4294967296L", 1.97 + "double d 3.14", 1.98 + "boolean b true", 1.99 + "char c '@'", 1.100 + "java.lang.String s \"sigh\"", 1.101 + "java.lang.Class k java.lang.Boolean.class", 1.102 + "java.lang.Class kb boolean.class", 1.103 + "java.lang.Class ka java.lang.Boolean[].class", 1.104 + "java.lang.Class kab int[][].class", 1.105 + "java.lang.Class<? extends java.lang.Number> w java.lang.Long.class", 1.106 + "java.lang.annotation.ElementType e java.lang.annotation.ElementType.TYPE", 1.107 + "java.lang.String[] sa {\"up\", \"down\"}", 1.108 + "AT1 a @AT1"}) 1.109 + Collection<String> toStringTests() { 1.110 + Collection<String> res = new ArrayList<String>(); 1.111 + AnnotationMirror anno = getAnno("getValue", "AT2"); 1.112 + 1.113 + for (Map.Entry<AnnotationTypeElementDeclaration,AnnotationValue> e : 1.114 + anno.getElementValues().entrySet()) { 1.115 + res.add(String.format("%s %s %s", 1.116 + e.getKey().getReturnType(), 1.117 + e.getKey().getSimpleName(), 1.118 + e.getValue().toString())); 1.119 + } 1.120 + return res; 1.121 + } 1.122 + 1.123 + @Test(result={ 1.124 + "byte b 0x0b", 1.125 + "float f 3.0f", 1.126 + "double nan 0.0/0.0", 1.127 + "double hi 1.0/0.0", 1.128 + "float lo -1.0f/0.0f", 1.129 + "char newline '\\n'", 1.130 + "char ff '\\u00ff'", 1.131 + "java.lang.String s \"\\\"high\\tlow\\\"\"", 1.132 + "java.lang.String smiley \"\\u263a\""}) 1.133 + @AT3(b = 11, 1.134 + f = 3, 1.135 + nan = 0.0/0.0, 1.136 + hi = 1.0/0.0, 1.137 + lo = -1.0f/0.0f, 1.138 + newline = '\n', 1.139 + ff = '\u00FF', 1.140 + s = "\"high\tlow\"", 1.141 + smiley = "\u263A") 1.142 + Collection<String> toStringFancy() { 1.143 + Collection<String> res = new ArrayList<String>(); 1.144 + AnnotationMirror anno = getAnno("toStringFancy", "AT3"); 1.145 + 1.146 + for (Map.Entry<AnnotationTypeElementDeclaration,AnnotationValue> e : 1.147 + anno.getElementValues().entrySet()) { 1.148 + res.add(String.format("%s %s %s", 1.149 + e.getKey().getReturnType(), 1.150 + e.getKey().getSimpleName(), 1.151 + e.getValue().toString())); 1.152 + } 1.153 + return res; 1.154 + } 1.155 + 1.156 + 1.157 + /** 1.158 + * Returns the simple name of an object's class. 1.159 + */ 1.160 + private String simpleClassName(Object o) { 1.161 + return (o == null) 1.162 + ? "null" 1.163 + : o.getClass().getName().replaceFirst(".*\\.", ""); 1.164 + } 1.165 +} 1.166 + 1.167 + 1.168 +/* 1.169 + * Annotations used for testing. 1.170 + */ 1.171 + 1.172 +@interface AT1 { 1.173 + String value() default ""; 1.174 +} 1.175 + 1.176 +@interface AT2 { 1.177 + int i(); 1.178 + long l(); 1.179 + double d(); 1.180 + boolean b(); 1.181 + char c(); 1.182 + String s(); 1.183 + Class k(); 1.184 + Class kb(); 1.185 + Class ka(); 1.186 + Class kab(); 1.187 + Class<? extends Number> w(); 1.188 + java.lang.annotation.ElementType e(); 1.189 + String[] sa(); 1.190 + AT1 a(); 1.191 +} 1.192 + 1.193 +@interface AT3 { 1.194 + byte b(); 1.195 + float f(); 1.196 + double nan(); 1.197 + double hi(); 1.198 + float lo(); 1.199 + char newline(); 1.200 + char ff(); 1.201 + String s(); 1.202 + String smiley(); 1.203 +}