use of java.beans.MethodDescriptor in project jdk8u_jdk by JetBrains.
the class Test7172865 method main.
public static void main(String[] args) throws Exception {
int errors = 0;
MethodDescriptor md = new MethodDescriptor(Test7172865.class.getMethod("getGood"));
errors += test(PropertyDescriptor.class, "good", true);
PropertyDescriptor pdGoodString = new PropertyDescriptor("good", Test7172865.class, "getGood", "setGood");
PropertyDescriptor pdGoodMethod = new PropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()));
errors += test(PropertyDescriptor.class, "bad", false);
PropertyDescriptor pdBadString = new PropertyDescriptor("bad", Test7172865.class, "getBad", null);
PropertyDescriptor pdBadMethod = new PropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()));
errors += test(IndexedPropertyDescriptor.class, "good", true);
IndexedPropertyDescriptor ipdGoodString = new IndexedPropertyDescriptor("good", Test7172865.class, "getGood", "setGood", "getGood", "setGood");
IndexedPropertyDescriptor ipdGoodMethod = new IndexedPropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()), Test7172865.class.getMethod("getGood", Integer.TYPE), Test7172865.class.getMethod("setGood", Integer.TYPE, String.class));
errors += test(IndexedPropertyDescriptor.class, "bad", false);
IndexedPropertyDescriptor ipdBadString = new IndexedPropertyDescriptor("bad", Test7172865.class, "getBad", null, "getBad", null);
IndexedPropertyDescriptor ipdBadMethod = new IndexedPropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()), Test7172865.class.getMethod("getBad", Integer.TYPE), Test7172865.class.getMethod("setBad", Integer.TYPE, String.class));
for (int i = 1; i <= 2; i++) {
System.out.println("STEP: " + i);
errors += test("md", null != md.getMethod());
errors += test("pdGoodString", pdGoodString, true, true);
errors += test("pdGoodMethod", pdGoodMethod, true, true);
errors += test("pdBadString", pdBadString, true, false);
errors += test("pdBadMethod", pdBadMethod, true, true);
errors += test("ipdGoodString", ipdGoodString, true, true, true, true);
errors += test("ipdGoodMethod", ipdGoodMethod, true, true, true, true);
errors += test("ipdBadString", ipdBadString, true, false, true, false);
errors += test("ipdBadMethod", ipdBadMethod, true, true, true, true);
try {
int[] array = new int[1024];
while (true) {
array = new int[array.length << 1];
}
} catch (OutOfMemoryError error) {
System.gc();
}
}
if (errors > 0) {
throw new Error("found " + errors + " errors");
}
}
use of java.beans.MethodDescriptor in project jdk8u_jdk by JetBrains.
the class Test8005065 method testMethodDescriptor.
private static void testMethodDescriptor() {
try {
ParameterDescriptor[] array = { new ParameterDescriptor() };
MethodDescriptor descriptor = new MethodDescriptor(MyDPD.class.getMethod("getArray"), array);
test(descriptor.getParameterDescriptors());
array[0] = null;
test(descriptor.getParameterDescriptors());
descriptor.getParameterDescriptors()[0] = null;
test(descriptor.getParameterDescriptors());
} catch (Exception exception) {
throw new Error("unexpected error", exception);
}
}
use of java.beans.MethodDescriptor in project lucene-solr by apache.
the class SolrPluginUtils method findSetter.
private static Method findSetter(Class<?> clazz, String setterName, String key, Class<?> paramClazz, boolean lenient) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException ie) {
if (lenient) {
return null;
}
throw new RuntimeException("Error getting bean info for class : " + clazz.getName(), ie);
}
for (final boolean matchParamClazz : new boolean[] { true, false }) {
for (final MethodDescriptor desc : beanInfo.getMethodDescriptors()) {
final Method m = desc.getMethod();
final Class<?>[] p = m.getParameterTypes();
if (m.getName().equals(setterName) && p.length == 1 && (!matchParamClazz || paramClazz.equals(p[0]))) {
return m;
}
}
}
if (lenient) {
return null;
}
throw new RuntimeException("No setter corrresponding to '" + key + "' in " + clazz.getName());
}
use of java.beans.MethodDescriptor in project spring-framework by spring-projects.
the class ExtendedBeanInfo method findCandidateWriteMethods.
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
List<Method> matches = new ArrayList<>();
for (MethodDescriptor methodDescriptor : methodDescriptors) {
Method method = methodDescriptor.getMethod();
if (isCandidateWriteMethod(method)) {
matches.add(method);
}
}
// Sort non-void returning write methods to guard against the ill effects of
// non-deterministic sorting of methods returned from Class#getDeclaredMethods
// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
Collections.sort(matches, new Comparator<Method>() {
@Override
public int compare(Method m1, Method m2) {
return m2.toString().compareTo(m1.toString());
}
});
return matches;
}
use of java.beans.MethodDescriptor in project yamcs-studio by yamcs.
the class DefaultWidgetIntrospector method getBeanInfo.
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
Introspector.flushFromCaches(beanClass);
BeanInfo bi = Introspector.getBeanInfo(beanClass);
BeanDescriptor bd = bi.getBeanDescriptor();
MethodDescriptor[] mds = bi.getMethodDescriptors();
EventSetDescriptor[] esds = bi.getEventSetDescriptors();
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
List<PropertyDescriptor> filteredPDList = new ArrayList<PropertyDescriptor>();
List<String> nonPropList = Arrays.asList(getNonProperties());
for (PropertyDescriptor pd : pds) {
if (!nonPropList.contains(pd.getName()) && pd.getWriteMethod() != null && pd.getReadMethod() != null)
filteredPDList.add(pd);
}
int defaultEvent = bi.getDefaultEventIndex();
int defaultProperty = bi.getDefaultPropertyIndex();
return new GenericBeanInfo(bd, esds, defaultEvent, filteredPDList.toArray(new PropertyDescriptor[filteredPDList.size()]), defaultProperty, mds, null);
}
Aggregations