Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Introspector/Test4935607.java
41149 views
1
/*
2
* Copyright (c) 2007, 2008, 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 %I% %G%
26
* @bug 4935607
27
* @summary Tests transient properties
28
* @author Sergey Malenkov
29
*/
30
31
import java.awt.Component;
32
import java.awt.Dimension;
33
import java.awt.Point;
34
import java.awt.Rectangle;
35
import java.awt.ScrollPane;
36
import java.awt.geom.RectangularShape;
37
import java.awt.im.InputContext;
38
39
import java.beans.FeatureDescriptor;
40
import java.beans.Transient;
41
42
import java.util.EventListener;
43
44
import javax.swing.AbstractButton;
45
import javax.swing.DefaultListSelectionModel;
46
import javax.swing.ImageIcon;
47
import javax.swing.JComboBox;
48
import javax.swing.JComponent;
49
import javax.swing.JLabel;
50
import javax.swing.JList;
51
import javax.swing.JMenuBar;
52
import javax.swing.JScrollPane;
53
import javax.swing.JTabbedPane;
54
import javax.swing.JViewport;
55
import javax.swing.table.JTableHeader;
56
import javax.swing.text.JTextComponent;
57
58
public class Test4935607 {
59
public static void main(String[] args) {
60
// test all possible cases
61
test(Null.class);
62
test(True.class);
63
test(False.class);
64
test(NullNull.class);
65
test(TrueNull.class);
66
test(FalseNull.class);
67
test(NullTrue.class);
68
test(TrueTrue.class);
69
test(FalseTrue.class);
70
test(NullFalse.class);
71
test(TrueFalse.class);
72
test(FalseFalse.class);
73
// test transient properties in AWT
74
test(RectangularShape.class, "frame"); // NON-NLS: getFrame()
75
test(Rectangle.class, "bounds"); // NON-NLS: getBounds()
76
test(Dimension.class, "size"); // NON-NLS: getSize()
77
test(Point.class, "location"); // NON-NLS: getLocation()
78
test(Component.class, "foreground"); // NON-NLS: getForeground()
79
test(Component.class, "background"); // NON-NLS: getBackground()
80
test(Component.class, "font"); // NON-NLS: getFont()
81
test(Component.class, "visible"); // NON-NLS: getVisible()
82
test(ScrollPane.class, "scrollPosition"); // NON-NLS: getScrollPosition()
83
test(InputContext.class, "compositionEnabled"); // NON-NLS: getCompositionEnabled()
84
// test transient properties in Swing
85
test(JComponent.class, "minimumSize"); // NON-NLS: getMinimumSize()
86
test(JComponent.class, "preferredSize"); // NON-NLS: getPreferredSize()
87
test(JComponent.class, "maximumSize"); // NON-NLS: getMaximumSize()
88
test(ImageIcon.class, "image"); // NON-NLS: getImage()
89
test(ImageIcon.class, "imageObserver"); // NON-NLS: getImageObserver()
90
test(JMenuBar.class, "helpMenu"); // NON-NLS: getHelpMenu()
91
test(JScrollPane.class, "verticalScrollBar"); // NON-NLS: getVerticalScrollBar()
92
test(JScrollPane.class, "horizontalScrollBar"); // NON-NLS: getHorizontalScrollBar()
93
test(JScrollPane.class, "rowHeader"); // NON-NLS: getRowHeader()
94
test(JScrollPane.class, "columnHeader"); // NON-NLS: getColumnHeader()
95
test(JViewport.class, "extentSize"); // NON-NLS: getExtentSize()
96
test(JTableHeader.class, "defaultRenderer"); // NON-NLS: getDefaultRenderer()
97
test(JList.class, "cellRenderer"); // NON-NLS: getCellRenderer()
98
test(JList.class, "selectedIndices"); // NON-NLS: getSelectedIndices()
99
test(DefaultListSelectionModel.class, "leadSelectionIndex"); // NON-NLS: getLeadSelectionIndex()
100
test(DefaultListSelectionModel.class, "anchorSelectionIndex"); // NON-NLS: getAnchorSelectionIndex()
101
test(JComboBox.class, "selectedIndex"); // NON-NLS: getSelectedIndex()
102
test(JTabbedPane.class, "selectedIndex"); // NON-NLS: getSelectedIndex()
103
test(JTabbedPane.class, "selectedComponent"); // NON-NLS: getSelectedComponent()
104
test(AbstractButton.class, "disabledIcon"); // NON-NLS: getDisabledIcon()
105
test(JLabel.class, "disabledIcon"); // NON-NLS: getDisabledIcon()
106
test(JTextComponent.class, "caret"); // NON-NLS: getCaret()
107
test(JTextComponent.class, "caretPosition"); // NON-NLS: getCaretPosition()
108
test(JTextComponent.class, "selectionStart"); // NON-NLS: getSelectionStart()
109
test(JTextComponent.class, "selectionEnd"); // NON-NLS: getSelectionEnd()
110
}
111
112
private static void test(Class type) {
113
Object value = getExpectedValue(type);
114
test(value, BeanUtils.getPropertyDescriptor(type, "property")); // NON-NLS: the property to check
115
test(value, BeanUtils.getEventSetDescriptor(type, "eventSet")); // NON-NLS: the event set to check
116
System.out.println();
117
}
118
119
private static void test(Class type, String property) {
120
System.out.print(type.getName() + ": ");
121
test(Boolean.TRUE, BeanUtils.getPropertyDescriptor(type, property));
122
}
123
124
private static void test(Object expected, FeatureDescriptor fd) {
125
System.out.println(fd.getName());
126
Object actual = fd.getValue("transient"); // NON-NLS: the attribute name
127
if ((actual == null) ? (expected != null) : !actual.equals(expected))
128
throw new Error("expected " + expected + " value, but actual value is " + actual);
129
}
130
131
private static Object getExpectedValue(Class type) {
132
try {
133
return type.getField("VALUE").get(type); // NON-NLS: the field name with expected value
134
} catch (NoSuchFieldException exception) {
135
return null;
136
} catch (IllegalAccessException exception) {
137
throw new Error("unexpected error", exception);
138
}
139
}
140
141
142
public static class Null {
143
public Object getProperty() {
144
return this;
145
}
146
147
public void setProperty(Object object) {
148
}
149
150
public void addEventSetListener(EventSetListener listener) {
151
}
152
153
public void removeEventSetListener(EventSetListener listener) {
154
}
155
}
156
157
public static class True {
158
public static final Boolean VALUE = Boolean.TRUE;
159
160
@Transient
161
public Object getProperty() {
162
return this;
163
}
164
165
@Transient
166
public void setProperty(Object object) {
167
}
168
169
@Transient
170
public void addEventSetListener(EventSetListener listener) {
171
}
172
173
@Transient
174
public void removeEventSetListener(EventSetListener listener) {
175
}
176
}
177
178
public static class False {
179
public static final Boolean VALUE = Boolean.FALSE;
180
181
@Transient(false)
182
public Object getProperty() {
183
return this;
184
}
185
186
@Transient(false)
187
public void setProperty(Object object) {
188
}
189
190
@Transient(false)
191
public void addEventSetListener(EventSetListener listener) {
192
}
193
194
@Transient(false)
195
public void removeEventSetListener(EventSetListener listener) {
196
}
197
}
198
199
public static class NullNull extends Null {
200
@Override
201
public Object getProperty() {
202
return this;
203
}
204
205
@Override
206
public void setProperty(Object object) {
207
}
208
209
@Override
210
public void addEventSetListener(EventSetListener listener) {
211
}
212
213
@Override
214
public void removeEventSetListener(EventSetListener listener) {
215
}
216
}
217
218
public static class TrueNull extends Null {
219
public static final Boolean VALUE = Boolean.TRUE;
220
221
@Override
222
@Transient
223
public Object getProperty() {
224
return this;
225
}
226
227
@Override
228
@Transient
229
public void setProperty(Object object) {
230
}
231
232
@Override
233
@Transient
234
public void addEventSetListener(EventSetListener listener) {
235
}
236
237
@Override
238
@Transient
239
public void removeEventSetListener(EventSetListener listener) {
240
}
241
}
242
243
public static class FalseNull extends Null {
244
public static final Boolean VALUE = Boolean.FALSE;
245
246
@Override
247
@Transient(false)
248
public Object getProperty() {
249
return this;
250
}
251
252
@Override
253
@Transient(false)
254
public void setProperty(Object object) {
255
}
256
257
@Override
258
@Transient(false)
259
public void addEventSetListener(EventSetListener listener) {
260
}
261
262
@Override
263
@Transient(false)
264
public void removeEventSetListener(EventSetListener listener) {
265
}
266
}
267
268
public static class NullTrue extends True {
269
@Override
270
public Object getProperty() {
271
return this;
272
}
273
274
@Override
275
public void setProperty(Object object) {
276
}
277
278
@Override
279
public void addEventSetListener(EventSetListener listener) {
280
}
281
282
@Override
283
public void removeEventSetListener(EventSetListener listener) {
284
}
285
}
286
287
public static class TrueTrue extends True {
288
@Override
289
@Transient
290
public Object getProperty() {
291
return this;
292
}
293
294
@Override
295
@Transient
296
public void setProperty(Object object) {
297
}
298
299
@Override
300
@Transient
301
public void addEventSetListener(EventSetListener listener) {
302
}
303
304
@Override
305
@Transient
306
public void removeEventSetListener(EventSetListener listener) {
307
}
308
}
309
310
public static class FalseTrue extends True {
311
public static final Boolean VALUE = Boolean.FALSE;
312
313
@Override
314
@Transient(false)
315
public Object getProperty() {
316
return this;
317
}
318
319
@Override
320
@Transient(false)
321
public void setProperty(Object object) {
322
}
323
324
@Override
325
@Transient(false)
326
public void addEventSetListener(EventSetListener listener) {
327
}
328
329
@Override
330
@Transient(false)
331
public void removeEventSetListener(EventSetListener listener) {
332
}
333
}
334
335
public static class NullFalse extends False {
336
@Override
337
public Object getProperty() {
338
return this;
339
}
340
341
@Override
342
public void setProperty(Object object) {
343
}
344
345
@Override
346
public void addEventSetListener(EventSetListener listener) {
347
}
348
349
@Override
350
public void removeEventSetListener(EventSetListener listener) {
351
}
352
}
353
354
public static class TrueFalse extends False {
355
public static final Boolean VALUE = Boolean.TRUE;
356
357
@Override
358
@Transient
359
public Object getProperty() {
360
return this;
361
}
362
363
@Override
364
@Transient
365
public void setProperty(Object object) {
366
}
367
368
@Override
369
@Transient
370
public void addEventSetListener(EventSetListener listener) {
371
}
372
373
@Override
374
@Transient
375
public void removeEventSetListener(EventSetListener listener) {
376
}
377
}
378
379
public static class FalseFalse extends False {
380
@Override
381
@Transient(false)
382
public Object getProperty() {
383
return this;
384
}
385
386
@Override
387
@Transient(false)
388
public void setProperty(Object object) {
389
}
390
391
@Override
392
@Transient(false)
393
public void addEventSetListener(EventSetListener listener) {
394
}
395
396
@Override
397
@Transient(false)
398
public void removeEventSetListener(EventSetListener listener) {
399
}
400
}
401
402
public static final class EventSetListener implements EventListener {
403
}
404
}
405
406