|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, 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 | +package jdk.internal.vm.test; |
| 24 | + |
| 25 | +import java.lang.annotation.Annotation; |
| 26 | +import java.lang.annotation.Inherited; |
| 27 | +import java.lang.annotation.Repeatable; |
| 28 | +import java.lang.annotation.Retention; |
| 29 | +import java.lang.annotation.RetentionPolicy; |
| 30 | + |
| 31 | +public class AnnotationTestInput { |
| 32 | + |
| 33 | + enum Mood { |
| 34 | + HAPPY, |
| 35 | + SAD, |
| 36 | + CONFUSED; |
| 37 | + } |
| 38 | + |
| 39 | + private class PrivateClass {} |
| 40 | + |
| 41 | + @Single(string = "a", |
| 42 | + stringArray = {"a", "b"}, |
| 43 | + classValue = String.class, |
| 44 | + classArray = {String.class, Exception.class}, |
| 45 | + byteValue = 1, |
| 46 | + byteArray = {1, 2, Byte.MIN_VALUE, Byte.MAX_VALUE}, |
| 47 | + charValue = 'a', |
| 48 | + charArray = {'a', 'b', |
| 49 | + Character.MIN_VALUE, Character.MAX_VALUE, |
| 50 | + '\b', '\f', '\n', '\r', '\t', '\\', '\'', '\"', '\u012A'}, |
| 51 | + doubleValue = 3.3D, |
| 52 | + doubleArray = {3.3D, 4.4D, |
| 53 | + Double.MIN_VALUE, Double.MAX_VALUE, |
| 54 | + Double.NaN, |
| 55 | + Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, |
| 56 | + floatValue = 4.4F, |
| 57 | + floatArray = {4.4F, 5.5F, |
| 58 | + Float.MIN_VALUE, Float.MAX_VALUE, |
| 59 | + Float.NaN, |
| 60 | + Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, |
| 61 | + intValue = 5, |
| 62 | + intArray = {5, 6, Integer.MIN_VALUE, Integer.MAX_VALUE}, |
| 63 | + longValue = 6L, |
| 64 | + longArray = {6L, 7L, Long.MIN_VALUE, Long.MAX_VALUE}, |
| 65 | + shortValue = 7, |
| 66 | + shortArray = {7, 8, Short.MIN_VALUE, Short.MAX_VALUE}, |
| 67 | + booleanValue = true, |
| 68 | + booleanArray = {true, false}, |
| 69 | + mood = Mood.SAD, |
| 70 | + moodArray = {Mood.CONFUSED, Mood.HAPPY}, |
| 71 | + nested = @NestedAnno("nested1"), |
| 72 | + nestedArray = {@NestedAnno("nested2"), @NestedAnno("nested3")}) |
| 73 | + @Single(string = "A", |
| 74 | + stringArray = {"A", "B"}, |
| 75 | + classValue = Thread.class, |
| 76 | + classArray = {Thread.class, PrivateClass.class}, |
| 77 | + byteValue = -1, |
| 78 | + byteArray = {-1, -2}, |
| 79 | + charValue = 'A', |
| 80 | + charArray = {'a', 'b'}, |
| 81 | + doubleValue = -3.3D, |
| 82 | + doubleArray = {3.3D, 4.4D}, |
| 83 | + floatValue = -4.4F, |
| 84 | + floatArray = {4.4F, 5.5F}, |
| 85 | + intValue = -5, |
| 86 | + intArray = {5, 6}, |
| 87 | + longValue = -6L, |
| 88 | + longArray = {6L, 7L}, |
| 89 | + shortValue = -7, |
| 90 | + shortArray = {7, 8}, |
| 91 | + booleanValue = true, |
| 92 | + booleanArray = {true, false}, |
| 93 | + mood = Mood.CONFUSED, |
| 94 | + moodArray = {Mood.SAD, Mood.CONFUSED}, |
| 95 | + nested = @NestedAnno("nested4"), |
| 96 | + nestedArray = {@NestedAnno("nested5"), @NestedAnno("nested6")}) |
| 97 | + @SingleWithDefaults |
| 98 | + @Deprecated |
| 99 | + @SuppressWarnings("unchecked") |
| 100 | + public void annotatedMethod() { |
| 101 | + } |
| 102 | + |
| 103 | + @Named("Super1") |
| 104 | + public static class Super1 {} |
| 105 | + @Named("Super2") |
| 106 | + public static class Super2 extends Super1 {} |
| 107 | + public static class Super3 extends Super1 {} |
| 108 | + |
| 109 | + @Named("NonInheritedValue") |
| 110 | + public static class OwnName extends Super1 {} |
| 111 | + |
| 112 | + public static class InheritedName1 extends Super1 {} |
| 113 | + public static class InheritedName2 extends Super2 {} |
| 114 | + public static class InheritedName3 extends Super3 {} |
| 115 | + |
| 116 | + @Named("AnnotatedClass") |
| 117 | + @Single(string = "a", |
| 118 | + stringArray = {"a", "b"}, |
| 119 | + classValue = String.class, |
| 120 | + classArray = {String.class, Exception.class}, |
| 121 | + byteValue = 1, |
| 122 | + byteArray = {1, 2, Byte.MIN_VALUE, Byte.MAX_VALUE}, |
| 123 | + charValue = 'a', |
| 124 | + charArray = {'a', 'b', |
| 125 | + Character.MIN_VALUE, Character.MAX_VALUE, |
| 126 | + '\b', '\f', '\n', '\r', '\t', '\\', '\'', '\"', '\u012A'}, |
| 127 | + doubleValue = 3.3D, |
| 128 | + doubleArray = {3.3D, 4.4D, |
| 129 | + Double.MIN_VALUE, Double.MAX_VALUE, |
| 130 | + Double.NaN, |
| 131 | + Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, |
| 132 | + floatValue = 4.4F, |
| 133 | + floatArray = {4.4F, 5.5F, |
| 134 | + Float.MIN_VALUE, Float.MAX_VALUE, |
| 135 | + Float.NaN, |
| 136 | + Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, |
| 137 | + intValue = 5, |
| 138 | + intArray = {5, 6, Integer.MIN_VALUE, Integer.MAX_VALUE}, |
| 139 | + longValue = 6L, |
| 140 | + longArray = {6L, 7L, Long.MIN_VALUE, Long.MAX_VALUE}, |
| 141 | + shortValue = 7, |
| 142 | + shortArray = {7, 8, Short.MIN_VALUE, Short.MAX_VALUE}, |
| 143 | + booleanValue = true, |
| 144 | + booleanArray = {true, false}, |
| 145 | + mood = Mood.SAD, |
| 146 | + moodArray = {Mood.CONFUSED, Mood.HAPPY}, |
| 147 | + nested = @NestedAnno("nested7"), |
| 148 | + nestedArray = {@NestedAnno("nested8"), @NestedAnno("nested9")}) |
| 149 | + @Single(string = "A", |
| 150 | + stringArray = {"A", "B"}, |
| 151 | + classValue = Thread.class, |
| 152 | + classArray = {Thread.class, PrivateClass.class}, |
| 153 | + byteValue = -1, |
| 154 | + byteArray = {-1, -2}, |
| 155 | + charValue = 'A', |
| 156 | + charArray = {'a', 'b'}, |
| 157 | + doubleValue = -3.3D, |
| 158 | + doubleArray = {3.3D, 4.4D}, |
| 159 | + floatValue = -4.4F, |
| 160 | + floatArray = {4.4F, 5.5F}, |
| 161 | + intValue = -5, |
| 162 | + intArray = {5, 6}, |
| 163 | + longValue = -6L, |
| 164 | + longArray = {6L, 7L}, |
| 165 | + shortValue = -7, |
| 166 | + shortArray = {7, 8}, |
| 167 | + booleanValue = true, |
| 168 | + booleanArray = {true, false}, |
| 169 | + mood = Mood.CONFUSED, |
| 170 | + moodArray = {Mood.SAD, Mood.CONFUSED}, |
| 171 | + nested = @NestedAnno("nested10"), |
| 172 | + nestedArray = {@NestedAnno("nested11"), @NestedAnno("nested12")}) |
| 173 | + @Deprecated |
| 174 | + @SuppressWarnings({"rawtypes", "all"}) |
| 175 | + public static class AnnotatedClass {} |
| 176 | + |
| 177 | + @Single(string = "a", |
| 178 | + stringArray = {"a", "b"}, |
| 179 | + classValue = String.class, |
| 180 | + classArray = {String.class, Exception.class}, |
| 181 | + byteValue = 1, |
| 182 | + byteArray = {1, 2, Byte.MIN_VALUE, Byte.MAX_VALUE}, |
| 183 | + charValue = 'a', |
| 184 | + charArray = {'a', 'b', |
| 185 | + Character.MIN_VALUE, Character.MAX_VALUE, |
| 186 | + '\b', '\f', '\n', '\r', '\t', '\\', '\'', '\"', '\u012A'}, |
| 187 | + doubleValue = 3.3D, |
| 188 | + doubleArray = {3.3D, 4.4D, |
| 189 | + Double.MIN_VALUE, Double.MAX_VALUE, |
| 190 | + Double.NaN, |
| 191 | + Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, |
| 192 | + floatValue = 4.4F, |
| 193 | + floatArray = {4.4F, 5.5F, |
| 194 | + Float.MIN_VALUE, Float.MAX_VALUE, |
| 195 | + Float.NaN, |
| 196 | + Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, |
| 197 | + intValue = 5, |
| 198 | + intArray = {5, 6, Integer.MIN_VALUE, Integer.MAX_VALUE}, |
| 199 | + longValue = 6L, |
| 200 | + longArray = {6L, 7L, Long.MIN_VALUE, Long.MAX_VALUE}, |
| 201 | + shortValue = 7, |
| 202 | + shortArray = {7, 8, Short.MIN_VALUE, Short.MAX_VALUE}, |
| 203 | + booleanValue = true, |
| 204 | + booleanArray = {true, false}, |
| 205 | + mood = Mood.SAD, |
| 206 | + moodArray = {Mood.CONFUSED, Mood.HAPPY}, |
| 207 | + nested = @NestedAnno("nested12"), |
| 208 | + nestedArray = {@NestedAnno("nested13"), @NestedAnno("nested14")}) |
| 209 | + @Single(string = "A", |
| 210 | + stringArray = {"A", "B"}, |
| 211 | + classValue = Thread.class, |
| 212 | + classArray = {Thread.class, PrivateClass.class}, |
| 213 | + byteValue = -1, |
| 214 | + byteArray = {-1, -2}, |
| 215 | + charValue = 'A', |
| 216 | + charArray = {'a', 'b'}, |
| 217 | + doubleValue = -3.3D, |
| 218 | + doubleArray = {3.3D, 4.4D}, |
| 219 | + floatValue = -4.4F, |
| 220 | + floatArray = {4.4F, 5.5F}, |
| 221 | + intValue = -5, |
| 222 | + intArray = {5, 6}, |
| 223 | + longValue = -6L, |
| 224 | + longArray = {6L, 7L}, |
| 225 | + shortValue = -7, |
| 226 | + shortArray = {7, 8}, |
| 227 | + booleanValue = true, |
| 228 | + booleanArray = {true, false}, |
| 229 | + mood = Mood.CONFUSED, |
| 230 | + moodArray = {Mood.SAD, Mood.CONFUSED}, |
| 231 | + nested = @NestedAnno("nested15"), |
| 232 | + nestedArray = {@NestedAnno("nested16"), @NestedAnno("nested17")}) |
| 233 | + private static final int annotatedField = 45; |
| 234 | + |
| 235 | + @Retention(RetentionPolicy.RUNTIME) |
| 236 | + public @interface NestedAnno { |
| 237 | + String value(); |
| 238 | + } |
| 239 | + |
| 240 | + @Inherited |
| 241 | + @Retention(RetentionPolicy.RUNTIME) |
| 242 | + public @interface Named { |
| 243 | + String value(); |
| 244 | + } |
| 245 | + |
| 246 | + @Retention(RetentionPolicy.RUNTIME) |
| 247 | + @Repeatable(SingleList.class) |
| 248 | + public @interface Single { |
| 249 | + Class<?> classValue(); |
| 250 | + Class<?>[] classArray(); |
| 251 | + |
| 252 | + String string(); |
| 253 | + String[] stringArray(); |
| 254 | + |
| 255 | + byte byteValue(); |
| 256 | + byte[] byteArray(); |
| 257 | + |
| 258 | + char charValue(); |
| 259 | + char[] charArray(); |
| 260 | + |
| 261 | + double doubleValue(); |
| 262 | + double[] doubleArray(); |
| 263 | + |
| 264 | + float floatValue(); |
| 265 | + float[] floatArray(); |
| 266 | + |
| 267 | + int intValue(); |
| 268 | + int[] intArray(); |
| 269 | + |
| 270 | + long longValue(); |
| 271 | + long[] longArray(); |
| 272 | + |
| 273 | + short shortValue(); |
| 274 | + short[] shortArray(); |
| 275 | + |
| 276 | + boolean booleanValue(); |
| 277 | + boolean[] booleanArray(); |
| 278 | + |
| 279 | + Mood mood(); |
| 280 | + Mood[] moodArray(); |
| 281 | + |
| 282 | + NestedAnno nested(); |
| 283 | + NestedAnno[] nestedArray(); |
| 284 | + } |
| 285 | + |
| 286 | + @Retention(RetentionPolicy.RUNTIME) |
| 287 | + @interface SingleWithDefaults { |
| 288 | + Class<?> classValue() default SingleWithDefaults.class; |
| 289 | + Class<?>[] classArray() default {}; |
| 290 | + |
| 291 | + String string() default "anonymous"; |
| 292 | + String[] stringArray() default {}; |
| 293 | + |
| 294 | + byte byteValue() default 101; |
| 295 | + byte[] byteArray() default {}; |
| 296 | + |
| 297 | + char charValue() default 'Z'; |
| 298 | + char[] charArray() default {}; |
| 299 | + |
| 300 | + double doubleValue() default 102.102D; |
| 301 | + double[] doubleArray() default {}; |
| 302 | + |
| 303 | + float floatValue() default 103.103F; |
| 304 | + float[] floatArray() default {}; |
| 305 | + |
| 306 | + int intValue() default 104; |
| 307 | + int[] intArray() default {}; |
| 308 | + |
| 309 | + long longValue() default 105L; |
| 310 | + long[] longArray() default {}; |
| 311 | + |
| 312 | + short shortValue() default 105; |
| 313 | + short[] shortArray() default {}; |
| 314 | + |
| 315 | + boolean booleanValue() default true; |
| 316 | + boolean[] booleanArray() default {}; |
| 317 | + |
| 318 | + Mood mood() default Mood.HAPPY; |
| 319 | + Mood[] moodArray() default {}; |
| 320 | + } |
| 321 | + |
| 322 | + @Retention(RetentionPolicy.RUNTIME) |
| 323 | + public @interface SingleList { |
| 324 | + Single[] value(); |
| 325 | + } |
| 326 | + |
| 327 | + @Retention(RetentionPolicy.RUNTIME) |
| 328 | + public @interface Missing {} |
| 329 | + |
| 330 | + @Retention(RetentionPolicy.RUNTIME) |
| 331 | + public @interface MissingWrapper { |
| 332 | + Missing value(); |
| 333 | + } |
| 334 | + |
| 335 | + @Retention(RetentionPolicy.RUNTIME) |
| 336 | + public @interface MissingContainer { |
| 337 | + Class<?> value(); |
| 338 | + } |
| 339 | + |
| 340 | + /** |
| 341 | + * Method with a directly missing annotation. |
| 342 | + */ |
| 343 | + @Missing |
| 344 | + public void missingAnnotation() {} |
| 345 | + |
| 346 | + /** |
| 347 | + * Method with an indirectly missing nested annotation. |
| 348 | + */ |
| 349 | + @MissingWrapper(@Missing) |
| 350 | + public void missingNestedAnnotation() {} |
| 351 | + |
| 352 | + /** |
| 353 | + * Method with an annotation that has a Class member |
| 354 | + * that cannot be resolved. |
| 355 | + */ |
| 356 | + @MissingContainer(Missing.class) |
| 357 | + public void missingTypeOfClassMember() {} |
| 358 | + |
| 359 | + /** |
| 360 | + * Method with an annotation that has a member |
| 361 | + * that is deleted in a newer version of the annotation. |
| 362 | + */ |
| 363 | + @MemberDeleted(value = "evolving", retained = -34, deleted = 56) |
| 364 | + public void missingMember() {} |
| 365 | + |
| 366 | + /** |
| 367 | + * Method with an annotation that has a member named "any" |
| 368 | + * whose type is changed from int to String in a newer version |
| 369 | + * of the annotation. |
| 370 | + */ |
| 371 | + @MemberTypeChanged(value = "evolving", retained = -34, any = 56) |
| 372 | + public void changeTypeOfMember() {} |
| 373 | + |
| 374 | +} |
| 375 | + |
0 commit comments