java.beans.BeanInfo Java Examples

The following examples show how to use java.beans.BeanInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertyManager.java    From jesterj with Apache License 2.0 6 votes vote down vote up
@Override
protected Set<Property> getProperties(Class<?> type) throws IntrospectionException {
  Set<Property> set = super.getProperties(type);
  Set<Property> filtered = new TreeSet<>();

  BeanInfo beanInfo = Introspector.getBeanInfo(type);
  PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
  Map<String, PropertyDescriptor> propMap = Arrays.asList(propertyDescriptors).stream().collect(Collectors.toMap(PropertyDescriptor::getName, Function.identity()));
  for (Property prop : set) {
    PropertyDescriptor pd = propMap.get(prop.getName());
    if (pd != null) {
      Method readMethod = pd.getReadMethod();
      AUTIL.runIfMethodAnnotated(readMethod, () -> filtered.add(prop), false, Transient.class);
    }
  }
  return filtered;
}
 
Example #2
Source File: BeanUtils.java    From jt808-server with Apache License 2.0 6 votes vote down vote up
public static Map<String, Object> toMapNotNull(Object obj) {
    if (obj == null)
        return null;

    Map<String, Object> result = new HashMap<>();

    BeanInfo beanInfo = getBeanInfo(obj.getClass());
    PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor pd : pds) {
        String name = pd.getName();
        if (ignores.contains(name))
            continue;

        Object value = getValue(obj, pd.getReadMethod());
        if (value != null)
            result.put(name, value);
    }
    return result;
}
 
Example #3
Source File: ExtendedBeanInfoTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void nonPublicStandardReadAndWriteMethods() throws Exception {
	@SuppressWarnings("unused") class C {
		String getFoo() { return null; }
		C setFoo(String foo) { return this; }
	}

	BeanInfo bi = Introspector.getBeanInfo(C.class);
	BeanInfo ebi = new ExtendedBeanInfo(bi);

	assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
	assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));

	assertThat(hasReadMethodForProperty(ebi, "foo"), is(false));
	assertThat(hasWriteMethodForProperty(ebi, "foo"), is(false));
}
 
Example #4
Source File: MapUtils.java    From utils with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> toStringMap(Object obj) {
    Map<String, String> map = null;
    if (obj == null) {
        return map;
    }

    map = new HashMap<String, String>();
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor property : propertyDescriptors) {
            String key = property.getName();
            if (!key.equals("class")) {
                Method getter = property.getReadMethod();
                map.put(key, getter.invoke(obj).toString());
            }

        }
    } catch (Exception e) {
        map = null;
    }

    return map;
}
 
Example #5
Source File: JOutlookBarBeanInfo.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/** Constructor for the JOutlookBarBeanInfo object */
public JOutlookBarBeanInfo() throws java.beans.IntrospectionException
{
	// setup bean descriptor in constructor. 
    bd.setName("JOutlookBar");

    bd.setShortDescription("JOutlookBar brings the famous Outlook component to Swing");

    BeanInfo info = Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass());
    String order = info.getBeanDescriptor().getValue("propertyorder") == null ? "" : (String) info.getBeanDescriptor().getValue("propertyorder");
    PropertyDescriptor[] pd = getPropertyDescriptors();
    for (int i = 0; i != pd.length; i++)
    {
       if (order.indexOf(pd[i].getName()) == -1)
       {
          order = order + (order.length() == 0 ? "" : ":") + pd[i].getName();
       }
    }
    getBeanDescriptor().setValue("propertyorder", order);
}
 
