当前位置: 首页>>代码示例>>Java>>正文


Java MetaProperty类代码示例

本文整理汇总了Java中groovy.lang.MetaProperty的典型用法代码示例。如果您正苦于以下问题:Java MetaProperty类的具体用法?Java MetaProperty怎么用?Java MetaProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MetaProperty类属于groovy.lang包,在下文中一共展示了MetaProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProperties

import groovy.lang.MetaProperty; //导入依赖的package包/类
public Map<String, ?> getProperties() {
    if (!includeProperties) {
        return Collections.emptyMap();
    }

    Map<String, Object> properties = new HashMap<String, Object>();
    List<MetaProperty> classProperties = getMetaClass().getProperties();
    for (MetaProperty metaProperty : classProperties) {
        if (metaProperty.getName().equals("properties")) {
            properties.put("properties", properties);
            continue;
        }
        if (metaProperty instanceof MetaBeanProperty) {
            MetaBeanProperty beanProperty = (MetaBeanProperty) metaProperty;
            if (beanProperty.getGetter() == null) {
                continue;
            }
        }
        properties.put(metaProperty.getName(), metaProperty.getProperty(bean));
    }
    getOpaqueProperties(properties);
    return properties;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:24,代码来源:BeanDynamicObject.java

示例2: createPojoMetaClassGetPropertySite

import groovy.lang.MetaProperty; //导入依赖的package包/类
private CallSite createPojoMetaClassGetPropertySite(Object receiver) {
    final MetaClass metaClass = InvokerHelper.getMetaClass(receiver);

    CallSite site;
    if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
        site = new PojoMetaClassGetPropertySite(this);
    } else {
        final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(receiver.getClass(), receiver, name, false);
        if (effective != null) {
            if (effective instanceof CachedField)
                site = new GetEffectivePojoFieldSite(this, (MetaClassImpl) metaClass, (CachedField) effective);
            else
                site = new GetEffectivePojoPropertySite(this, (MetaClassImpl) metaClass, effective);
        } else {
            site = new PojoMetaClassGetPropertySite(this);
        }
    }

    array.array[index] = site;
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AbstractCallSite.java

示例3: createPogoMetaClassGetPropertySite

import groovy.lang.MetaProperty; //导入依赖的package包/类
private CallSite createPogoMetaClassGetPropertySite(GroovyObject receiver) {
    MetaClass metaClass = receiver.getMetaClass();

    CallSite site;
    if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
        site = new PogoMetaClassGetPropertySite(this, metaClass);
    } else {
        final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(this.array.owner, receiver, name, false);
        if (effective != null) {
            if (effective instanceof CachedField)
                site = new GetEffectivePogoFieldSite(this, metaClass, (CachedField) effective);
            else
                site = new GetEffectivePogoPropertySite(this, metaClass, effective);
        } else {
            site = new PogoMetaClassGetPropertySite(this, metaClass);
        }
    }

    array.array[index] = site;
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AbstractCallSite.java

示例4: getPropertySuggestionString

import groovy.lang.MetaProperty; //导入依赖的package包/类
/**
 * Returns a string detailing possible solutions to a missing field or property
 * if no good solutions can be found a empty string is returned.
 *
 * @param fieldName the missing field
 * @param type the class on which the field is sought
 * @return a string with probable solutions to the exception
 */
public static String getPropertySuggestionString(String fieldName, Class type){
    ClassInfo ci = ClassInfo.getClassInfo(type);
    List<MetaProperty>  fi = ci.getMetaClass().getProperties();
    List<RankableField> rf = new ArrayList<RankableField>(fi.size());
    StringBuilder sb = new StringBuilder();
    sb.append("\nPossible solutions: ");
    
    for(MetaProperty mp : fi) rf.add(new RankableField(fieldName, mp));
    Collections.sort(rf);

    int i = 0;
    for (RankableField f : rf) {
        if (i > MAX_RECOMENDATIONS) break;
        if (f.score > MAX_FIELD_SCORE) break;
        if(i > 0) sb.append(", ");
        sb.append(f.f.getName());
        i++;
    }
    return i > 0? sb.toString(): "";
}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:MethodRankHelper.java

示例5: setChild

import groovy.lang.MetaProperty; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:ObjectGraphBuilder.java

示例6: resolveConstrainedProperties

import groovy.lang.MetaProperty; //导入依赖的package包/类
private Map resolveConstrainedProperties(Object object, GrailsDomainClass dc) {
	Map constrainedProperties = null;
	if (dc != null) {
		constrainedProperties = dc.getConstrainedProperties();
	} else {
		// is this dead code? , didn't remove in case it's used somewhere
		MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass());
		MetaProperty metaProp = mc.getMetaProperty(CONSTRAINTS_PROPERTY);
		if (metaProp != null) {
			Object constrainedPropsObj = getMetaPropertyValue(metaProp, object);
			if (constrainedPropsObj instanceof Map) {
				constrainedProperties = (Map) constrainedPropsObj;
			}
		}
	}
	return constrainedProperties;
}
 
