1 /* |
1 /* |
2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
33 import java.util.*; |
33 import java.util.*; |
34 |
34 |
35 public class GenericStringTest { |
35 public class GenericStringTest { |
36 public static void main(String argv[]) throws Exception { |
36 public static void main(String argv[]) throws Exception { |
37 int failures = 0; |
37 int failures = 0; |
38 List<Class<?>> classList = new LinkedList<Class<?>>(); |
|
39 classList.add(TestClass1.class); |
|
40 classList.add(TestClass2.class); |
|
41 classList.add(Roebling.class); |
|
42 classList.add(TestInterface1.class); |
|
43 |
38 |
44 |
39 for(Class<?> clazz: List.of(TestClass1.class, TestClass2.class, |
45 for(Class<?> clazz: classList) |
40 Roebling.class, TestInterface1.class)) |
46 for(Method method: clazz.getDeclaredMethods()) { |
41 for(Method method: clazz.getDeclaredMethods()) { |
47 ExpectedGenericString egs = method.getAnnotation(ExpectedGenericString.class); |
42 ExpectedGenericString egs = method.getAnnotation(ExpectedGenericString.class); |
48 if (egs != null) { |
43 if (egs != null) { |
49 String actual = method.toGenericString(); |
44 String actual = method.toGenericString(); |
50 System.out.println(actual); |
45 System.out.println(actual); |
119 public <T> T method1(E e, T t) {return null;} |
114 public <T> T method1(E e, T t) {return null;} |
120 |
115 |
121 @ExpectedGenericString( |
116 @ExpectedGenericString( |
122 "public void TestClass2.method2() throws F") |
117 "public void TestClass2.method2() throws F") |
123 public void method2() throws F {return;} |
118 public void method2() throws F {return;} |
|
119 |
|
120 @ExpectedGenericString( |
|
121 "public E[] TestClass2.method3()") |
|
122 public E[] method3() {return null;} |
|
123 |
|
124 @ExpectedGenericString( |
|
125 "public E[][] TestClass2.method4()") |
|
126 public E[][] method4() {return null;} |
|
127 |
|
128 @ExpectedGenericString( |
|
129 "public java.util.List<E[]> TestClass2.method5()") |
|
130 public List<E[]> method5() {return null;} |
|
131 |
|
132 @ExpectedGenericString( |
|
133 "public java.util.List<?> TestClass2.method6()") |
|
134 public List<?> method6() {return null;} |
|
135 |
|
136 @ExpectedGenericString( |
|
137 "public java.util.List<?>[] TestClass2.method7()") |
|
138 public List<?>[] method7() {return null;} |
|
139 |
|
140 @ExpectedGenericString( |
|
141 "public <K,V> java.util.Map<K, V> TestClass2.method8()") |
|
142 public <K, V> Map<K, V> method8() {return null;} |
124 } |
143 } |
125 |
144 |
126 class Roebling implements Comparable<Roebling> { |
145 class Roebling implements Comparable<Roebling> { |
127 @ExpectedGenericString( |
146 @ExpectedGenericString( |
128 value="public int Roebling.compareTo(Roebling)", |
147 value="public int Roebling.compareTo(Roebling)", |
155 @ExpectedString( |
174 @ExpectedString( |
156 "public default strictfp double TestInterface1.quux()") |
175 "public default strictfp double TestInterface1.quux()") |
157 @ExpectedGenericString( |
176 @ExpectedGenericString( |
158 "public default strictfp double TestInterface1.quux()") |
177 "public default strictfp double TestInterface1.quux()") |
159 strictfp default double quux(){return 1.0;} |
178 strictfp default double quux(){return 1.0;} |
160 |
|
161 } |
179 } |
162 |
180 |
163 @Retention(RetentionPolicy.RUNTIME) |
181 @Retention(RetentionPolicy.RUNTIME) |
164 @interface ExpectedGenericString { |
182 @interface ExpectedGenericString { |
165 String value(); |
183 String value(); |