public Class getType() { return mp.getType(); }
public Class getReturnType() { return property.getType(); }
public Class getReturnType() { return property.getType(); }
@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); }
@Override public ISlot create(Object owner, Type ownerType, String name) { String plural = toPluralForm(name); MetaProperty property = GroovyRuntimeUtil.getMetaClass(owner).getMetaProperty(plural); return property != null && Collection.class.isAssignableFrom(property.getType()) && MopUtil.isReadable(property) ? new CollectionSlot(plural, owner, ownerType, property) : null; }
public MixinInstanceMetaProperty(MetaProperty property, MixinInMetaClass mixinInMetaClass) { super(property.getName(), property.getType(), createGetter(property, mixinInMetaClass), createSetter(property, mixinInMetaClass)); }
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)); } }; } }
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; } }; }
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)) {
public Class getType() { return mp.getType(); }
public Class getType() { return mp.getType(); }
public Class getReturnType() { return property.getType(); }
public Class getReturnType() { return property.getType(); }
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; }
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; }
@SuppressWarnings("unchecked") public List<PropertyDescriptor> getPropertiesAssignableFromType(Class assignableType) { 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().isAssignableFrom( assignableType )) continue; addBeanProperty(propertyDescriptors, property); } return propertyDescriptors; }
@SuppressWarnings("unchecked") public List<PropertyDescriptor> getPropertiesAssignableToType(Class assignableType) { 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("$") || !assignableType.isAssignableFrom(property.getType())) { continue; } addBeanProperty(propertyDescriptors, property); } return propertyDescriptors; }
private void initGroovyCommands(final ScriptEngine scriptEngine, final ScriptContext scriptContext) { Commands commands = new Commands(scriptContext); for (MetaProperty mp : commands.getMetaClass().getProperties()) { String propertyType = mp.getType().getCanonicalName(); String propertyName = mp.getName(); if (propertyType.equals(groovy.lang.Closure.class.getCanonicalName())) { scriptEngine.put(propertyName, commands.getProperty(propertyName)); } } }
public static Class<?> getPropertyType(Class<?> cls, String propertyName) { MetaProperty metaProperty = GroovySystem.getMetaClassRegistry().getMetaClass(cls).getMetaProperty(propertyName); if(metaProperty != null) { return metaProperty.getType(); } return null; }
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; }