类java.beans.MethodDescriptor源码实例Demo

下面列出了怎么用java.beans.MethodDescriptor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: j2objc   文件: EventSetDescriptorTest.java
public void testEventSetDescriptorStringClassMethodDescriptorArrayMethodMethod_ListenerMDNull()
        throws IntrospectionException, NoSuchMethodException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;

    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod(
            "addMockPropertyChangeListener", listenerType);
    Method removeMethod = sourceClass.getMethod(
            "removeMockPropertyChangeListener", listenerType);

    EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
            listenerType, (MethodDescriptor[]) null, addMethod,
            removeMethod);

    assertNull(esd.getListenerMethodDescriptors());
    assertNull(esd.getListenerMethods());
}
 
源代码2 项目: j2objc   文件: MethodDescriptorTest.java
public void testMethodDescriptorMethod() throws SecurityException,
        NoSuchMethodException {
    String beanName = "MethodDescriptorTest.bean";
    MockJavaBean bean = new MockJavaBean(beanName);
    Method method = bean.getClass()
            .getMethod("getBeanName", (Class[]) null);
    MethodDescriptor md = new MethodDescriptor(method);

    assertSame(method, md.getMethod());
    assertNull(md.getParameterDescriptors());

    assertEquals(method.getName(), md.getDisplayName());
    assertEquals(method.getName(), md.getName());
    assertEquals(method.getName(), md.getShortDescription());

    assertNotNull(md.attributeNames());

    assertFalse(md.isExpert());
    assertFalse(md.isHidden());
    assertFalse(md.isPreferred());
}
 
源代码3 项目: j2objc   文件: EventSetDescriptorTest.java
public void testSetInDefaultEventSet_false() 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);
    assertTrue(esd.isInDefaultEventSet());
    esd.setInDefaultEventSet(false);
    assertFalse(esd.isInDefaultEventSet());
}
 
源代码4 项目: spring4-understanding   文件: ExtendedBeanInfo.java
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
	List<Method> matches = new ArrayList<Method>();
	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;
}
 
源代码5 项目: lucene-solr   文件: SolrPluginUtils.java
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());
}
 
源代码6 项目: nebula   文件: DefaultWidgetIntrospector.java
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);
	
}
 
源代码7 项目: j2objc   文件: IntrospectorTest.java
public void testGetBeanInfo_StaticMethods() throws Exception {
    BeanInfo beanInfo = Introspector.getBeanInfo(StaticClazz.class);
    PropertyDescriptor[] propertyDescriptors = beanInfo
            .getPropertyDescriptors();
    assertEquals(1, propertyDescriptors.length);
    assertTrue(contains("class", Class.class, propertyDescriptors));
    MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
    assertTrue(contains("getStaticMethod", methodDescriptors));
    assertTrue(contains("setStaticMethod", methodDescriptors));

    beanInfo = Introspector.getBeanInfo(StaticClazzWithProperty.class);
    propertyDescriptors = beanInfo.getPropertyDescriptors();
    assertEquals(1, propertyDescriptors.length);
    methodDescriptors = beanInfo.getMethodDescriptors();
    assertTrue(contains("getStaticName", methodDescriptors));
    assertTrue(contains("setStaticName", methodDescriptors));
}
 
源代码8 项目: lams   文件: ExtendedBeanInfo.java
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
	List<Method> matches = new ArrayList<Method>();
	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;
}
 
源代码9 项目: lams   文件: QuartzSchedulerMBeanImpl.java
private static Method findMethod(Class<?> targetType, String methodName,
        Class<?>[] argTypes) throws IntrospectionException {
    BeanInfo beanInfo = Introspector.getBeanInfo(targetType);
    if (beanInfo != null) {
        for(MethodDescriptor methodDesc: beanInfo.getMethodDescriptors()) {
            Method method = methodDesc.getMethod();
            Class<?>[] parameterTypes = method.getParameterTypes();
            if (methodName.equals(method.getName()) && argTypes.length == parameterTypes.length) {
                boolean matchedArgTypes = true;
                for (int i = 0; i < argTypes.length; i++) { 
                    if (getWrapperIfPrimitive(argTypes[i]) != parameterTypes[i]) {
                        matchedArgTypes = false;
                        break;
                    }
                }
                if (matchedArgTypes) {
                    return method;
                }
            }
        }
    }
    return null;
}
 
源代码10 项目: j2objc   文件: IntrospectorTest.java
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);
}
 
