Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with MethodDescriptor

use of java.beans.MethodDescriptor in project j2objc by google.

the class EventSetDescriptorTest method testSetUnicast.

public void testSetUnicast() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Method[] listenerMethods = { listenerType.getMethod("mockPropertyChange", new Class[] { MockPropertyChangeEvent.class }), listenerType.getMethod("mockPropertyChange2", new Class[] { MockPropertyChangeEvent.class }) };
    MethodDescriptor[] listenerMethodDescriptors = { new MethodDescriptor(listenerMethods[0]), new MethodDescriptor(listenerMethods[1]) };
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod("addMockPropertyChangeListener", new Class[] { listenerType });
    Method removeMethod = sourceClass.getMethod("removeMockPropertyChangeListener", new Class[] { listenerType });
    EventSetDescriptor esd = new EventSetDescriptor(eventSetName, listenerType, listenerMethodDescriptors, addMethod, removeMethod);
    assertFalse(esd.isUnicast());
    esd.setInDefaultEventSet(true);
    assertTrue(esd.isInDefaultEventSet());
}
Also used : MockPropertyChangeListener(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener) MockPropertyChangeEvent(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor)

Aggregations

MethodDescriptor (java.beans.MethodDescriptor)27 Method (java.lang.reflect.Method)18 EventSetDescriptor (java.beans.EventSetDescriptor)10 BeanInfo (java.beans.BeanInfo)9 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)7 PropertyDescriptor (java.beans.PropertyDescriptor)6 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)5 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 BeanDescriptor (java.beans.BeanDescriptor)4 ParameterDescriptor (java.beans.ParameterDescriptor)4 ArrayList (java.util.ArrayList)3 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)3 IntrospectionException (java.beans.IntrospectionException)2 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 FeatureDescriptor (java.beans.FeatureDescriptor)1 IndexedPropertyChangeEvent (java.beans.IndexedPropertyChangeEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1