• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MetaProperty类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: setProperty

import groovy.lang.MetaProperty; //导入依赖的package包/类
public void setProperty(final String name, Object value, SetPropertyResult result) {
    if (!includeProperties) {
        return;
    }

    MetaClass metaClass = getMetaClass();
    MetaProperty property = lookupProperty(metaClass, name);
    if (property != null) {
        if (property instanceof MultipleSetterProperty) {
            // Invoke the setter method, to pick up type coercion
            String setterName = MetaProperty.getSetterName(property.getName());
            InvokeMethodResult setterResult = new InvokeMethodResult();
            invokeMethod(setterName, setterResult, value);
            if (setterResult.isFound()) {
                result.found();
                return;
            }
        } else {
            if (property instanceof MetaBeanProperty) {
                MetaBeanProperty metaBeanProperty = (MetaBeanProperty) property;
                if (metaBeanProperty.getSetter() == null) {
                    if (metaBeanProperty.getField() == null) {
                        throw setReadOnlyProperty(name);
                    }
                    value = propertySetTransformer.transformValue(metaBeanProperty.getField().getType(), value);
                    metaBeanProperty.getField().setProperty(bean, value);
                } else {
                    // Coerce the value to the type accepted by the property setter and invoke the setter directly
                    Class setterType = metaBeanProperty.getSetter().getParameterTypes()[0].getTheClass();
                    value = propertySetTransformer.transformValue(setterType, value);
                    value = DefaultTypeTransformation.castToType(value, setterType);
                    metaBeanProperty.getSetter().invoke(bean, new Object[]{value});
                }
            } else {
                // Coerce the value to the property type, if known
                value = propertySetTransformer.transformValue(property.getType(), value);
                property.setProperty(bean, value);
            }
            result.found();
            return;
        }
    }

    if (!implementsMissing) {
        return;
    }

    try {
        setOpaqueProperty(metaClass, name, value);
        result.found();
    } catch (MissingPropertyException e) {
        if (!name.equals(e.getProperty())) {
            throw e;
        }
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:57,代码来源:BeanDynamicObject.java


示例17: transformBinaryExpression

import groovy.lang.MetaProperty; //导入依赖的package包/类
private Expression transformBinaryExpression(final BinaryExpression exp) {
    Expression trn = super.transform(exp);
    if (trn instanceof BinaryExpression) {
        BinaryExpression bin = (BinaryExpression) trn;
        Expression leftExpression = bin.getLeftExpression();
        if (bin.getOperation().getType() == Types.EQUAL && leftExpression instanceof PropertyExpression) {
            ClassNode traitReceiver = null;
            PropertyExpression leftPropertyExpression = (PropertyExpression) leftExpression;
            if (isTraitSuperPropertyExpression(leftPropertyExpression.getObjectExpression())) {
                PropertyExpression pexp = (PropertyExpression) leftPropertyExpression.getObjectExpression();
                traitReceiver = pexp.getObjectExpression().getType();
            }
            if (traitReceiver!=null) {
                // A.super.foo = ...
                TraitHelpersTuple helpers = Traits.findHelpers(traitReceiver);
                ClassNode helper = helpers.getHelper();
                String setterName = MetaProperty.getSetterName(leftPropertyExpression.getPropertyAsString());
                List<MethodNode> methods = helper.getMethods(setterName);
                for (MethodNode method : methods) {
                    Parameter[] parameters = method.getParameters();
                    if (parameters.length==2 && parameters[0].getType().equals(traitReceiver)) {
                        ArgumentListExpression args = new ArgumentListExpression(
                                new VariableExpression("this"),
                                transform(exp.getRightExpression())
                        );
                        MethodCallExpression setterCall = new MethodCallExpression(
                                new ClassExpression(helper),
                                setterName,
                                args
                        );
                        setterCall.setMethodTarget(method);
                        setterCall.setImplicitThis(false);
                        return setterCall;
                    }
                }
                return bin;
            }
        }
    }
    return trn;
}
 
开发者ID:apache,项目名称:groovy,代码行数:42,代码来源:SuperCallTraitTransformer.java


示例18: GetEffectivePojoPropertySite

import groovy.lang.MetaProperty; //导入依赖的package包/类
public GetEffectivePojoPropertySite(CallSite site, MetaClassImpl metaClass, MetaProperty effective) {
    super(site);
    this.metaClass = metaClass;
    this.effective = effective;
    version = metaClass.getVersion();
}
 
开发者ID:apache,项目名称:groovy,代码行数:7,代码来源:GetEffectivePojoPropertySite.java


示例19: GetEffectivePogoPropertySite

import groovy.lang.MetaProperty; //导入依赖的package包/类
public GetEffectivePogoPropertySite(CallSite site, MetaClass metaClass, MetaProperty effective) {
    super(site);
    this.metaClass = metaClass;
    this.effective = effective;
}
 
开发者ID:apache,项目名称:groovy,代码行数:6,代码来源:GetEffectivePogoPropertySite.java


示例20: RankableField

import groovy.lang.MetaProperty; //导入依赖的package包/类
public RankableField(String name, MetaProperty mp) {
    this.f = mp;
    this.score = delDistance(name,mp.getName());
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:MethodRankHelper.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ZipOutputStream类代码示例发布时间:2022-05-22
下一篇:
Java AbstractFilter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap