Search in sources :

Example 1 with MethodMetaProperty

use of org.codehaus.groovy.runtime.metaclass.MethodMetaProperty in project groovity by disney.

the class MetaPropertyLookup method getSettableMetaProperty.

public static final MetaProperty getSettableMetaProperty(Object o, String name) {
    final Class<?> c = o.getClass();
    ConcurrentHashMap<String, MetaProperty> properties = singlePropertyCache.get(c);
    if (properties == null) {
        MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(c);
        List<MetaProperty> mps = mc.getProperties();
        properties = new ConcurrentHashMap<>();
        for (MetaProperty mp : mps) {
            if (mp instanceof MetaBeanProperty) {
                MetaBeanProperty mbp = ((MetaBeanProperty) mp);
                if (mbp.getSetter() == null) {
                    CachedField cf = mbp.getField();
                    if (cf == null || cf.isFinal() || cf.isStatic()) {
                        continue;
                    }
                }
            } else if (mp instanceof MethodMetaProperty) {
                continue;
            }
            properties.put(mp.getName(), mp);
        }
        singlePropertyCache.putIfAbsent(c, properties);
    }
    return properties.get(name);
}
Also used : MetaClass(groovy.lang.MetaClass) MetaBeanProperty(groovy.lang.MetaBeanProperty) MethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty) MethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty) MetaProperty(groovy.lang.MetaProperty) CachedField(org.codehaus.groovy.reflection.CachedField)

Aggregations

MetaBeanProperty (groovy.lang.MetaBeanProperty)1 MetaClass (groovy.lang.MetaClass)1 MetaProperty (groovy.lang.MetaProperty)1 CachedField (org.codehaus.groovy.reflection.CachedField)1 MethodMetaProperty (org.codehaus.groovy.runtime.metaclass.MethodMetaProperty)1