Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Introspector/8132566/OverrideUserDefPropertyInfoTest.java
41153 views
1
/*
2
* Copyright (c) 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.beans.BeanDescriptor;
25
import java.beans.BeanInfo;
26
import java.beans.BeanProperty;
27
import java.beans.EventSetDescriptor;
28
import java.beans.IntrospectionException;
29
import java.beans.Introspector;
30
import java.beans.JavaBean;
31
import java.beans.MethodDescriptor;
32
import java.beans.PropertyChangeListener;
33
import java.beans.PropertyDescriptor;
34
import java.beans.SimpleBeanInfo;
35
36
/**
37
* @test
38
* @bug 8132566 8132669 8131939
39
* @summary Check if the derived class overrides
40
* the parent's user-defined property info.
41
* @author a.stepanov
42
*/
43
44
public class OverrideUserDefPropertyInfoTest {
45
46
private static final boolean baseFlag = true;
47
private static final boolean childFlag = false;
48
49
@JavaBean(description = "CHILD")
50
public static class C extends Base {
51
52
private int x;
53
54
@BeanProperty(
55
bound = childFlag,
56
expert = childFlag,
57
hidden = childFlag,
58
preferred = childFlag,
59
required = childFlag,
60
visualUpdate = childFlag,
61
description = "CHILDPROPERTY",
62
enumerationValues = {"javax.swing.SwingConstants.BOTTOM"}
63
)
64
@Override
65
public void setX(int v) { x = v; }
66
@Override
67
public int getX() { return x; }
68
69
@Override
70
public void addPropertyChangeListener(PropertyChangeListener l) {}
71
@Override
72
public void removePropertyChangeListener(PropertyChangeListener l) {}
73
}
74
75
public static class Base {
76
private int x;
77
public void setX(int v) { x = v; }
78
public int getX() { return x; }
79
public void addPropertyChangeListener(PropertyChangeListener l) {}
80
public void removePropertyChangeListener(PropertyChangeListener l) {}
81
}
82
83
public static class BaseBeanInfo extends SimpleBeanInfo {
84
85
@Override
86
public BeanDescriptor getBeanDescriptor() {
87
BeanDescriptor d = new BeanDescriptor(Base.class, null);
88
d.setShortDescription("BASE");
89
return d;
90
}
91
92
@Override
93
public PropertyDescriptor[] getPropertyDescriptors() {
94
PropertyDescriptor[] p = new PropertyDescriptor[1];
95
96
try {
97
p[0] = new PropertyDescriptor ("x", Base.class, "getX", null);
98
p[0].setShortDescription("BASEPROPERTY");
99
p[0].setBound (baseFlag);
100
p[0].setExpert(baseFlag);
101
p[0].setHidden(baseFlag);
102
p[0].setPreferred(baseFlag);
103
p[0].setValue("required", baseFlag);
104
p[0].setValue("visualUpdate", baseFlag);
105
p[0].setValue("enumerationValues",
106
new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});
107
} catch(IntrospectionException e) { e.printStackTrace(); }
108
109
return p;
110
}
111
112
@Override
113
public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; }
114
@Override
115
public MethodDescriptor[] getMethodDescriptors() {
116
MethodDescriptor[] m = new MethodDescriptor[1];
117
try {
118
m[0] = new MethodDescriptor(Base.class.getMethod("setX", new Class[] {int.class}));
119
m[0].setDisplayName("");
120
}
121
catch( NoSuchMethodException | SecurityException e) {}
122
return m;
123
}
124
125
@Override
126
public int getDefaultPropertyIndex() { return -1; }
127
@Override
128
public int getDefaultEventIndex() { return -1; }
129
@Override
130
public java.awt.Image getIcon(int iconKind) { return null; }
131
}
132
133
public static void main(String[] args) throws Exception {
134
135
BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
136
Checker.checkEq("description",
137
i.getBeanDescriptor().getShortDescription(), "CHILD");
138
139
PropertyDescriptor[] pds = i.getPropertyDescriptors();
140
Checker.checkEq("number of properties", pds.length, 1);
141
PropertyDescriptor p = pds[0];
142
143
Checker.checkEq("property description", p.getShortDescription(), "CHILDPROPERTY");
144
Checker.checkEq("isBound", p.isBound(), childFlag);
145
Checker.checkEq("isExpert", p.isExpert(), childFlag);
146
Checker.checkEq("isHidden", p.isHidden(), childFlag);
147
Checker.checkEq("isPreferred", p.isPreferred(), childFlag);
148
Checker.checkEq("required", p.getValue("required"), childFlag);
149
Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), childFlag);
150
151
Checker.checkEnumEq("enumerationValues", p.getValue("enumerationValues"),
152
new Object[]{"BOTTOM", 3, "javax.swing.SwingConstants.BOTTOM"});
153
}
154
}
155
156