Example #6
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_MixedSimpleClass19() throws Exception {
    BeanInfo info = Introspector.getBeanInfo(MixedSimpleClass19.class);
    Method getter = MixedSimpleClass19.class.getDeclaredMethod("getList",
            int.class);
    Method setter = MixedSimpleClass19.class.getDeclaredMethod("setList",
            int.class, Object.class);

    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
        if (propertyName.equals(pd.getName())) {
            assertTrue(pd instanceof IndexedPropertyDescriptor);
            assertNull(pd.getReadMethod());
            assertNull(pd.getWriteMethod());
            assertEquals(getter, ((IndexedPropertyDescriptor) pd)
                    .getIndexedReadMethod());
            assertEquals(setter, ((IndexedPropertyDescriptor) pd)
                    .getIndexedWriteMethod());
        }
    }
}
 
Example #7
Source File: AbstractContextMenuFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
//        System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
        item.setName(action);
        item.putClientProperty(KEY_ACTION, action);
        item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
        item.putClientProperty(KEY_CREATOR, this);
        item.setText(
            provider.getDisplayName(action, containerCtx));
        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, context);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0; 
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
        //Intentionally use enabled property
        item.setVisible(enabled);
        item.setMnemonic(provider.getMnemonic(action, containerCtx));
        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
Example #8
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_MixedBooleanSimpleClass3() throws Exception {
    BeanInfo info = Introspector
            .getBeanInfo(MixedBooleanSimpleClass3.class);
    Method getter = MixedBooleanSimpleClass3.class.getDeclaredMethod(
            "getList", int.class);

    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
        if (propertyName.equals(pd.getName())) {
            assertTrue(pd instanceof IndexedPropertyDescriptor);
            assertNull(pd.getReadMethod());
            assertNull(pd.getWriteMethod());
            assertEquals(getter, ((IndexedPropertyDescriptor) pd)
                    .getIndexedReadMethod());
            assertNull(((IndexedPropertyDescriptor) pd)
                    .getIndexedWriteMethod());
        }
    }
}
 
Example #9
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testMockIncompatibleGetterAndIndexedGetterBean() throws Exception {
    Class<?> beanClass = MockIncompatibleGetterAndIndexedGetterBean.class;
    BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
    PropertyDescriptor pd = null;
    PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
    for (int i = 0; i < pds.length; i++) {
        pd = pds[i];
        if (pd.getName().equals("data")) {
            break;
        }
    }
    assertNotNull(pd);
    assertTrue(pd instanceof IndexedPropertyDescriptor);
    IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
    assertNull(ipd.getReadMethod());
    assertNull(ipd.getWriteMethod());
    Method indexedReadMethod = beanClass.getMethod("getData",
            new Class[] { int.class });
    Method indexedWriteMethod = beanClass.getMethod("setData", new Class[] {
            int.class, int.class });
    assertEquals(indexedReadMethod, ipd.getIndexedReadMethod());
    assertEquals(indexedWriteMethod, ipd.getIndexedWriteMethod());
}
 
Example #10
Source File: RootClassInfo.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private RootClassInfo(String className, List<String> warnings) {
    super();
    this.className = className;
    this.warnings = warnings;

    if (className == null) {
        return;
    }

    try {
        Class<?> clazz = ObjectFactory.externalClassForName(className);
        BeanInfo bi = Introspector.getBeanInfo(clazz);
        propertyDescriptors = bi.getPropertyDescriptors();
    } catch (Exception e) {
        propertyDescriptors = null;
        warnings.add(getString("Warning.20", className)); //$NON-NLS-1$
    }
}
 
Example #11
Source File: ExtendedBeanInfoTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void propertyCountsWithNonStandardWriteMethod() throws IntrospectionException {
	class ExtendedTestBean extends TestBean {
		@SuppressWarnings("unused")
		public ExtendedTestBean setFoo(String s) { return this; }
	}
	BeanInfo bi = Introspector.getBeanInfo(ExtendedTestBean.class);
	BeanInfo ebi = new ExtendedBeanInfo(bi);

	boolean found = false;
	for (PropertyDescriptor pd : ebi.getPropertyDescriptors()) {
		if (pd.getName().equals("foo")) {
			found = true;
		}
	}
	assertThat(found, is(true));
	assertThat(ebi.getPropertyDescriptors().length, equalTo(bi.getPropertyDescriptors().length+1));
}
 
