public Object getValue() { return mp.getProperty(bean); }
private static MetaMethod createSetter(final MetaProperty property, final MixinInMetaClass mixinInMetaClass) { return new MetaMethod() { final String name = getSetterName(property.getName()); { setParametersTypes (new CachedClass [] {ReflectionCache.getCachedClass(property.getType())} ); } public int getModifiers() { return Modifier.PUBLIC; } public String getName() { return name; } public Class getReturnType() { return property.getType(); } public CachedClass getDeclaringClass() { return mixinInMetaClass.getInstanceClass(); } public Object invoke(Object object, Object[] arguments) { property.setProperty(mixinInMetaClass.getMixinInstance(object), arguments[0]); return null; } }; }
@Override @SuppressWarnings("unchecked") public void write(Object value) { Collection collection = (Collection) property.getProperty(owner); if (collection == null) { if (MopUtil.isWriteable(property)) { collection = createCollection(property.getType()); property.setProperty(owner, collection); } else { throw new RuntimeException(String.format( "Cannot add element to collection property '%s' because it is neither initialized nor does it have a setter", name)); } } collection.add(value); }
private static MetaMethod createGetter(final MetaProperty property, final MixinInMetaClass mixinInMetaClass) { return new MetaMethod() { final String name = getGetterName(property.getName(), property.getType()); { setParametersTypes (CachedClass.EMPTY_ARRAY); } public int getModifiers() { return Modifier.PUBLIC; } public String getName() { return name; } public Class getReturnType() { return property.getType(); } public CachedClass getDeclaringClass() { return mixinInMetaClass.getInstanceClass(); } public Object invoke(Object object, Object[] arguments) { return property.getProperty(mixinInMetaClass.getMixinInstance(object)); } }; } }
public List<PropertyDescriptor> getPropertiesOfType(Class javaClass) { List<MetaProperty> properties = theMetaClass.getProperties(); List<PropertyDescriptor> propertyDescriptors = new ArrayList<>(2); for (MetaProperty property : properties) { int modifiers = property.getModifiers(); if(Modifier.isStatic(modifiers) || property.getName().contains("$") || !property.getType().equals(javaClass)) continue; addBeanProperty(propertyDescriptors, property); } return propertyDescriptors; }
String prjProp = "lenskit." + prop.getName(); if (project.hasProperty(prjProp)) { Object val = project.findProperty(prjProp); String vstr = val != null ? val.toString() : null; logger.info("setting property {} to {}", prjProp, val); Class type = prop.getType(); Consumer<Object> set = (v) -> prop.setProperty(lenskit, v); if (type.equals(Property.class)) { Method m = null; try { m = lenskit.getClass().getMethod("get" + StringUtils.capitalize(prop.getName())); } catch (NoSuchMethodException e) { throw new RuntimeException(e); Type rt = args.get(Property.class.getTypeParameters()[0]); type = TypeUtils.getRawType(rt, Object.class); set = (v) -> ((Property) prop.getProperty(lenskit)).set(v);
public Class getType() { return mp.getType(); }
public String[] getIdentifierName() { if(idPropertiesArray != null) { return idPropertiesArray; } List<String> idProperties = new ArrayList<>(); ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(entity.getJavaClass()); for (MetaProperty metaProperty : cpf.getMetaProperties()) { int modifiers = metaProperty.getModifiers(); if(Modifier.isStatic(modifiers) || Modifier.isAbstract(modifiers)) { continue; } PropertyDescriptor pd = propertyFactory.createPropertyDescriptor(entity.getJavaClass(), metaProperty); if(pd != null) { if (hasAnnotation(cpf, pd, Id.class)) { idProperties.add(metaProperty.getName()); } else if (hasAnnotation(cpf, pd, EmbeddedId.class)) { idProperties.add(metaProperty.getName()); } } } if(idProperties.isEmpty()) { // default to just use 'id' idProperties.add(GormProperties.IDENTITY); } idPropertiesArray = idProperties.toArray(new String[idProperties.size()]); return idPropertiesArray; }
@Override public void write(Object value) { property.setProperty(owner, value); } }
method = mbp.getSetter(); MetaProperty f = mbp.getField(); if (method != null || (f != null && !Modifier.isFinal(f.getModifiers()))) { arguments = new Object[]{newValue}; field = f; if (Modifier.isFinal(field.getModifiers())) { if(!(this.isMap && isPrivateOrPkgPrivate(field.getModifiers()))) { field.setProperty(object, newValue); return;
if(cachedClass.isInterface()) continue; MetaProperty metaProperty = current.getMetaClass().getMetaProperty(name); if(metaProperty != null && Modifier.isStatic(metaProperty.getModifiers())) { Class type = metaProperty.getType(); if(type == Object.class || c.isAssignableFrom(type)) { if(metaProperty instanceof MetaBeanProperty) { Object val = metaProperty.getProperty(javaClass); if(c.isInstance(val)) { values.add((T) val); Object val = metaProperty.getProperty(javaClass); if(c.isInstance(val)) { values.add((T) val);
if (property instanceof MultipleSetterProperty) { String setterName = MetaProperty.getSetterName(property.getName()); DynamicInvokeResult setterResult = invokeMethod(setterName, value); if (setterResult.isFound()) { value = propertySetTransformer.transformValue(property.getType(), value); property.setProperty(bean, value);
private static Object getStaticPropertyValue(MetaClass theMetaClass, String name) { MetaProperty metaProperty = theMetaClass.getMetaProperty(name); if(metaProperty != null && Modifier.isStatic(metaProperty.getModifiers())) { return metaProperty.getProperty(theMetaClass.getTheClass()); } return null; }
public String getName() { return mp.getName(); }
if (metaProperty != null) if (isGetter) return metaProperty.getProperty(instance); else { metaProperty.setProperty(instance, optionalValue); return null;
public Class getPropertyType(String name, boolean onlyInstanceProperties) { MetaProperty metaProperty = theMetaClass.getMetaProperty(name); if(metaProperty != null) { boolean isStatic = Modifier.isStatic(metaProperty.getModifiers()); if(onlyInstanceProperties && isStatic) { return null; } else { return metaProperty.getType(); } } return null; }
MetaProperty metaProperty = super.getMetaProperty(propertyName); if (metaProperty instanceof MetaBeanProperty) { boolean staticProp = Modifier.isStatic(metaProperty.getModifiers()); if (isStatic==staticProp) { beanProperty = (MetaBeanProperty) metaProperty;
static public boolean isJavaBeanPropertyWritable(Object instance, String propertyName) { MetaClass mc = InvokerHelper.getMetaClass(instance); MetaProperty metaProperty = mc.getMetaProperty(propertyName); if(metaProperty != null) { String setterName = MetaProperty.getSetterName(propertyName); return !mc.respondsTo(instance, setterName, new Class[]{metaProperty.getType()}).isEmpty(); } else if(instance instanceof Script) { return ((Script)instance).getProperty(propertyName) != null; } return false; }
public MultipleSetterProperty(String name) { super(name, Object.class); this.setterName = MetaProperty.getSetterName(name); }