author | malenkov |
Mon, 29 Apr 2013 16:42:22 +0400 | |
changeset 17148 | bb5fff33bf49 |
child 42338 | a60f280f803c |
permissions | -rw-r--r-- |
17148
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
1 |
/* |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
4 |
* |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
8 |
* |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
14 |
* |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
18 |
* |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
21 |
* questions. |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
22 |
*/ |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
23 |
|
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
24 |
/* |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
25 |
* @test |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
26 |
* @bug 8007458 |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
27 |
* @summary Tests CardLayout encoding |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
28 |
* @author Sergey Malenkov |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
29 |
*/ |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
30 |
|
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
31 |
import java.awt.CardLayout; |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
32 |
import java.lang.reflect.Field; |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
33 |
import java.util.Vector; |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
34 |
import javax.swing.JLabel; |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
35 |
|
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
36 |
public final class java_awt_CardLayout extends AbstractTest<CardLayout> { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
37 |
private static final Field VECTOR = getField("java.awt.CardLayout.vector"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
38 |
private static final Field NAME = getField("java.awt.CardLayout$Card.name"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
39 |
private static final Field COMP = getField("java.awt.CardLayout$Card.comp"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
40 |
|
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
42 |
new java_awt_CardLayout().test(true); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
43 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
44 |
|
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
45 |
@Override |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
46 |
protected CardLayout getObject() { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
47 |
CardLayout layout = new CardLayout(); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
48 |
layout.addLayoutComponent(new JLabel("a"), "a"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
49 |
layout.addLayoutComponent(new JLabel("b"), "b"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
50 |
layout.addLayoutComponent(new JLabel("c"), "c"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
51 |
return layout; |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
52 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
53 |
|
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
54 |
@Override |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
55 |
protected CardLayout getAnotherObject() { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
56 |
CardLayout layout = new CardLayout(); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
57 |
layout.addLayoutComponent(new JLabel("a"), "a"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
58 |
layout.addLayoutComponent(new JLabel("b"), "b"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
59 |
layout.addLayoutComponent(new JLabel("c"), "c"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
60 |
layout.addLayoutComponent(new JLabel("d"), "d"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
61 |
return layout; |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
62 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
63 |
|
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
64 |
@Override |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
65 |
protected void validate(CardLayout before, CardLayout after) { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
66 |
super.validate(before, after); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
67 |
try { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
68 |
Vector a = (Vector) VECTOR.get(after); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
69 |
Vector b = (Vector) VECTOR.get(before); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
70 |
int size = a.size(); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
71 |
if (size != b.size()) { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
72 |
throw new Error("different content"); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
73 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
74 |
for (int i = 0; i < size; i++) { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
75 |
super.validator.validate(NAME.get(a.get(i)), NAME.get(b.get(i))); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
76 |
super.validator.validate(COMP.get(a.get(i)), COMP.get(b.get(i))); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
77 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
78 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
79 |
catch (Exception exception) { |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
80 |
throw new Error(exception); |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
81 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
82 |
} |
bb5fff33bf49
8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents:
diff
changeset
|
83 |
} |