Example #12
Source File: FieldHelper.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 通过方法获取属性
 *
 * @param entityClass
 * @return
 */
@Override
public List<EntityField> getProperties(Class<?> entityClass) {
    List<EntityField> entityFields = new ArrayList<EntityField>();
    BeanInfo beanInfo = null;
    try {
        beanInfo = Introspector.getBeanInfo(entityClass);
    } catch (IntrospectionException e) {
        throw new MapperException(e);
    }
    PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor desc : descriptors) {
        if (!"class".equals(desc.getName())) {
            entityFields.add(new EntityField(null, desc));
        }
    }
    return entityFields;
}
 
Example #13
Source File: ExtendedBeanInfoTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void indexedWriteMethodOnly() throws IntrospectionException {
	@SuppressWarnings("unused")
	class C {
		// indexed write method
		public void setFoos(int i, String foo) { }
	}

	BeanInfo bi = Introspector.getBeanInfo(C.class);
	BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));

	assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
	assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(true));

	assertThat(hasWriteMethodForProperty(ebi, "foos"), is(false));
	assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(true));
}
 
Example #14
Source File: TestUtils.java    From java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Test access to the properties of an object through its accessors.
 *
 * @param obj the object to test
 * @throws Exception any exception
 */
public static void assertNoExceptionsOnGetters(final Object obj) throws Exception {

  final Class<?> clazz = obj.getClass();
  final BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
  final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

  for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
    final Method readMethod = propertyDescriptor.getReadMethod();

    if (readMethod != null) {
      try {
        readMethod.invoke(obj, new Object[] {});
      } catch (final InvocationTargetException e) {
        final StringBuffer msg = new StringBuffer();
        msg.append("Failure: " + propertyDescriptor.getName());
        msg.append(" Exception: " + e.getCause().getClass());
        msg.append(" Msg: " + e.getCause().getMessage());
        throw new AssertionFailedError(msg.toString());
      }
    }
  }
}
 
Example #15
Source File: Test7195106.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] arg) throws Exception {
    BeanInfo info = Introspector.getBeanInfo(My.class);
    if (null == info.getIcon(BeanInfo.ICON_COLOR_16x16)) {
        throw new Error("Unexpected behavior");
    }
    try {
        int[] array = new int[1024];
        while (true) {
            array = new int[array.length << 1];
        }
    }
    catch (OutOfMemoryError error) {
        System.gc();
    }
    if (null == info.getIcon(BeanInfo.ICON_COLOR_16x16)) {
        throw new Error("Explicit BeanInfo is collected");
    }
}
 
Example #16
Source File: ExtendedBeanInfoTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * {@link ExtendedBeanInfo} should behave exactly like {@link BeanInfo}
 * in strange edge cases.
 */
@Test
public void readMethodReturnsSubtypeOfWriteMethodParameter() throws IntrospectionException {
	@SuppressWarnings("unused") class C {
		public Integer getFoo() { return null; }
		public void setFoo(Number foo) { }
	}

	BeanInfo bi = Introspector.getBeanInfo(C.class);
	BeanInfo ebi = new ExtendedBeanInfo(bi);

	assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
	assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));

	assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
	assertThat(hasWriteMethodForProperty(ebi, "foo"), is(false));
}
 
Example #17
Source File: ObjectUtil.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
public static void copyProperties(Object fromObj, Object toObj) {
    Class<?> fromClass = fromObj.getClass();
    Class<?> toClass = toObj.getClass();

    try {
        BeanInfo fromBean = Introspector.getBeanInfo(fromClass);
        BeanInfo toBean = Introspector.getBeanInfo(toClass);

        PropertyDescriptor[] toPd = toBean.getPropertyDescriptors();
        List<PropertyDescriptor> fromPd = Arrays.asList(fromBean.getPropertyDescriptors());

        for (PropertyDescriptor propertyDescriptor : toPd) {
            propertyDescriptor.getDisplayName();
            PropertyDescriptor pd = fromPd.get(fromPd.indexOf(propertyDescriptor));
            if (pd.getDisplayName().equals(
                    propertyDescriptor.getDisplayName()) &&
                    !pd.getDisplayName().equals("class") &&
                    propertyDescriptor.getWriteMethod() != null) {
                propertyDescriptor.getWriteMethod().invoke(toObj, pd.getReadMethod().invoke(fromObj, null));
            }

        }
    } catch (IntrospectionException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
        throw new RuntimeException(e);
    }
}
 
