1 /* 2 * Copyright (c) 2004, 2016, 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 5033583 6316717 6470106 8004979 8161500 8162539 27 * @summary Check toGenericString() and toString() methods 28 * @author Joseph D. Darcy 29 */ 30 31 import java.lang.reflect.*; 32 import java.lang.annotation.*; 33 import java.util.*; 34 35 public class GenericStringTest { 36 public static void main(String argv[]) throws Exception { 37 int failures = 0; 38 39 for(Class<?> clazz: List.of(TestClass1.class, TestClass2.class, 40 Roebling.class, TestInterface1.class)) 41 for(Method method: clazz.getDeclaredMethods()) { 42 ExpectedGenericString egs = method.getAnnotation(ExpectedGenericString.class); 43 if (egs != null) { 44 String actual = method.toGenericString(); 45 System.out.println(actual); 46 if (method.isBridge()) { 86 return 0; 87 } 88 } 89 90 class TestClass1 { 91 @ExpectedGenericString( 92 "void TestClass1.method1(int,double)") 93 void method1(int x, double y) {} 94 95 @ExpectedGenericString( 96 "private static java.lang.String TestClass1.method2(int,int)") 97 private static String method2(int x, int param2) {return null;} 98 99 @ExpectedGenericString( 100 "static void TestClass1.method3() throws java.lang.RuntimeException") 101 static void method3() throws RuntimeException {return;} 102 103 @ExpectedGenericString( 104 "protected <S,T> S TestClass1.method4(S,T) throws java.lang.Exception") 105 protected <S, T> S method4(S s, T t) throws Exception {return null;} 106 } 107 108 class TestClass2<E, F extends Exception> { 109 @ExpectedGenericString( 110 "public <T> T TestClass2.method1(E,T)") 111 public <T> T method1(E e, T t) {return null;} 112 113 @ExpectedGenericString( 114 "public void TestClass2.method2() throws F") 115 @ExpectedString( 116 "public void TestClass2.method2() throws java.lang.Exception") 117 public void method2() throws F {return;} 118 119 @ExpectedGenericString( 120 "public E[] TestClass2.method3()") 121 public E[] method3() {return null;} 122 123 @ExpectedGenericString( 124 "public E[][] TestClass2.method4()") 125 public E[][] method4() {return null;} 126 127 @ExpectedGenericString( 128 "public java.util.List<E[]> TestClass2.method5()") 129 public List<E[]> method5() {return null;} 130 131 @ExpectedGenericString( 132 "public java.util.List<?> TestClass2.method6()") 133 public List<?> method6() {return null;} 134 135 @ExpectedGenericString( 136 "public java.util.List<?>[] TestClass2.method7()") 137 public List<?>[] method7() {return null;} 138 139 @ExpectedGenericString( 140 "public <K,V> java.util.Map<K, V> TestClass2.method8()") 141 public <K, V> Map<K, V> method8() {return null;} 142 } 143 144 class Roebling implements Comparable<Roebling> { 145 @ExpectedGenericString( 146 value="public int Roebling.compareTo(Roebling)", 147 bridgeValue="public int Roebling.compareTo(java.lang.Object)") 148 public int compareTo(Roebling r) { 149 throw new IllegalArgumentException(); 150 } 151 152 // Not a transient method, (transient var-arg overlap) 153 @ExpectedGenericString( 154 "void Roebling.varArg(java.lang.Object...)") 155 @ExpectedString( 156 "void Roebling.varArg(java.lang.Object[])") 157 void varArg(Object ... arg) {} 158 } 159 160 interface TestInterface1 { 161 @ExpectedGenericString( | 1 /* 2 * Copyright (c) 2004, 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 5033583 6316717 6470106 8004979 8161500 8162539 6304578 27 * @summary Check toGenericString() and toString() methods 28 * @author Joseph D. Darcy 29 */ 30 31 import java.lang.reflect.*; 32 import java.lang.annotation.*; 33 import java.util.*; 34 35 public class GenericStringTest { 36 public static void main(String argv[]) throws Exception { 37 int failures = 0; 38 39 for(Class<?> clazz: List.of(TestClass1.class, TestClass2.class, 40 Roebling.class, TestInterface1.class)) 41 for(Method method: clazz.getDeclaredMethods()) { 42 ExpectedGenericString egs = method.getAnnotation(ExpectedGenericString.class); 43 if (egs != null) { 44 String actual = method.toGenericString(); 45 System.out.println(actual); 46 if (method.isBridge()) { 86 return 0; 87 } 88 } 89 90 class TestClass1 { 91 @ExpectedGenericString( 92 "void TestClass1.method1(int,double)") 93 void method1(int x, double y) {} 94 95 @ExpectedGenericString( 96 "private static java.lang.String TestClass1.method2(int,int)") 97 private static String method2(int x, int param2) {return null;} 98 99 @ExpectedGenericString( 100 "static void TestClass1.method3() throws java.lang.RuntimeException") 101 static void method3() throws RuntimeException {return;} 102 103 @ExpectedGenericString( 104 "protected <S,T> S TestClass1.method4(S,T) throws java.lang.Exception") 105 protected <S, T> S method4(S s, T t) throws Exception {return null;} 106 107 @ExpectedGenericString( 108 "public static <T> T TestClass1.max(java.util.Collection<? extends T>,java.util.Comparator<? super T>)") 109 public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {return null;} 110 } 111 112 class TestClass2<E, F extends Exception> { 113 @ExpectedGenericString( 114 "public <T> T TestClass2.method1(E,T)") 115 public <T> T method1(E e, T t) {return null;} 116 117 @ExpectedGenericString( 118 "public void TestClass2.method2() throws F") 119 @ExpectedString( 120 "public void TestClass2.method2() throws java.lang.Exception") 121 public void method2() throws F {return;} 122 123 @ExpectedGenericString( 124 "public E[] TestClass2.method3()") 125 public E[] method3() {return null;} 126 127 @ExpectedGenericString( 128 "public E[][] TestClass2.method4()") 129 public E[][] method4() {return null;} 130 131 @ExpectedGenericString( 132 "public java.util.List<E[]> TestClass2.method5()") 133 public List<E[]> method5() {return null;} 134 135 @ExpectedGenericString( 136 "public java.util.List<?> TestClass2.method6()") 137 public List<?> method6() {return null;} 138 139 @ExpectedGenericString( 140 "public java.util.List<?>[] TestClass2.method7()") 141 public List<?>[] method7() {return null;} 142 143 @ExpectedGenericString( 144 "public <K,V> java.util.Map<K, V> TestClass2.method8()") 145 public <K, V> Map<K, V> method8() {return null;} 146 147 @ExpectedGenericString( 148 "public <V extends java.lang.Number & java.lang.Runnable> java.util.Set<V> TestClass2.method9(V)") 149 public <V extends Number & Runnable> Set<V> method9(V v) {return null;} 150 } 151 152 class Roebling implements Comparable<Roebling> { 153 @ExpectedGenericString( 154 value="public int Roebling.compareTo(Roebling)", 155 bridgeValue="public int Roebling.compareTo(java.lang.Object)") 156 public int compareTo(Roebling r) { 157 throw new IllegalArgumentException(); 158 } 159 160 // Not a transient method, (transient var-arg overlap) 161 @ExpectedGenericString( 162 "void Roebling.varArg(java.lang.Object...)") 163 @ExpectedString( 164 "void Roebling.varArg(java.lang.Object[])") 165 void varArg(Object ... arg) {} 166 } 167 168 interface TestInterface1 { 169 @ExpectedGenericString( |