开发者ID:curtiszimmerman,项目名称:AlgoTrader,代码行数:18,代码来源:GrailsDataBinder.java

示例7: lookupProperty

import groovy.lang.MetaProperty; //导入依赖的package包/类
@Nullable
protected MetaProperty lookupProperty(MetaClass metaClass, String name) {
    if (metaClass instanceof MetaClassImpl) {
        // MetaClass.getMetaProperty(name) is very expensive when the property is not known. Instead, reach into the meta class to call a much more efficient lookup method
        try {
            return (MetaProperty) META_PROP_METHOD.invoke(metaClass, name, false);
        } catch (Throwable e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
    }

    // Some other meta-class implementation - fall back to the public API
    return metaClass.getMetaProperty(name);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:15,代码来源:BeanDynamicObject.java

示例8: createSetter

import groovy.lang.MetaProperty; //导入依赖的package包/类
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;
      }
  };
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:MixinInstanceMetaProperty.java

示例9: createGetter

import groovy.lang.MetaProperty; //导入依赖的package包/类
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));
        }
    };
}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:MixinInstanceMetaProperty.java

示例10: resolveChildRelationName

import groovy.lang.MetaProperty; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ObjectGraphBuilder.java

示例11: resolveLazyReferences

import groovy.lang.MetaProperty; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:32,代码来源:ObjectGraphBuilder.java

示例12: testInspectUninspectableProperty

import groovy.lang.MetaProperty; //导入依赖的package包/类
public void testInspectUninspectableProperty() {
    Object dummyInstance = new Object();
    Inspector inspector = getTestableInspector(dummyInstance);
    Class[] paramTypes = {Object.class, MetaProperty.class};
    Object[] params = {null, null};
    Mock mock = mock(PropertyValue.class, paramTypes, params);
    mock.expects(once()).method("getType");
    mock.expects(once()).method("getName");
    mock.expects(once()).method("getValue").will(throwException(new RuntimeException()));
    PropertyValue propertyValue = (PropertyValue) mock.proxy();
    String[] result = inspector.fieldInfo(propertyValue);
    assertEquals(Inspector.NOT_APPLICABLE, result[Inspector.MEMBER_VALUE_IDX]);
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:InspectorTest.java

示例13: getMetaPropertyValue

import groovy.lang.MetaProperty; //导入依赖的package包/类
/**
 * Hack because of bug in ThreadManagedMetaBeanProperty, http://jira.codehaus.org/browse/GROOVY-3723 , fixed since 1.6.5
 *
 * @param metaProperty
 * @param delegate
 * @return
 */
private Object getMetaPropertyValue(MetaProperty metaProperty, Object delegate) {
	if (metaProperty instanceof ThreadManagedMetaBeanProperty) {
		return ((ThreadManagedMetaBeanProperty) metaProperty).getGetter().invoke(delegate, MetaClassHelper.EMPTY_ARRAY);
	}

	return metaProperty.getProperty(delegate);
}
 
开发者ID:curtiszimmerman,项目名称:AlgoTrader,代码行数:15,代码来源:GrailsDataBinder.java

示例14: hasFieldTest

import groovy.lang.MetaProperty; //导入依赖的package包/类
@Test(groups = { TestGroups.UNIT })
public void hasFieldTest() {
    class TestClass {
        @SuppressWarnings("unused")
        public Object a = new Object();
    }

    Assert.assertTrue(DefaultGroovyMethods.hasProperty(TestClass.class, "a") == null);
    Assert.assertTrue(ClassUtil.hasField(TestClass.class, "a") instanceof MetaProperty);

    Assert.assertFalse(ClassUtil.hasField(TestClass.class, "b") instanceof MetaProperty);
    Assert.assertTrue(ClassUtil.hasField(TestClass.class, "b") == null);
}
 
开发者ID:vmware,项目名称:upgrade-framework,代码行数:14,代码来源:ClassUtilTest.java

示例15: initGroovyCommands

import groovy.lang.MetaProperty; //导入依赖的package包/类
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));
		}
	}
}
 
开发者ID:mgm-tp,项目名称:jfunk,代码行数:13,代码来源:ScriptExecutor.java


注:本文中的groovy.lang.MetaProperty类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。