Search in sources :

Example 21 with MethodDescriptor

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

the class IntrospectorTest method testGetBeanInfoClassint_IGNORE_ALL_Method.

/*
     * FLAG=IGNORE_ALL_BEANINFO;
     */
public void testGetBeanInfoClassint_IGNORE_ALL_Method() throws IntrospectionException {
    BeanInfo info = Introspector.getBeanInfo(MockFooSub.class, Introspector.IGNORE_ALL_BEANINFO);
    MethodDescriptor[] mds = info.getMethodDescriptors();
    int getMethod = 0;
    int setMethod = 0;
    for (MethodDescriptor element : mds) {
        String name = element.getName();
        if (name.startsWith("getText")) {
            getMethod++;
            assertEquals("getText", name);
        }
        if (name.startsWith("setText")) {
            setMethod++;
            assertEquals("setText", name);
        }
    }
    assertEquals(1, getMethod);
    assertEquals(1, setMethod);
}
Also used : BeanInfo(java.beans.BeanInfo) SimpleBeanInfo(java.beans.SimpleBeanInfo) FakeFox01BeanInfo(org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo) MethodDescriptor(java.beans.MethodDescriptor)

Example 22 with MethodDescriptor

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

the class IntrospectorTest method testGetBeanInfoClass_no_BeanInfo.

/*
     * Class under test for BeanInfo getBeanInfo(Class) No XXXXBeanInfo + test
     * cache info
     */
public void testGetBeanInfoClass_no_BeanInfo() throws IntrospectionException {
    Class<FakeFox> beanClass = FakeFox.class;
    BeanInfo info = Introspector.getBeanInfo(beanClass);
    assertNull(info.getAdditionalBeanInfo());
    BeanDescriptor beanDesc = info.getBeanDescriptor();
    assertEquals("FakeFox", beanDesc.getName());
    assertEquals(0, info.getEventSetDescriptors().length);
    assertEquals(-1, info.getDefaultEventIndex());
    assertEquals(-1, info.getDefaultPropertyIndex());
    MethodDescriptor[] methodDesc = info.getMethodDescriptors();
    Method[] methods = beanClass.getMethods();
    assertEquals(methods.length, methodDesc.length);
    ArrayList<Method> methodList = new ArrayList<Method>();
    for (Method element : methods) {
        methodList.add(element);
    }
    for (MethodDescriptor element : methodDesc) {
        assertTrue(methodList.contains(element.getMethod()));
    }
    PropertyDescriptor[] propertyDesc = info.getPropertyDescriptors();
    assertEquals(1, propertyDesc.length);
    for (PropertyDescriptor element : propertyDesc) {
        if (element.getName().equals("class")) {
            assertNull(element.getWriteMethod());
            assertNotNull(element.getReadMethod());
        }
    }
    BeanInfo cacheInfo = Introspector.getBeanInfo(FakeFox.class);
    assertSame(info, cacheInfo);
}
Also used : IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) PropertyDescriptor(java.beans.PropertyDescriptor) BeanDescriptor(java.beans.BeanDescriptor) FakeFox(org.apache.harmony.beans.tests.support.mock.FakeFox) BeanInfo(java.beans.BeanInfo) SimpleBeanInfo(java.beans.SimpleBeanInfo) FakeFox01BeanInfo(org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor)

Example 23 with MethodDescriptor

use of java.beans.MethodDescriptor in project jdk8u_jdk by JetBrains.

the class Test4498236 method main.

