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


Java MetaClassHelper类代码示例

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


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

示例1: correctArguments

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
public Object[] correctArguments(Object[] argumentArray) {
    // correct argumentArray's length
    if (argumentArray == null) {
        return MetaClassHelper.EMPTY_ARRAY;
    }

    final CachedClass[] pt = getParameterTypes();
    if (pt.length == 1 && argumentArray.length == 0) {
        if (isVargsMethod)
            return new Object[]{Array.newInstance(pt[0].getTheClass().getComponentType(), 0)};
        else
            return MetaClassHelper.ARRAY_WITH_NULL;
    }

    if (isVargsMethod && isVargsMethod(argumentArray)) {
        return fitToVargs(argumentArray, pt);
    }

    return argumentArray;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ParameterTypes.java

示例2: isValidVarargsMethod

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private static boolean isValidVarargsMethod(Class[] arguments, int size, CachedClass[] pt, int paramMinus1) {
    // first check normal number of parameters
    for (int i = 0; i < paramMinus1; i++) {
        if (pt[i].isAssignableFrom(arguments[i])) continue;
        return false;
    }

    // check direct match
    CachedClass varg = pt[paramMinus1];
    Class clazz = varg.getTheClass().getComponentType();
    if (size == pt.length &&
            (varg.isAssignableFrom(arguments[paramMinus1]) ||
                    testComponentAssignable(clazz, arguments[paramMinus1]))) {
        return true;
    }

    // check varged
    for (int i = paramMinus1; i < size; i++) {
        if (MetaClassHelper.isAssignableFrom(clazz, arguments[i])) continue;
        return false;
    }
    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:ParameterTypes.java

示例3: checkDuplicateProperties

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private void checkDuplicateProperties(PropertyNode node) {
    ClassNode cn = node.getDeclaringClass();
    String name = node.getName();
    String getterName = "get" + MetaClassHelper.capitalize(name);
    if (Character.isUpperCase(name.charAt(0))) {
        for (PropertyNode propNode : cn.getProperties()) {
            String otherName = propNode.getField().getName();
            String otherGetterName = "get" + MetaClassHelper.capitalize(otherName);
            if (node != propNode && getterName.equals(otherGetterName)) {
                String msg = "The field " + name + " and " + otherName + " on the class " +
                        cn.getName() + " will result in duplicate JavaBean properties, which is not allowed";
                addError(msg, node);
            }
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ClassCompletionVerifier.java

示例4: createListenerSetter

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private void createListenerSetter(SourceUnit source, boolean bindable, ClassNode declaringClass, PropertyNode propertyNode) {
    if (bindable && needsPropertyChangeSupport(declaringClass, source)) {
        addPropertyChangeSupport(declaringClass);
    }
    if (needsVetoableChangeSupport(declaringClass, source)) {
        addVetoableChangeSupport(declaringClass);
    }
    String setterName = "set" + MetaClassHelper.capitalize(propertyNode.getName());
    if (declaringClass.getMethods(setterName).isEmpty()) {
        Expression fieldExpression = fieldX(propertyNode.getField());
        BlockStatement setterBlock = new BlockStatement();
        setterBlock.addStatement(createConstrainedStatement(propertyNode, fieldExpression));
        if (bindable) {
            setterBlock.addStatement(createBindableStatement(propertyNode, fieldExpression));
        } else {
            setterBlock.addStatement(createSetStatement(fieldExpression));
        }

        // create method void <setter>(<type> fieldName)
        createSetterMethod(declaringClass, propertyNode, setterName, setterBlock);
    } else {
        wrapSetterMethod(declaringClass, bindable, propertyNode.getName());
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:VetoableASTTransformation.java

示例5: getNormalMethodWithCaching

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private MetaMethod getNormalMethodWithCaching(Object[] arguments, MetaMethodIndex.Entry e) {
    MetaMethodIndex.CacheEntry cacheEntry;
    final Object methods = e.methods;
    if (methods == null)
      return null;

    cacheEntry = e.cachedMethod;

    if (cacheEntry != null &&
        MetaClassHelper.sameClasses(cacheEntry.params, arguments, methods instanceof MetaMethod))
    {
        MetaMethod method = cacheEntry.method;
        if (method!=null) return method;
    }

    final Class[] classes = MetaClassHelper.convertToTypeArray(arguments);
    cacheEntry = new MetaMethodIndex.CacheEntry (classes, (MetaMethod) chooseMethod(e.name, methods, classes));

    e.cachedMethod = cacheEntry;

    return cacheEntry.method;
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:MetaClassImpl.java

示例6: retrieveStaticMethod

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
public MetaMethod retrieveStaticMethod(String methodName, Object[] arguments) {
    final MetaMethodIndex.Entry e = metaMethodIndex.getMethods(theClass, methodName);
    MetaMethodIndex.CacheEntry cacheEntry;
    if (e != null) {
        cacheEntry = e.cachedStaticMethod;

        if (cacheEntry != null &&
            MetaClassHelper.sameClasses(cacheEntry.params, arguments, e.staticMethods instanceof MetaMethod))
        {
             return cacheEntry.method;
        }

        final Class[] classes = MetaClassHelper.convertToTypeArray(arguments);
        cacheEntry = new MetaMethodIndex.CacheEntry (classes, pickStaticMethod(methodName, classes));

        e.cachedStaticMethod = cacheEntry;

        return cacheEntry.method;
    }
    else
      return pickStaticMethod(methodName, MetaClassHelper.convertToTypeArray(arguments));
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:MetaClassImpl.java

示例7: pickStaticMethod

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private MetaMethod pickStaticMethod(String methodName, Class[] arguments) {
    MetaMethod method = null;
    MethodSelectionException mse = null;
    Object methods = getStaticMethods(theClass, methodName);

    if (!(methods instanceof FastArray) || !((FastArray)methods).isEmpty()) {
        try {
            method = (MetaMethod) chooseMethod(methodName, methods, arguments);
        } catch(MethodSelectionException msex) {
            mse = msex;
        }
    }
    if (method == null && theClass != Class.class) {
        MetaClass classMetaClass = registry.getMetaClass(Class.class);
        method = classMetaClass.pickMethod(methodName, arguments);
    }
    if (method == null) {
        method = (MetaMethod) chooseMethod(methodName, methods, MetaClassHelper.convertToTypeArray(arguments));
    }

    if (method == null && mse != null) {
        throw mse;
    } else {
        return method;
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:MetaClassImpl.java

示例8: createCachedConstructor

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private CachedConstructor createCachedConstructor(Object[] arguments) {
    if (arguments == null) arguments = EMPTY_ARGUMENTS;
    Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
    MetaClassHelper.unwrap(arguments);
    CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses);
    if (constructor == null) {
        constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses);
    }
    if (constructor == null) {
        throw new GroovyRuntimeException(
                "Could not find matching constructor for: "
                        + theClass.getName()
                        + "(" + InvokerHelper.toTypeString(arguments) + ")");
    }
    return constructor;
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:MetaClassImpl.java

示例9: retrieveConstructor

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
/**
 * This is a helper method added in Groovy 2.1.0, which is used only by indy.
 * This method is for internal use only.
 * @since Groovy 2.1.0
 */
public MetaMethod retrieveConstructor(Object[] arguments) {
    checkInitalised();
    if (arguments == null) arguments = EMPTY_ARGUMENTS;
    Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
    MetaClassHelper.unwrap(arguments);
    Object res = chooseMethod("<init>", constructors, argClasses);
    if (res instanceof MetaMethod) return (MetaMethod) res;
    CachedConstructor constructor = (CachedConstructor) res;
    if (constructor != null) return new MetaConstructor(constructor, false);
    if (arguments.length == 1 && arguments[0] instanceof Map) {
        res = chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
    } else if (
            arguments.length == 2 && arguments[1] instanceof Map &&
            theClass.getEnclosingClass()!=null &&
            theClass.getEnclosingClass().isAssignableFrom(argClasses[0]))
    {
        res = chooseMethod("<init>", constructors, new Class[]{argClasses[0]});
    }
    if (res instanceof MetaMethod) return (MetaMethod) res;
    constructor = (CachedConstructor) res;
    if (constructor != null) return new MetaConstructor(constructor, true);

    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:MetaClassImpl.java

示例10: invokeConstructor

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private Object invokeConstructor(Class at, Object[] arguments) {
    checkInitalised();
    if (arguments == null) arguments = EMPTY_ARGUMENTS;
    Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
    MetaClassHelper.unwrap(arguments);
    CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses);
    if (constructor != null) {
        return constructor.doConstructorInvoke(arguments);
    }

    if (arguments.length == 1) {
        Object firstArgument = arguments[0];
        if (firstArgument instanceof Map) {
            constructor = (CachedConstructor) chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
            if (constructor != null) {
                Object bean = constructor.doConstructorInvoke(MetaClassHelper.EMPTY_ARRAY);
                setProperties(bean, ((Map) firstArgument));
                return bean;
            }
        }
    }
    throw new GroovyRuntimeException(
            "Could not find matching constructor for: "
                    + theClass.getName()
                    + "(" + InvokerHelper.toTypeString(arguments) + ")");
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:MetaClassImpl.java

示例11: doChooseMostSpecificParams

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
protected static Object doChooseMostSpecificParams(String theClassName, String name, List matchingMethods, Class[] arguments, boolean checkParametersCompatible) {
    long matchesDistance = -1;
    LinkedList matches = new LinkedList();
    for (Object method : matchingMethods) {
        final ParameterTypes parameterTypes = (ParameterTypes) method;
        if (checkParametersCompatible && !MetaClassHelper.parametersAreCompatible(arguments, parameterTypes.getNativeParameterTypes())) continue;
        long dist = MetaClassHelper.calculateParameterDistance(arguments, parameterTypes);
        if (dist == 0) return method;
        matchesDistance = handleMatches(matchesDistance, matches, method, dist);
    }

    int size = matches.size();
    if (1 == size) {
        return matches.getFirst();
    }
    if (0 == size) {
        return null;
    }

    //more than one matching method found --> ambiguous!
    throw new GroovyRuntimeException(createErrorMessageForAmbiguity(theClassName, name, arguments, matches));
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:MetaClassImpl.java

示例12: createPogoCallSite

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
/**
 * Create a CallSite
 */
public CallSite createPogoCallSite(CallSite site, Object[] args) {
    if (!GroovyCategorySupport.hasCategoryInCurrentThread() && !(this instanceof AdaptingMetaClass)) {
        Class [] params = MetaClassHelper.convertToTypeArray(args);
        CallSite tempSite = site;
        if (site.getName().equals("call") && GeneratedClosure.class.isAssignableFrom(theClass)) {
            // here, we want to point to a method named "doCall" instead of "call"
            // but we don't want to replace the original call site name, otherwise
            // we loose the fact that the original method name was "call" so instead
            // we will point to a metamethod called "doCall"
            // see GROOVY-5806 for details
            tempSite = new AbstractCallSite(site.getArray(),site.getIndex(),"doCall");
        }
        MetaMethod metaMethod = getMethodWithCachingInternal(theClass, tempSite, params);
        if (metaMethod != null)
           return PogoMetaMethodSite.createPogoMetaMethodSite(site, this, metaMethod, params, args);
    }
    return new PogoMetaClassSite(site, this);
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:MetaClassImpl.java

示例13: processDoMethodInvokeException

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
/**
     * This method is called when an exception occurs while invoking this method.
     */
    public final RuntimeException processDoMethodInvokeException (Exception e, Object object, Object [] argumentArray) {
//        if (e instanceof IllegalArgumentException) {
//            //TODO: test if this is OK with new MOP, should be changed!
//            // we don't want the exception being unwrapped if it is a IllegalArgumentException
//            // but in the case it is for example a IllegalThreadStateException, we want the unwrapping
//            // from the runtime
//            //Note: the reason we want unwrapping sometimes and sometimes not is that the method
//            // invocation tries to invoke the method with and then reacts with type transformation
//            // if the invocation failed here. This is OK for IllegalArgumentException, but it is
//            // possible that a Reflector will be used to execute the call and then an Exception from inside
//            // the method is not wrapped in a InvocationTargetException and we will end here.
//            boolean setReason = e.getClass() != IllegalArgumentException.class || this instanceof org.codehaus.groovy.reflection.GeneratedMetaMethod;
//            return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, setReason);
//        }

        if (e instanceof RuntimeException)
          return (RuntimeException) e;

        return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, true);
    }
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:MetaMethod.java

示例14: addReadOnlyProperty

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
public static void addReadOnlyProperty(ClassNode classNode, String propertyName, ClassNode propertyClass, Object value) {
    final boolean hasProperty = hasOrInheritsProperty(classNode, propertyName);

    if (!hasProperty) {
        int visibility = Modifier.PRIVATE | Modifier.FINAL;
        Expression initialValue = value != null && !(value instanceof Expression) ? new ConstantExpression(value) : (Expression) value;
        classNode.addField(propertyName, visibility, propertyClass, initialValue);
        addMethod(classNode, new MethodNode(
            "get" + MetaClassHelper.capitalize(propertyName),
            Modifier.PUBLIC,
            propertyClass,
            Parameter.EMPTY_ARRAY,
            ClassNode.EMPTY_ARRAY,
            new ReturnStatement(
                new ExpressionStatement(
                    new FieldExpression(classNode.getField(propertyName))))));
    }
}
 
开发者ID:aalmiray,项目名称:griffon2,代码行数:19,代码来源:GriffonASTUtils.java

示例15: inferTypes

import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private Class[] inferTypes(Object... arguments) {
    if (arguments == null || arguments.length == 0) {
        return MetaClassHelper.EMPTY_CLASS_ARRAY;
    }
    Class[] classes = new Class[arguments.length];
    for (int i = 0; i < arguments.length; i++) {
        Object argType = arguments[i];
        if (argType == null) {
            classes[i] = null;
        } else {
            classes[i] = argType.getClass();
        }
    }
    return classes;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:16,代码来源:BeanDynamicObject.java


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