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


Java Parameter.getType方法代码示例

本文整理汇总了Java中org.codehaus.groovy.ast.Parameter.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.getType方法的具体用法?Java Parameter.getType怎么用?Java Parameter.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.groovy.ast.Parameter的用法示例。


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

示例1: transformClosureExpression

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
protected Expression transformClosureExpression(ClosureExpression ce) {
    boolean oldInClosure = inClosure;
    inClosure = true;
    Parameter[] paras = ce.getParameters();
    if (paras != null) {
        for (Parameter para : paras) {
            ClassNode t = para.getType();
            resolveOrFail(t, ce);
            visitAnnotations(para);
            if (para.hasInitialExpression()) {
                Object initialVal = para.getInitialExpression();
                if (initialVal instanceof Expression) {
                    para.setInitialExpression(transform((Expression) initialVal));
                }
            }
            visitAnnotations(para);
        }
    }
    Statement code = ce.getCode();
    if (code != null) code.visit(this);
    inClosure = oldInClosure;
    return ce;
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:ResolveVisitor.java

示例2: typeCheckMethodsWithGenericsOrFail

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
protected boolean typeCheckMethodsWithGenericsOrFail(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod, Expression location) {
    if (!typeCheckMethodsWithGenerics(receiver, arguments, candidateMethod)) {
        Map<String, GenericsType> classGTs = GenericsUtils.extractPlaceholders(receiver);
        ClassNode[] ptypes = new ClassNode[candidateMethod.getParameters().length];
        final Parameter[] parameters = candidateMethod.getParameters();
        for (int i = 0; i < parameters.length; i++) {
            final Parameter parameter = parameters[i];
            ClassNode type = parameter.getType();
            ptypes[i] = fullyResolveType(type, classGTs);
        }
        addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
                toMethodParametersString(candidateMethod.getName(), ptypes) +
                " with arguments " + formatArgumentList(arguments), location);
        return false;
    }
    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:StaticTypeCheckingVisitor.java

示例3: visitMethod

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
@Override
public void visitMethod(MethodNode node) {
    Parameter[] parameters = node.getParameters();
    for (Parameter param : parameters) {
        ClassNode paramType = param.getType();
        checkGenericsUsage(paramType, paramType.redirect());
    }
    ClassNode returnType = node.getReturnType();
    checkGenericsUsage(returnType, returnType.redirect());
    super.visitMethod(node);
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:GenericsVisitor.java

示例4: allParametersAndArgumentsMatchWithDefaultParams

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
/**
 * Checks that arguments and parameter types match, expecting that the number of parameters is strictly greater
 * than the number of arguments, allowing possible inclusion of default parameters.
 * @param params method parameters
 * @param args type arguments
 * @return -1 if arguments do not match, 0 if arguments are of the exact type and >0 when one or more argument is
 * not of the exact type but still match
 */
static int allParametersAndArgumentsMatchWithDefaultParams(Parameter[] params, ClassNode[] args) {
    int dist = 0;
    ClassNode ptype = null;
    // we already know the lengths are equal
    for (int i = 0, j=0; i < params.length; i++) {
        Parameter param = params[i];
        ClassNode paramType = param.getType();
        ClassNode arg = j>=args.length?null:args[j];
        if (arg==null || !isAssignableTo(arg, paramType)){
            if (!param.hasInitialExpression() && (ptype==null || !ptype.equals(paramType))) {
                return -1; // no default value
            }
            // a default value exists, we can skip this param
            ptype = null;
        } else {
            j++;
            if (!paramType.equals(arg)) dist+=getDistance(arg, paramType);
            if (param.hasInitialExpression()) {
                ptype = arg;
            } else {
                ptype = null;
            }
        }
    }
    return dist;
}
 
开发者ID:apache,项目名称:groovy,代码行数:35,代码来源:StaticTypeCheckingSupport.java

示例5: parameterizeArguments

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
/**
 * Given a receiver and a method node, parameterize the method arguments using
 * available generic type information.
 *
 * @param receiver the class
 * @param m the method
 * @return the parameterized arguments
 */
public static Parameter[] parameterizeArguments(final ClassNode receiver, final MethodNode m) {
    Map<String, GenericsType> genericFromReceiver = GenericsUtils.extractPlaceholders(receiver);
    Map<String, GenericsType> contextPlaceholders = extractGenericsParameterMapOfThis(m);
    Parameter[] methodParameters = m.getParameters();
    Parameter[] params = new Parameter[methodParameters.length];
    for (int i = 0; i < methodParameters.length; i++) {
        Parameter methodParameter = methodParameters[i];
        ClassNode paramType = methodParameter.getType();
        params[i] = buildParameter(genericFromReceiver, contextPlaceholders, methodParameter, paramType);
    }
    return params;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:StaticTypeCheckingSupport.java

示例6: adjustTypesIfStaticMainMethod

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private static void adjustTypesIfStaticMainMethod(MethodNode node) {
    if (node.getName().equals("main") && node.isStatic()) {
        Parameter[] params = node.getParameters();
        if (params.length == 1) {
            Parameter param = params[0];
            if (param.getType() == null || param.getType() == ClassHelper.OBJECT_TYPE) {
                param.setType(ClassHelper.STRING_TYPE.makeArray());
                ClassNode returnType = node.getReturnType();
                if (returnType == ClassHelper.OBJECT_TYPE) {
                    node.setReturnType(ClassHelper.VOID_TYPE);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:16,代码来源:Verifier.java

示例7: generateMopCalls

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
/**
 * generates a Meta Object Protocol method, that is used to call a non public
 * method, or to make a call to super.
 *
 * @param mopCalls list of methods a mop call method should be generated for
 * @param useThis  true if "this" should be used for the naming
 */
protected void generateMopCalls(LinkedList<MethodNode> mopCalls, boolean useThis) {
    for (MethodNode method : mopCalls) {
        String name = getMopMethodName(method, useThis);
        Parameter[] parameters = method.getParameters();
        String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameters());
        MethodVisitor mv = controller.getClassVisitor().visitMethod(ACC_PUBLIC | ACC_SYNTHETIC, name, methodDescriptor, null, null);
        controller.setMethodVisitor(mv);
        mv.visitVarInsn(ALOAD, 0);
        int newRegister = 1;
        OperandStack operandStack = controller.getOperandStack();
        for (Parameter parameter : parameters) {
            ClassNode type = parameter.getType();
            operandStack.load(parameter.getType(), newRegister);
            // increment to next register, double/long are using two places
            newRegister++;
            if (type == ClassHelper.double_TYPE || type == ClassHelper.long_TYPE) newRegister++;
        }
        operandStack.remove(parameters.length);
        ClassNode declaringClass = method.getDeclaringClass();
        // JDK 8 support for default methods in interfaces
        // this should probably be strenghtened when we support the A.super.foo() syntax
        int opcode = declaringClass.isInterface()?INVOKEINTERFACE:INVOKESPECIAL;
        mv.visitMethodInsn(opcode, BytecodeHelper.getClassInternalName(declaringClass), method.getName(), methodDescriptor, opcode == INVOKEINTERFACE);
        BytecodeHelper.doReturn(mv, method.getReturnType());
        mv.visitMaxs(0, 0);
        mv.visitEnd();
        controller.getClassNode().addMethod(name, ACC_PUBLIC | ACC_SYNTHETIC, method.getReturnType(), parameters, null, null);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:37,代码来源:MopWriter.java

示例8: getConstructorArgumentType

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private static ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) {
    if (!(arg instanceof VariableExpression)) return arg.getType();
    VariableExpression vexp = (VariableExpression) arg;
    String name = vexp.getName();
    for (Parameter param : node.getParameters()) {
        if (param.getName().equals(name)) {
            return param.getType();
        }
    }
    return vexp.getType();
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:JavaStubGenerator.java

示例9: defineMethodVariables

import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private void defineMethodVariables(Parameter[] paras, boolean isInStaticContext) {
    Label startLabel  = new Label();
    thisStartLabel = startLabel;
    controller.getMethodVisitor().visitLabel(startLabel);

    makeLocalVariablesOffset(paras,isInStaticContext);

    for (Parameter para : paras) {
        String name = para.getName();
        BytecodeVariable answer;
        ClassNode type = para.getType();
        if (para.isClosureSharedVariable()) {
            boolean useExistingReference = para.getNodeMetaData(ClosureWriter.UseExistingReference.class) != null;
            answer = defineVar(name, para.getOriginType(), true, useExistingReference);
            answer.setStartLabel(startLabel);
            if (!useExistingReference) {
                controller.getOperandStack().load(type, currentVariableIndex);
                controller.getOperandStack().box();

                // GROOVY-4237, the original variable should always appear
                // in the variable index, otherwise some programs get into
                // trouble. So we define a dummy variable for the packaging
                // phase and let it end right away before the normal
                // reference will be used
                Label newStart = new Label();
                controller.getMethodVisitor().visitLabel(newStart);
                BytecodeVariable var = new BytecodeVariable(currentVariableIndex, para.getOriginType(), name, currentVariableIndex);
                var.setStartLabel(startLabel);
                var.setEndLabel(newStart);
                usedVariables.add(var);
                answer.setStartLabel(newStart);

                createReference(answer);
            }
        } else {
            answer = defineVar(name, type, false, false);
            answer.setStartLabel(startLabel);
        }
        stackVariables.put(name, answer);
    }

    nextVariableIndex = localVariableOffset;
}
 
开发者ID:apache,项目名称:groovy,代码行数:44,代码来源:CompileStack.java


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