public static void main(String[] args) throws Exception {
    PropertyChangeEvent event = new PropertyChangeEvent("source", null, null, null);
    event.setPropagationId("id");
    test("[propertyName=null; oldValue=null; newValue=null; propagationId=id; source=source]", event);
    test("[propertyName=name; oldValue=old; newValue=new; propagationId=null; source=source]", new PropertyChangeEvent("source", "name", "old", "new"));
    test("[propertyName=array; index=5; oldValue=old; newValue=new; propagationId=null; source=source]", new IndexedPropertyChangeEvent("source", "array", "old", "new", 5));
    FeatureDescriptor fd = new FeatureDescriptor();
    fd.setName("n");
    fd.setDisplayName("dn");
    fd.setShortDescription("sd");
    fd.setPreferred(true);
    fd.setHidden(true);
    fd.setExpert(true);
    fd.setValue("first", "value");
    test("[name=n; displayName=dn; shortDescription=sd; preferred; hidden; expert; values={first=value}]", fd);
    test("[name=String; beanClass=class java.lang.String]", new BeanDescriptor(String.class));
    test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]", new BeanDescriptor(Object.class, String.class));
    test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]", new BeanDescriptor(Object.class, String.class));
    test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object)]", new MethodDescriptor(Object.class.getMethod("equals", Object.class)));
    test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object); parameterDescriptors={java.beans.ParameterDescriptor[name=null]}]", new MethodDescriptor(Object.class.getMethod("equals", Object.class), new ParameterDescriptor[] { new ParameterDescriptor() }));
    Class type = KeyListener.class;
    String[] names = { "keyTyped", "keyPressed", "keyReleased" };
    Method[] methods = new Method[names.length];
    for (int i = 0; i < names.length; i++) {
        methods[i] = type.getMethod(names[i], KeyEvent.class);
    }
    test("[name=key; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.getKeyListeners(); addListenerMethod=public void Test4498236.addKeyListener(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.removeKeyListener(java.awt.event.KeyListener)]", new EventSetDescriptor(Test4498236.class, "key", type, names[0]));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove"));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove", "get"));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type)));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type), Test4498236.class.getMethod("get")));
    test("[name=value; propertyType=boolean; readMethod=public boolean Test4498236.isValue(); writeMethod=public void Test4498236.setValue(boolean)]", new PropertyDescriptor("value", Test4498236.class));
    test("[name=$$$]", new PropertyDescriptor("$$$", Test4498236.class, null, null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]", new PropertyDescriptor("$$$", Test4498236.class, "getValue", null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]", new PropertyDescriptor("$$$", Test4498236.class, "getValue", "setValue"));
    test("[name=$$$]", new PropertyDescriptor("$$$", null, null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]", new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]", new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), Test4498236.class.getMethod("setValue", boolean.class)));
    test("[name=index; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]", new IndexedPropertyDescriptor("index", Test4498236.class));
    test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]", new IndexedPropertyDescriptor("$$$", Test4498236.class, "getIndex", "setIndex", "getIndex", "setIndex"));
    test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]", new IndexedPropertyDescriptor("$$$", Test4498236.class.getMethod("getIndex"), Test4498236.class.getMethod("setIndex", new int[0].getClass()), Test4498236.class.getMethod("getIndex", int.class), Test4498236.class.getMethod("setIndex", int.class, int.class)));
}
Also used : IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) ParameterDescriptor(java.beans.ParameterDescriptor) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor) KeyEvent(java.awt.event.KeyEvent) FeatureDescriptor(java.beans.FeatureDescriptor) BeanDescriptor(java.beans.BeanDescriptor) IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent) KeyListener(java.awt.event.KeyListener) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 24 with MethodDescriptor

use of java.beans.MethodDescriptor in project jdk8u_jdk by JetBrains.

the class UnloadClassBeanInfo method main.

public static void main(final String[] args) throws Exception {
    Class cl = getStub();
    System.out.println("cl.getClassLoader() = " + cl.getClassLoader());
    final BeanInfo beanInfo = Introspector.getBeanInfo(cl, Object.class);
    MethodDescriptor[] mds = beanInfo.getMethodDescriptors();
    System.out.println("mds = " + Arrays.toString(mds));
    loader.close();
    loader = null;
    cl = null;
    Util.generateOOME();
    mds = beanInfo.getMethodDescriptors();
    System.out.println("mds = " + Arrays.toString(mds));
}
Also used : BeanInfo(java.beans.BeanInfo) MethodDescriptor(java.beans.MethodDescriptor)

Example 25 with MethodDescriptor

use of java.beans.MethodDescriptor in project jdk8u_jdk by JetBrains.

the class Test8005065 method testEventSetDescriptor.

private static void testEventSetDescriptor() {
    try {
        MethodDescriptor[] array = { new MethodDescriptor(MyDPD.class.getMethod("getArray")) };
        EventSetDescriptor descriptor = new EventSetDescriptor(null, null, array, null, null);
        test(descriptor.getListenerMethodDescriptors());
        array[0] = null;
        test(descriptor.getListenerMethodDescriptors());
        descriptor.getListenerMethodDescriptors()[0] = null;
        test(descriptor.getListenerMethodDescriptors());
    } catch (Exception exception) {
        throw new Error("unexpected error", exception);
    }
}
Also used : MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor)

Aggregations

MethodDescriptor (java.beans.MethodDescriptor)26 Method (java.lang.reflect.Method)18 EventSetDescriptor (java.beans.EventSetDescriptor)9 BeanInfo (java.beans.BeanInfo)8 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)7 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)5 PropertyDescriptor (java.beans.PropertyDescriptor)5 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 ParameterDescriptor (java.beans.ParameterDescriptor)4 BeanDescriptor (java.beans.BeanDescriptor)3 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)3 IntrospectionException (java.beans.IntrospectionException)2 ArrayList (java.util.ArrayList)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