1 /* 2 * Copyright (c) 2018, 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 24 /* 25 * @test 26 * @bug 8058202 27 * @summary Test java.lang.Object methods on AnnotatedType's. 28 */ 29 30 import java.lang.reflect.*; 31 import java.util.*; 32 33 /* 34 * Testing notes: see if type.toString() is a postfix of AnnotatedType.toString() 35 36 * For the annotations, for multiple annotations, compare with 37 * a runtime construction since the order of annotations from 38 * getAnnotations is not specified. 39 */ 40 41 42 /** 43 * Test toString, equals, and hashCode on various AnnotatedType objects. 44 */ 45 public class TestObjectMethods { 46 47 public static void main(String... args) { 48 testToString(); 49 } 50 51 static void testToString() { 52 Method[] methods = TypeAnnotationHost.class.getDeclaredMethods(); 53 for (Method m : methods) { 54 AnnotatedType annotType = m.getAnnotatedReturnType(); 55 String annotTypeString = annotType.toString(); 56 57 Type type = m.getGenericReturnType(); 58 String typeString = type.toString(); 59 60 System.out.println(typeString + "\t\t" + annotTypeString + 61 "\t" + annotTypeString.endsWith(typeString)); 62 } 63 } 64 65 /* 66 * There are various subtypes of AnnotatedType implementations: 67 * 68 * AnnotatedType 69 * AnnotatedArrayType 70 * AnnotatedParameterizedType 71 * AnnotatedTypeVariable 72 * AnnotatedWildcardType 73 * 74 * The implementations of each these implementions should be examined. 75 */ 76 77 static class TypeAnnotationHost<E, F extends Number> { 78 public int foo() {return 0;} 79 public String fooString() {return null;} 80 81 public int[] fooIntArray() {return null;} 82 public String[] fooStringArray() {return null;} 83 84 public Set<String> fooSetString() {return null;} 85 public E fooE() {return null;} 86 public F fooF() {return null;} 87 public <G> G fooG() {return null;} 88 89 public Set<? extends Number> fooNumberSet() {return null;} 90 public Set<? extends Number> fooNumberSet2() {return null;} 91 } 92 }