|
1 /* |
|
2 * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 5012133 |
|
27 * @summary Check Class.isSynthetic method |
|
28 * @author Joseph D. Darcy |
|
29 */ |
|
30 |
|
31 import java.lang.reflect.*; |
|
32 |
|
33 public class IsSynthetic { |
|
34 |
|
35 static class NestedClass { |
|
36 } |
|
37 |
|
38 static int test(Class<?> clazz, boolean expected) { |
|
39 if (clazz.isSynthetic() == expected) |
|
40 return 0; |
|
41 else { |
|
42 System.err.println("Unexpected synthetic status for " + |
|
43 clazz.getName() + " expected: " + expected + |
|
44 " got: " + (!expected)); |
|
45 return 1; |
|
46 } |
|
47 } |
|
48 |
|
49 public static void main(String argv[]) { |
|
50 int failures = 0; |
|
51 class LocalClass {} |
|
52 |
|
53 Cloneable clone = new Cloneable() {}; |
|
54 |
|
55 failures += test(IsSynthetic.class, false); |
|
56 failures += test(java.lang.String.class, false); |
|
57 failures += test(LocalClass.class, false); |
|
58 failures += test(NestedClass.class, false); |
|
59 failures += test(clone.getClass(), false); |
|
60 |
|
61 for(Constructor c: Tricky.class.getDeclaredConstructors()) { |
|
62 Class<?>[] paramTypes = c.getParameterTypes(); |
|
63 if (paramTypes.length > 0) { |
|
64 System.out.println("Testing class that should be synthetic."); |
|
65 for(Class paramType: paramTypes) { |
|
66 failures += test(paramType, true); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 if (failures != 0) |
|
72 throw new RuntimeException("Test failed with " + failures + " failures."); |
|
73 } |
|
74 } |
|
75 |
|
76 class Tricky { |
|
77 private Tricky() {} |
|
78 |
|
79 public static class Nested { |
|
80 Tricky t = new Tricky(); |
|
81 } |
|
82 } |