源代码11 项目: j2objc   文件: EventSetDescriptorTest.java
public void testSetUnicast_false() throws SecurityException,
        NoSuchMethodException, IntrospectionException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Method[] listenerMethods = {
            listenerType.getMethod("mockPropertyChange",
                    MockPropertyChangeEvent.class),
            listenerType.getMethod("mockPropertyChange2",
                    MockPropertyChangeEvent.class) };
    MethodDescriptor[] listenerMethodDescriptors = {
            new MethodDescriptor(listenerMethods[0]),
            new MethodDescriptor(listenerMethods[1]), };
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod(
            "addMockPropertyChangeListener",listenerType);
    Method removeMethod = sourceClass.getMethod(
            "removeMockPropertyChangeListener", listenerType);

    EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
            listenerType, listenerMethodDescriptors, addMethod,
            removeMethod);
    assertFalse(esd.isUnicast());
    esd.setInDefaultEventSet(false);
    assertFalse(esd.isInDefaultEventSet());
}
 
源代码12 项目: j2objc   文件: EventSetDescriptorTest.java
public void test_EventSetDescriptor_Constructor() throws Exception {
    EventSetDescriptor eventSetDescriptor = new EventSetDescriptor(
            (String) null, (Class<?>) null, new MethodDescriptor[] { null,
                    null }, (Method) null, (Method) null);
    assertNull(eventSetDescriptor.getName());
    assertNull(eventSetDescriptor.getListenerType());
    assertNull(eventSetDescriptor.getAddListenerMethod());
    assertNull(eventSetDescriptor.getRemoveListenerMethod());

    try {
        eventSetDescriptor.getListenerMethods();
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
        // Expected
    }
}
 
源代码13 项目: spring-analysis-note   文件: ExtendedBeanInfo.java
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 https://bugs.java.com/view_bug.do?bug_id=7023180
	matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
	return matches;
}
 
源代码14 项目: dragonwell8_jdk   文件: UnloadClassBeanInfo.java
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));
}
 
源代码15 项目: openjdk-8-source   文件: Test8005065.java
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);
    }
}
 
源代码16 项目: dragonwell8_jdk   文件: Test8005065.java
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);
    }
}
 
源代码17 项目: dragonwell8_jdk   文件: Test8005065.java
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);
    }
}
 
源代码18 项目: jdk8u-dev-jdk   文件: Test8005065.java
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);
    }
}
 
源代码19 项目: TencentKona-8   文件: Test6277246.java
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
源代码20 项目: jdk8u-jdk   文件: Test8005065.java
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);
    }
}
 
源代码21 项目: TencentKona-8   文件: Test8005065.java
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);
    }
}
 
/**
 * Gets the methodDescriptors attribute ...
 *
 * @return   The methodDescriptors value
 */
public MethodDescriptor[] getMethodDescriptors() {
   Vector descriptors = new Vector();
   MethodDescriptor descriptor = null;
   Method[] m;
   Method method;

   try {
      m = Class.forName("com.l2fprod.common.swing.JDirectoryChooser").getMethods();
   } catch (ClassNotFoundException e) {
      return new MethodDescriptor[0];
   }

   return (MethodDescriptor[]) descriptors.toArray(new MethodDescriptor[descriptors.size()]);
}
 
源代码23 项目: java-technology-stack   文件: ExtendedBeanInfo.java
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
	matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
	return matches;
}
 
/**
 * Gets the methodDescriptors attribute ...
 *
 * @return   The methodDescriptors value
 */
public MethodDescriptor[] getMethodDescriptors() {
   Vector descriptors = new Vector();
   MethodDescriptor descriptor = null;
   Method[] m;
   Method method;

   try {
      m = Class.forName("com.l2fprod.common.swing.JFontChooser").getMethods();
   } catch (ClassNotFoundException e) {
      return new MethodDescriptor[0];
   }

   return (MethodDescriptor[]) descriptors.toArray(new MethodDescriptor[descriptors.size()]);
}
 
/**
 * Gets the methodDescriptors attribute ...
 *
 * @return   The methodDescriptors value
 */
public MethodDescriptor[] getMethodDescriptors() {
   Vector descriptors = new Vector();
   MethodDescriptor descriptor = null;
   Method[] m;
   Method method;

   try {
      m = Class.forName("com.l2fprod.common.swing.JCollapsiblePane").getMethods();
   } catch (ClassNotFoundException e) {
      return new MethodDescriptor[0];
   }

   return (MethodDescriptor[]) descriptors.toArray(new MethodDescriptor[descriptors.size()]);
}
 
源代码26 项目: jdk8u60   文件: Test8040656.java
private static void test(Class<?> type, Class<?> bean) throws Exception {
    for (MethodDescriptor md : Introspector.getBeanInfo(bean).getMethodDescriptors()) {
        if (md.getName().equals("getFoo")) {
            if (type != md.getMethod().getReturnType()) {
                throw new Error("unexpected type");
            }
        }
    }
}
 
源代码27 项目: jdk8u60   文件: Test6277246.java
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
源代码28 项目: jdk8u60   文件: Test8005065.java
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);
    }
}
 
源代码29 项目: jdk8u60   文件: Test8005065.java
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);
    }
}
 
源代码30 项目: openjdk-8   文件: Test8005065.java
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);
    }
}
 
 类所在包
 同包方法