Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Introspector/4058433/TestJavaBean.java
41152 views
1
/*
2
* Copyright (c) 2014, 2015, 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
import java.awt.event.ActionListener;
25
import java.beans.BeanDescriptor;
26
import java.beans.BeanInfo;
27
import java.beans.Introspector;
28
import java.beans.JavaBean;
29
30
/*
31
* @test
32
* @bug 4058433
33
* @summary Tests the JavaBean annotation
34
* @author Sergey Malenkov
35
*/
36
public class TestJavaBean {
37
38
static final String DSCR = "description";
39
static final String PRP = "value";
40
static final String ACT = "action";
41
42
public static void main(final String[] args) throws Exception {
43
test(X.class, "TestJavaBean$X", "TestJavaBean$X", null, null);
44
test(D.class, "TestJavaBean$D", DSCR, null, null);
45
test(DP.class, "TestJavaBean$DP", "TestJavaBean$DP", PRP, null);
46
test(DES.class, "TestJavaBean$DES", "TestJavaBean$DES", null, ACT);
47
test(DDP.class, "TestJavaBean$DDP", DSCR, PRP, null);
48
test(DDES.class, "TestJavaBean$DDES", DSCR, null, ACT);
49
test(DPDES.class, "TestJavaBean$DPDES", "TestJavaBean$DPDES", PRP, ACT);
50
test(DDPDES.class, "TestJavaBean$DDPDES", DSCR, PRP, ACT);
51
}
52
53
private static void test(Class<?> type, String name, String descr,
54
String prop, String event) throws Exception {
55
BeanInfo info = Introspector.getBeanInfo(type);
56
BeanDescriptor bd = info.getBeanDescriptor();
57
58
if (!bd.getName().equals(name)) {
59
throw new Error("unexpected name of the bean");
60
}
61
62
if (!bd.getShortDescription().equals(descr)) {
63
throw new Error("unexpected description of the bean");
64
}
65
66
int dp = info.getDefaultPropertyIndex();
67
if (dp < 0 && prop != null) {
68
throw new Error("unexpected index of the default property");
69
}
70
if (dp >= 0) {
71
if (!info.getPropertyDescriptors()[dp].getName().equals(prop)) {
72
throw new Error("unexpected default property");
73
}
74
}
75
int des = info.getDefaultEventIndex();
76
if (des < 0 && event != null) {
77
throw new Error("unexpected index of the default event set");
78
}
79
if (des >= 0) {
80
if (!info.getEventSetDescriptors()[des].getName().equals(event)) {
81
throw new Error("unexpected default event set");
82
}
83
}
84
}
85
86
public static class X {
87
}
88
89
@JavaBean(description = DSCR)
90
public static class D {
91
}
92
93
@JavaBean(defaultProperty = PRP)
94
public static class DP {
95
private int value;
96
97
public int getValue() {
98
return this.value;
99
}
100
101
public void setValue(int value) {
102
this.value = value;
103
}
104
}
105
106
@JavaBean(defaultEventSet = ACT)
107
public static class DES {
108
public void addActionListener(ActionListener listener) {
109
}
110
111
public void removeActionListener(ActionListener listener) {
112
}
113
}
114
115
@JavaBean(description = DSCR, defaultProperty = PRP)
116
public static class DDP {
117
private int value;
118
119
public int getValue() {
120
return this.value;
121
}
122
123
public void setValue(int value) {
124
this.value = value;
125
}
126
}
127
128
@JavaBean(description = DSCR, defaultEventSet = ACT)
129
public static class DDES {
130
public void addActionListener(ActionListener listener) {
131
}
132
133
public void removeActionListener(ActionListener listener) {
134
}
135
}
136
137
@JavaBean(defaultProperty = PRP, defaultEventSet = ACT)
138
public static class DPDES {
139
private int value;
140
141
public int getValue() {
142
return this.value;
143
}
144
145
public void setValue(int value) {
146
this.value = value;
147
}
148
149
public void addActionListener(ActionListener listener) {
150
}
151
152
public void removeActionListener(ActionListener listener) {
153
}
154
}
155
156
@JavaBean(description = DSCR, defaultProperty = PRP, defaultEventSet = ACT)
157
public static class DDPDES {
158
private int value;
159
160
public int getValue() {
161
return this.value;
162
}
163
164
public void setValue(int value) {
165
this.value = value;
166
}
167
168
public void addActionListener(ActionListener listener) {
169
}
170
171
public void removeActionListener(ActionListener listener) {
172
}
173
}
174
}
175
176