Example #18
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_MixedSimpleClass61() throws Exception {
    BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass61.class);
    Method getter = MixedSimpleClass61.class.getMethod("getList",
            new Class<?>[] { int.class });
    Method setter = MixedSimpleClass61.class.getMethod("setList",
            new Class<?>[] { int.class, boolean.class });
    assertEquals(2, beanInfo.getPropertyDescriptors().length);
    for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
        if (propertyName.equals(pd.getName())) {
            assertNull(pd.getReadMethod());
            assertNull(pd.getWriteMethod());
            assertTrue(pd instanceof IndexedPropertyDescriptor);
            assertEquals(getter,
                    ((IndexedPropertyDescriptor) pd).getIndexedReadMethod());
            assertEquals(setter,
                    ((IndexedPropertyDescriptor) pd)
                            .getIndexedWriteMethod());
        }
    }
}
 
Example #19
Source File: DocumentConfiguration.java    From Cheddar with Apache License 2.0 6 votes vote down vote up
public DocumentConfiguration(final Class<? extends Document> documentClass, final String namespace) {
    if (documentClass == null) {
        throw new IllegalArgumentException("Document class for DocumentConfiguration must not be empty");
    }
    if (namespace == null || namespace.isEmpty()) {
        throw new IllegalArgumentException("Namespace for DocumentConfiguration must not be empty");
    }
    this.documentClass = documentClass;
    this.namespace = namespace;
    indexDefinitions = new ArrayList<IndexDefinition>();
    properties = new HashMap<>();
    try {
        final BeanInfo beanInfo = Introspector.getBeanInfo(documentClass);
        final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (final PropertyDescriptor prop : propertyDescriptors) {
            if (!EXCLUDED_PROPERTIES.contains(prop.getName())) {
                properties.put(prop.getName(), prop);
            }
        }
    } catch (final IntrospectionException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #20
Source File: AbstractVisualResource.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Sets the value for a specified parameter.
 *
 * @param paramaterName the name for the parameteer
 * @param parameterValue the value the parameter will receive
 */
@Override
public void setParameterValue(String paramaterName, Object parameterValue)
            throws ResourceInstantiationException{
  // get the beaninfo for the resource bean, excluding data about Object
  BeanInfo resBeanInf = null;
  try {
    resBeanInf = Introspector.getBeanInfo(this.getClass(), Object.class);
  } catch(Exception e) {
    throw new ResourceInstantiationException(
      "Couldn't get bean info for resource " + this.getClass().getName()
      + Strings.getNl() + "Introspector exception was: " + e
    );
  }
  AbstractResource.setParameterValue(this, resBeanInf, paramaterName, parameterValue);
}
 
Example #21
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_MixedBooleanSimpleClass31() throws Exception {
    BeanInfo info = Introspector
            .getBeanInfo(MixedBooleanSimpleClass31.class);
    Method indexedGetter = MixedBooleanSimpleClass31.class
            .getDeclaredMethod("getList", int.class);

    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
        if (propertyName.equals(pd.getName())) {
            assertTrue(pd instanceof IndexedPropertyDescriptor);
            assertNull(pd.getReadMethod());
            assertNull(pd.getWriteMethod());
            assertEquals(indexedGetter, ((IndexedPropertyDescriptor) pd)
                    .getIndexedReadMethod());
            assertNull(((IndexedPropertyDescriptor) pd)
                    .getIndexedWriteMethod());

        }
    }
}
 
Example #22
Source File: ProcessVarBeanInfo.java    From AndrOBD with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public BeanInfo[] getAdditionalBeanInfo()
{//GEN-FIRST:Superclass
	Class superclass = ProcessVar.class.getSuperclass();
	BeanInfo sbi = null;
	try
	{
		sbi = Introspector.getBeanInfo(superclass);//GEN-HEADEREND:Superclass

		// Here you can add code for customizing the Superclass BeanInfo.

	} catch (IntrospectionException ignored)
	{
	}
	return new BeanInfo[]{sbi};
}
 
Example #23
Source File: SimpleObjectExporter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void createFields ()
{
    try
    {
        final BeanInfo bi = Introspector.getBeanInfo ( this.objectClass );
        for ( final PropertyDescriptor pd : bi.getPropertyDescriptors () )
        {
            if ( pd.getReadMethod () != null )
            {
                createDataItem ( pd );
            }
        }
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to create fields", e );
    }
}
 
Example #24
Source File: UISupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Image computeIcon(ServerIcon serverIcon) {
    // get the default folder icon
    Node folderNode = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
    Image folder;
    if (serverIcon == ServerIcon.EJB_OPENED_FOLDER || serverIcon == ServerIcon.WAR_OPENED_FOLDER 
            || serverIcon == ServerIcon.EAR_OPENED_FOLDER) {
        folder = folderNode.getOpenedIcon(BeanInfo.ICON_COLOR_16x16);
    } else {
        folder = folderNode.getIcon(BeanInfo.ICON_COLOR_16x16);
    }
    Image badge;
    if (serverIcon == ServerIcon.EJB_FOLDER || serverIcon == ServerIcon.EJB_OPENED_FOLDER) {
        badge = ImageUtilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/ejbBadge.png"); // NOI18N
    } else if (serverIcon == ServerIcon.WAR_FOLDER || serverIcon == ServerIcon.WAR_OPENED_FOLDER) {
        badge = ImageUtilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/warBadge.png"); // NOI18N
    } else if (serverIcon == ServerIcon.EAR_FOLDER || serverIcon == ServerIcon.EAR_OPENED_FOLDER) {
        badge = ImageUtilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/earBadge.png" ); // NOI18N
    } else {
        return null;
    }
    return ImageUtilities.mergeImages(folder, badge, 7, 7);
}
 
Example #25
Source File: GlslFragmentShaderDataLoaderBeanInfo.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #26
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_MixedExtendClass6() throws Exception {
    BeanInfo info = Introspector.getBeanInfo(MixedExtendClass6.class);
    Method getter = MixedExtendClass6.class.getDeclaredMethod("getList");
    Method setter = MixedSimpleClass25.class.getDeclaredMethod("setList",
            Object.class);

    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
        if (propertyName.equals(pd.getName())) {
            assertFalse(pd instanceof IndexedPropertyDescriptor);
            assertEquals(getter, pd.getReadMethod());
            assertEquals(setter, pd.getWriteMethod());
            break;
        }
    }
}
 
