Search in sources :

Example 1 with MethodDescriptor

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");
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) MethodDescriptor(java.beans.MethodDescriptor)

Example 2 with MethodDescriptor

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);
    }
}
Also used : ParameterDescriptor(java.beans.ParameterDescriptor) MethodDescriptor(java.beans.MethodDescriptor)

Example 3 with MethodDescriptor

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());
}
Also used : BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor)

Example 4 with MethodDescriptor

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;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor)

Example 5 with MethodDescriptor

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);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor) BeanDescriptor(java.beans.BeanDescriptor)

Aggregations

MethodDescriptor (java.beans.MethodDescriptor)34 Method (java.lang.reflect.Method)21 BeanInfo (java.beans.BeanInfo)12 EventSetDescriptor (java.beans.EventSetDescriptor)10 PropertyDescriptor (java.beans.PropertyDescriptor)10 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)7 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)7 IntrospectionException (java.beans.IntrospectionException)6 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 ArrayList (java.util.ArrayList)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 BeanDescriptor (java.beans.BeanDescriptor)4 ParameterDescriptor (java.beans.ParameterDescriptor)4 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1