Search in sources :

Example 51 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project intellij-community by JetBrains.

the class ListenerNavigateButton method buildNavigateActionGroup.

private static DefaultActionGroup buildNavigateActionGroup(RadComponent component, final PsiField boundField) {
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    final EventSetDescriptor[] eventSetDescriptors;
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(component.getComponentClass());
        eventSetDescriptors = beanInfo.getEventSetDescriptors();
    } catch (IntrospectionException e) {
        LOG.error(e);
        return null;
    }
    PsiFile boundClassFile = boundField.getContainingFile();
    if (boundClassFile == null) {
        return null;
    }
    final LocalSearchScope scope = new LocalSearchScope(boundClassFile);
    ReferencesSearch.search(boundField, scope).forEach(ref -> {
        final PsiElement element = ref.getElement();
        if (element.getParent() instanceof PsiReferenceExpression) {
            PsiReferenceExpression refExpr = (PsiReferenceExpression) element.getParent();
            if (refExpr.getParent() instanceof PsiMethodCallExpression) {
                PsiMethodCallExpression methodCall = (PsiMethodCallExpression) refExpr.getParent();
                final PsiElement psiElement = refExpr.resolve();
                if (psiElement instanceof PsiMethod) {
                    PsiMethod method = (PsiMethod) psiElement;
                    for (EventSetDescriptor eventSetDescriptor : eventSetDescriptors) {
                        if (Comparing.equal(eventSetDescriptor.getAddListenerMethod().getName(), method.getName())) {
                            final String eventName = eventSetDescriptor.getName();
                            final PsiExpression[] args = methodCall.getArgumentList().getExpressions();
                            if (args.length > 0) {
                                addListenerRef(actionGroup, eventName, args[0]);
                            }
                        }
                    }
                }
            }
        }
        return true;
    });
    return actionGroup;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 52 with EventSetDescriptor

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

the class Test6976577 method main.

public static void main(String[] args) throws Exception {
    Class<?> bt = Accessor.getBeanType();
    Class<?> lt = Accessor.getListenerType();
    // test PropertyDescriptor
    PropertyDescriptor pd = new PropertyDescriptor("boolean", bt);
    test(pd.getReadMethod());
    test(pd.getWriteMethod());
    // test IndexedPropertyDescriptor
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor("indexed", bt);
    test(ipd.getReadMethod());
    test(ipd.getWriteMethod());
    test(ipd.getIndexedReadMethod());
    test(ipd.getIndexedWriteMethod());
    // test EventSetDescriptor
    EventSetDescriptor esd = new EventSetDescriptor(bt, "test", lt, "process");
    test(esd.getAddListenerMethod());
    test(esd.getRemoveListenerMethod());
    test(esd.getGetListenerMethod());
    test(esd.getListenerMethods());
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 53 with EventSetDescriptor

use of java.beans.EventSetDescriptor 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 54 with EventSetDescriptor

use of java.beans.EventSetDescriptor 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)

Example 55 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project groovy by apache.

the class MetaClassImpl method addProperties.

private void addProperties() {
    BeanInfo info;
    //     introspect
    try {
        if (isBeanDerivative(theClass)) {
            info = (BeanInfo) AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws IntrospectionException {
                    return Introspector.getBeanInfo(theClass, Introspector.IGNORE_ALL_BEANINFO);
                }
            });
        } else {
            info = (BeanInfo) AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws IntrospectionException {
                    return Introspector.getBeanInfo(theClass);
                }
            });
        }
    } catch (PrivilegedActionException pae) {
        throw new GroovyRuntimeException("exception during bean introspection", pae.getException());
    }
    PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
    // build up the metaproperties based on the public fields, property descriptors,
    // and the getters and setters
    setupProperties(descriptors);
    EventSetDescriptor[] eventDescriptors = info.getEventSetDescriptors();
    for (EventSetDescriptor descriptor : eventDescriptors) {
        Method[] listenerMethods = descriptor.getListenerMethods();
        for (Method listenerMethod : listenerMethods) {
            final MetaMethod metaMethod = CachedMethod.find(descriptor.getAddListenerMethod());
            // we skip that here
            if (metaMethod == null)
                continue;
            addToAllMethodsIfPublic(metaMethod);
            String name = listenerMethod.getName();
            if (listeners.containsKey(name)) {
                listeners.put(name, AMBIGUOUS_LISTENER_METHOD);
            } else {
                listeners.put(name, metaMethod);
            }
        }
    }
}
Also used : NewInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod) NewMetaMethod(org.codehaus.groovy.runtime.metaclass.NewMetaMethod) MixinInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod) NewStaticMetaMethod(org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) ClosureMetaMethod(org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod) TransformMetaMethod(org.codehaus.groovy.runtime.metaclass.TransformMetaMethod) PropertyDescriptor(java.beans.PropertyDescriptor) PrivilegedActionException(java.security.PrivilegedActionException) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) NewInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod) Method(java.lang.reflect.Method) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) NewMetaMethod(org.codehaus.groovy.runtime.metaclass.NewMetaMethod) MixinInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod) NewStaticMetaMethod(org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) ClosureMetaMethod(org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod) TransformMetaMethod(org.codehaus.groovy.runtime.metaclass.TransformMetaMethod) EventSetDescriptor(java.beans.EventSetDescriptor)

Aggregations

EventSetDescriptor (java.beans.EventSetDescriptor)55 Method (java.lang.reflect.Method)34 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)31 BeanInfo (java.beans.BeanInfo)10 MethodDescriptor (java.beans.MethodDescriptor)10 IntrospectionException (java.beans.IntrospectionException)9 PropertyDescriptor (java.beans.PropertyDescriptor)6 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)3 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 BeanDescriptor (java.beans.BeanDescriptor)2 PrivilegedActionException (java.security.PrivilegedActionException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 CachedMethod (org.codehaus.groovy.reflection.CachedMethod)2 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)2 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)2 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)2 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)2