Example #27
Source File: RunAnalysisPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon() {
    try {
        DataObject d = DataObject.find(file);
        Node n = d.getNodeDelegate();
        return ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
    } catch (DataObjectNotFoundException ex) {
        LOG.log(Level.FINE, null, ex);
        return null;
    }
}
 
Example #28
Source File: CachedIntrospectionResultsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void shouldUseExtendedBeanInfoWhenApplicable() throws NoSuchMethodException, SecurityException {
	// given a class with a non-void returning setter method
	@SuppressWarnings("unused")
	class C {
		public Object setFoo(String s) { return this; }
		public String getFoo() { return null; }
	}

	// CachedIntrospectionResults should delegate to ExtendedBeanInfo
	CachedIntrospectionResults results = CachedIntrospectionResults.forClass(C.class);
	BeanInfo info = results.getBeanInfo();
	PropertyDescriptor pd = null;
	for (PropertyDescriptor candidate : info.getPropertyDescriptors()) {
		if (candidate.getName().equals("foo")) {
			pd = candidate;
		}
	}

	// resulting in a property descriptor including the non-standard setFoo method
	assertThat(pd, notNullValue());
	assertThat(pd.getReadMethod(), equalTo(C.class.getMethod("getFoo")));
	assertThat(
			"No write method found for non-void returning 'setFoo' method. " +
			"Check to see if CachedIntrospectionResults is delegating to " +
			"ExtendedBeanInfo as expected",
			pd.getWriteMethod(), equalTo(C.class.getMethod("setFoo", String.class)));
}
 
