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;
}
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());
}
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)));
}
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);
}
}
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);
}
}
}
}
Aggregations