public MetaProperty hasProperty(Object obj, String name) { return delegate.hasProperty(obj, name); }
/** * <p>Returns true of the implementing MetaClass has a property of the given name * * <p>Note that this method will only return true for realised properties and does not take into * account implementation of getProperty or propertyMissing * * @param self The object to inspect * @param name The name of the property of interest * @return The found MetaProperty or null if it doesn't exist * @see groovy.lang.MetaObjectProtocol#hasProperty(java.lang.Object, java.lang.String) * @since 1.6.1 */ public static MetaProperty hasProperty(Object self, String name) { return InvokerHelper.getMetaClass(self).hasProperty(self, name); }
/** * Handles the common English regular plurals with the following rules. * <ul> * <li>If childName ends in {consonant}y, replace 'y' with "ies". For example, allergy to allergies.</li> * <li>Otherwise, append 's'. For example, monkey to monkeys; employee to employees.</li> * </ul> * If the property does not exist then it will return childName unchanged. * * @see <a href="http://en.wikipedia.org/wiki/English_plural">English_plural</a> */ public String resolveChildRelationName(String parentName, Object parent, String childName, Object child) { boolean matchesIESRule = PLURAL_IES_PATTERN.matcher(childName).matches(); String childNamePlural = matchesIESRule ? childName.substring(0, childName.length() - 1) + "ies" : childName + "s"; MetaProperty metaProperty = InvokerHelper.getMetaClass(parent) .hasProperty(parent, childNamePlural); return metaProperty != null ? childNamePlural : childName; }
public static void checkPropNames(Object instance, Map<String, Object> args) { final MetaClass metaClass = InvokerHelper.getMetaClass(instance); for (String k : args.keySet()) { if (metaClass.hasProperty(instance, k) == null) throw new MissingPropertyException(k, instance.getClass()); } }
public Object getProperty(String property) { if(ExpandoMetaClass.isValidExpandoProperty(property)) { if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) || property.equals(ExpandoMetaClass.CONSTRUCTOR) || Holder.META_CLASS.hasProperty(this, property) == null) { return replaceDelegate().getProperty(property); } } return Holder.META_CLASS.getProperty(this, property); }
public MetaProperty hasProperty(Object obj, String name) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.hasProperty(owner, name); }
public Object getProperty(String property) { if (isValidExpandoProperty(property)) { if (property.equals(STATIC_QUALIFIER)) { return new ExpandoMetaProperty(property, true); } else if (property.equals(CONSTRUCTOR)) { return new ExpandoMetaConstructor(); } else { if (myMetaClass.hasProperty(this, property) == null) return new ExpandoMetaProperty(property); else return myMetaClass.getProperty(this, property); } } else { return myMetaClass.getProperty(this, property); } }
public void setChild(FactoryBuilderSupport builder, Object parent, Object child) { if (child == null) return; ObjectGraphBuilder ogbuilder = (ObjectGraphBuilder) builder; if (parent != null) { Map context = ogbuilder.getContext(); Map parentContext = ogbuilder.getParentContext(); String parentName = null; String childName = (String) context.get(NODE_NAME); if (parentContext != null) { parentName = (String) parentContext.get(NODE_NAME); } String propertyName = ogbuilder.relationNameResolver.resolveParentRelationName( parentName, parent, childName, child); MetaProperty metaProperty = InvokerHelper.getMetaClass(child) .hasProperty(child, propertyName); if (metaProperty != null) { metaProperty.setProperty(child, parent); } } }
private void resolveLazyReferences() { if (!lazyReferencesAllowed) return; for (NodeReference ref : lazyReferences) { if (ref.parent == null) continue; Object child = null; try { child = getProperty(ref.refId); } catch (MissingPropertyException mpe) { // ignore } if (child == null) { throw new IllegalArgumentException("There is no valid node for reference " + ref.parentName + "." + ref.childName + "=" + ref.refId); } // set child first childPropertySetter.setChild(ref.parent, child, ref.parentName, relationNameResolver.resolveChildRelationName(ref.parentName, ref.parent, ref.childName, child)); // set parent afterwards String propertyName = relationNameResolver.resolveParentRelationName(ref.parentName, ref.parent, ref.childName, child); MetaProperty metaProperty = InvokerHelper.getMetaClass(child) .hasProperty(child, propertyName); if (metaProperty != null) { metaProperty.setProperty(child, ref.parent); } } }
final MetaProperty metaProperty = InvokerHelper.getMetaClass(Class.class).hasProperty(instance, propertyName); if (metaProperty != null) if (isGetter)
@Override public MetaProperty hasProperty(Object obj, String name) { return adaptee.hasProperty(obj, name); }
public MetaProperty hasProperty(Object obj, String name) { return delegate.hasProperty(obj, name); }
public static void checkPropNames(Object instance, Map<String, Object> args) { final MetaClass metaClass = InvokerHelper.getMetaClass(instance); for (String k : args.keySet()) { if (metaClass.hasProperty(instance, k) == null) throw new MissingPropertyException(k, instance.getClass()); } } }
public boolean supports(Object object) { if (object == null) return false; MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass()); return mc.hasProperty(object, HIBERNATE_LAZY_INITIALIZER_PROP) != null; }
public Object getProperty(String property) { if(ExpandoMetaClass.isValidExpandoProperty(property)) { if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) || property.equals(ExpandoMetaClass.CONSTRUCTOR) || myMetaClass.hasProperty(this, property) == null) { return replaceDelegate().getProperty(property); } } return myMetaClass.getProperty(this, property); }
public Object getProperty(String property) { if(ExpandoMetaClass.isValidExpandoProperty(property)) { if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) || property.equals(ExpandoMetaClass.CONSTRUCTOR) || myMetaClass.hasProperty(this, property) == null) { return replaceDelegate().getProperty(property); } } return myMetaClass.getProperty(this, property); }
public Object getProperty(String property) { if(ExpandoMetaClass.isValidExpandoProperty(property)) { if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) || property.equals(ExpandoMetaClass.CONSTRUCTOR) || myMetaClass.hasProperty(this, property) == null) { return replaceDelegate().getProperty(property); } } return myMetaClass.getProperty(this, property); }
public MetaProperty hasProperty(Object obj, String name) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.hasProperty(owner, name); }
public MetaProperty hasProperty(Object obj, String name) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.hasProperty(owner, name); }
public MetaProperty hasProperty(Object obj, String name) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.hasProperty(owner, name); }