如何使用new API(Java 9)在运行时获取JavaBean信息?

How to obtain JavaBean informations at runtime with new API (Java 9)?

我开发了一个库(JAXX) to generate Swing java file using JavaBean information of Swing widgets, that I am trying to migrate to Java > 9 (See issue)。

使用新的 JavaBean API 不再有效,因为我使用运行时反射从 bean 获取信息(参见 JAXXIntrospector class)。

private static BeanInfo getExplicitBeanInfo(ClassDescriptor classDescriptor) {
    try {
        Class<?> beanClass = Class.forName(classDescriptor.getName(), true, classDescriptor.getClassLoader()); // see if there is a class by that name in this package
        Method findExplicitBeanInfo = Introspector.class.getDeclaredMethod("findExplicitBeanInfo", Class.class);
        findExplicitBeanInfo.setAccessible(true);
        return (BeanInfo) findExplicitBeanInfo.invoke(null, beanClass);
    } catch (ClassNotFoundException | NoClassDefFoundError e) {
        return null; // happens for uncompiled classes
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Error: could not find method 'findExplicitBeanInfo' in java.beans.Introspector.  You are most likely running a version of Java against which JAXX has not been tested.");
    } catch (InvocationTargetException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

我现在试图找到如何使用 Jigsaw 获取这些信息,但找不到任何地方可以使用新的 API。

现在如何获取这些运行时信息?

谢谢。

使用publicAPI(Introspector.getBeanInfo)解决问题。