Example #29
Source File: CacheManagerTestBaseHid.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void checkStruct(FileSystem f) throws Exception {
    assertEquals("Root has 5 children", 5, f.getRoot().getChildren().length);
    assertEquals(1, f.findResource("bar").getChildren().length);
    assertEquals("", slurp(f, "bar/test5"));
    assertEquals(5, f.findResource("foo").getChildren().length);
    // XXX not clear if this is in fact supposed to be empty instead:
    //assertEquals("lala", slurp(f, "foo/test1"));
    assertEquals("two", attr(f, "foo/test1", "y"));
    assertEquals("rara!", slurp(f, "foo/test2"));
    assertEquals("hi!", slurp(f, "foo/test3"));
    assertEquals("three", attr(f, "foo/test3", "x"));
    assertEquals("one too", attr(f, "foo/test3", "y"));
    assertEquals("", slurp(f, "foo/test4"));
    // #29356: methodvalue should pass in MultiFileObject, not the original FileObject:
    FileSystem ffs = FileUtil.createMemoryFileSystem();
    FileUtil.createData(ffs.getRoot(), "foo/29356").setAttribute("x", "val");
    MultiFileSystem mfs = new MultiFileSystem(f, ffs);
    assertEquals("val", attr(ffs, "foo/29356", "x"));
    assertEquals("val", attr(mfs, "foo/29356", "x"));
    assertEquals("val/a", attr(mfs, "foo/29356", "a"));
    assertEquals("val", attr(mfs, "foo/29356", "map1"));
    assertEquals("val/map2", attr(mfs, "foo/29356", "map2"));
    assertEquals("Ahoj", attr(mfs, "foo/29356", "mapDisplayName"));

    StatusDecorator s = FileUtil.getConfigRoot().getFileSystem().getDecorator();
    ImageDecorator id = FileUIUtils.getImageDecorator(FileUtil.getConfigRoot().getFileSystem());
    FileObject annot = f.findResource("foo/29356");
    String annotName = s.annotateName(null, Collections.singleton(annot));
    assertEquals("Ahoj", annotName);

    Image img = id.annotateIcon(null, BeanInfo.ICON_COLOR_16x16, Collections.singleton(annot));
    assertNotNull("Icon provided", img);
    assertEquals("height", 16, img.getHeight(this));
    assertEquals("width", 16, img.getHeight(this));
    Image img32 = id.annotateIcon(null, BeanInfo.ICON_COLOR_32x32, Collections.singleton(annot));
    assertNotNull("Icon 32 provided", img32);
    assertEquals("height", 32, img32.getHeight(this));
    assertEquals("width", 32, img32.getHeight(this));
}
 
Example #30
Source File: TestIntrospector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void test(StringBuilder sb, Class type) throws IntrospectionException {
    long time = 0L;
    if (sb != null) {
        time = -System.currentTimeMillis();
    }
    BeanInfo info = Introspector.getBeanInfo(type);
    if (sb != null) {
        time += System.currentTimeMillis();
        sb.append('\n').append(time);
        sb.append('\t').append(info.getPropertyDescriptors().length);
        sb.append('\t').append(info.getEventSetDescriptors().length);
        sb.append('\t').append(info.getMethodDescriptors().length);
        sb.append('\t').append(type.getName());
    }
}