public static PropertyDescriptor[] getPropertyDescriptors(Class<?> objectClass) { // If the class is an interface, use custom method to get all prop descriptors in the inheritance hierarchy. // PropertyUtils.getPropertyDescriptors() does not work correctly for interface inheritance. It finds props in the // actual interface ok, but does not find props in the inheritance hierarchy. if (objectClass.isInterface()) { return getInterfacePropertyDescriptors(objectClass); } else { return PropertyUtils.getPropertyDescriptors(objectClass); } }
private static Set<String> getProperties(Class<?> clss) { final Set<String> result = new TreeSet<>(); final PropertyDescriptor[] map = PropertyUtils.getPropertyDescriptors(clss); for (PropertyDescriptor p : map) { if (p.getWriteMethod() != null) { result.add(p.getName()); } } return result; }
/** * Returns property accessor by class property name. * * @param clazz class from which to get property accessor. * @param prop name of the property. * * @return property accessor. */ public static PojoFieldAccessor getPojoFieldAccessor(Class clazz, String prop) { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz); if (descriptors != null) { for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getName().equals(prop)) { Field field = null; try { field = clazz.getDeclaredField(prop); } catch (Throwable ignore) { } return new PojoFieldAccessor(descriptor, field); } } } try { return new PojoFieldAccessor(clazz.getDeclaredField(prop)); } catch (Throwable e) { throw new IllegalArgumentException("POJO class " + clazz.getName() + " doesn't have '" + prop + "' property"); } }
Map<String, PropertyDescriptor> descriptors = Arrays.stream(PropertyUtils.getPropertyDescriptors(target)) .filter(d -> d.getReadMethod() != null && d.getReadMethod().isAnnotationPresent(PersistentProperty.class)) .collect(Collectors.toMap(PropertyDescriptor::getName, d -> d));
final Pattern p = Pattern.compile("^(cm_msg|[a-z][a-z][a-z]?)([0-9]+)_(\\w+)$"); try { final java.beans.PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(field); for (final java.beans.PropertyDescriptor property : properties) { final String propertyName = property.getName();
static PropertyDescriptor[] getInterfacePropertyDescriptors(Class<?> interfaceClass) { List<PropertyDescriptor> propDescriptors = new ArrayList<>(); propDescriptors.addAll(Arrays.asList(PropertyUtils.getPropertyDescriptors(interfaceClass)));
@Override public void exitFieldAccess(FieldAccessExpression expr) { final CodeBlock object = codeSnippet.get(expr.object()); final CodeBlock field = codeSnippet.get(expr.field()); final Object objectRef = blockOrMissing(object, expr.object()); final Expression o = expr.object(); final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(o.getType()); final ImmutableMap<String, PropertyDescriptor> propertyByName = Maps.uniqueIndex(Iterators.forArray(propertyDescriptors), FeatureDescriptor::getName); final String fieldName = field.toString(); final CodeBlock block; if (propertyByName.containsKey(fieldName)) { // we have the property, resolve the read method name for it final PropertyDescriptor descriptor = propertyByName.get(fieldName); final String methodName = descriptor.getReadMethod().getName(); block = CodeBlock.of("$L.$L()", objectRef, methodName); } else if (o instanceof Map) { // there wasn't any property, but the object is a Map, translate into .get() call block = CodeBlock.of("$L.get($S)", objectRef, field); } else { // this is basically an error, because we expected either a property to match or a map lookup. log.warn("Unable to determine field accessor for property {}", field); block = CodeBlock.of("null"); } codeSnippet.put(expr, block); }
SimpleBeanModelNode node = new SimpleBeanModelNode(root.getClass()); for (PropertyDescriptor d : PropertyUtils.getPropertyDescriptors(root)) { if (d.getReadMethod() == null) { continue;
for (PropertyDescriptor prop : PropertyUtils.getPropertyDescriptors(node.getClass())) { if (prop.getReadMethod() != null && Modifier.isPublic(prop.getReadMethod().getModifiers()) && prop.getReadMethod().getDeclaringClass() == node.getClass()) {
PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(getJavaClass());
Map<String, DictionaryInfo> sets = new TreeMap<String, DictionaryInfo>( String.CASE_INSENSITIVE_ORDER ); PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors( entityClass );
PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(openmrsObject); for (PropertyDescriptor property : properties) {
@Override public boolean hasChildren() { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(xmlizable); return descriptors.length != 0; }
@Override public boolean hasChildren() { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(xmlizable); return descriptors.length != 0; }
private List<PropertyDescriptor> getPropertyDescriptors() { List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>(); for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(xmlizable)) { if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { descriptors.add(descriptor); } } return descriptors; } }
private List<PropertyDescriptor> getPropertyDescriptors() { List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>(); for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(xmlizable)) { if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { descriptors.add(descriptor); } } return descriptors; } }
protected List<Field> getFields(Class<?> clz) { List<Field> result = new ArrayList<Field>(); if (clz == null) return result; for (PropertyDescriptor prop : PropertyUtils.getPropertyDescriptors(clz)) { FieldImpl field = getField(clz, prop); if (field != null) { result.add(field); } } return result; }
public static PropertyDescriptor[] getPropertyDescriptors(Class<?> objectClass) { // If the class is an interface, use custom method to get all prop descriptors in the inheritance hierarchy. // PropertyUtils.getPropertyDescriptors() does not work correctly for interface inheritance. It finds props in the // actual interface ok, but does not find props in the inheritance hierarchy. if (objectClass.isInterface()) { return getInterfacePropertyDescriptors(objectClass); } else { return PropertyUtils.getPropertyDescriptors(objectClass); } }
public static PropertyDescriptor[] getPropertyDescriptors(Class<?> objectClass) { // If the class is an interface, use custom method to get all prop descriptors in the inheritance hierarchy. // PropertyUtils.getPropertyDescriptors() does not work correctly for interface inheritance. It finds props in the // actual interface ok, but does not find props in the inheritance hierarchy. if (objectClass.isInterface()) { return getInterfacePropertyDescriptors(objectClass); } else { return PropertyUtils.getPropertyDescriptors(objectClass); } }
public static void setValue(Object obj, String type, Object value) { for (PropertyDescriptor desc : PropertyUtils .getPropertyDescriptors(obj)) { String semValue = getSemanticValue(desc); if (value == null) { continue; } if (type.equals(semValue)) { P.set(obj, desc.getName(), value); } } }