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


Java ClassHelper.getWrapper方法代码示例

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


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

示例1: revertType

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private static Expression revertType(Expression val, ClassNode returnWrapperType) {
    ConstantExpression ce = (ConstantExpression) val;
    if (ClassHelper.Character_TYPE.equals(returnWrapperType) && ClassHelper.STRING_TYPE.equals(val.getType())) {
        return configure(val, Verifier.transformToPrimitiveConstantIfPossible((ConstantExpression) val));
    }
    ClassNode valWrapperType = ClassHelper.getWrapper(val.getType());
    if (ClassHelper.Integer_TYPE.equals(valWrapperType)) {
        Integer i = (Integer) ce.getValue();
        if (ClassHelper.Character_TYPE.equals(returnWrapperType)) {
            return configure(val, new ConstantExpression((char) i.intValue(), true));
        }
        if (ClassHelper.Short_TYPE.equals(returnWrapperType)) {
            return configure(val, new ConstantExpression(i.shortValue(), true));
        }
        if (ClassHelper.Byte_TYPE.equals(returnWrapperType)) {
            return configure(val, new ConstantExpression(i.byteValue(), true));
        }
    }
    if (ClassHelper.BigDecimal_TYPE.equals(valWrapperType)) {
        BigDecimal bd = (BigDecimal) ce.getValue();
        if (ClassHelper.Float_TYPE.equals(returnWrapperType)) {
            return configure(val, new ConstantExpression(bd.floatValue(), true));
        }
        if (ClassHelper.Double_TYPE.equals(returnWrapperType)) {
            return configure(val, new ConstantExpression(bd.doubleValue(), true));
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:AnnotationConstantsVisitor.java

示例2: matchWithOrWithourBoxing

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private static boolean matchWithOrWithourBoxing(final ClassNode argType, final Class aClass) {
    final boolean match;
    ClassNode type = ClassHelper.make(aClass);
    if (ClassHelper.isPrimitiveType(type) && !ClassHelper.isPrimitiveType(argType)) {
        type = ClassHelper.getWrapper(type);
    } else if (ClassHelper.isPrimitiveType(argType) && !ClassHelper.isPrimitiveType(type)) {
        type = ClassHelper.getUnwrapper(type);
    }
    match = argType.equals(type);
    return match;
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:AbstractTypeCheckingExtension.java

示例3: visitConstantExpression

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
protected void visitConstantExpression(String attrName, ConstantExpression constExpr, ClassNode attrType) {
    ClassNode constType = constExpr.getType();
    ClassNode wrapperType = ClassHelper.getWrapper(constType);
    if (!hasCompatibleType(attrType, wrapperType)) {
        addError("Attribute '" + attrName + "' should have type '" + attrType.getName()
                + "'; but found type '" + constType.getName() + "'", constExpr);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:9,代码来源:AnnotationVisitor.java

示例4: coerce

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Override
public void coerce(ClassNode from, ClassNode target) {
    ClassNode wrapper = ClassHelper.getWrapper(target);
    makeIndyCall(invokeMethod, EmptyExpression.INSTANCE, false, false, "asType", new ClassExpression(wrapper));
    if (ClassHelper.boolean_TYPE.equals(target) || ClassHelper.Boolean_TYPE.equals(target)) {
        writeIndyCast(ClassHelper.OBJECT_TYPE,target);
    } else {
        BytecodeHelper.doCast(controller.getMethodVisitor(), wrapper);
        controller.getOperandStack().replace(wrapper);
        controller.getOperandStack().doGroovyCast(target);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:13,代码来源:InvokeDynamicWriter.java

示例5: castToNonPrimitiveIfNecessary

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Override
public void castToNonPrimitiveIfNecessary(ClassNode sourceType, ClassNode targetType) {
    ClassNode boxedType = ClassHelper.getWrapper(sourceType);
    if (WideningCategories.implementsInterfaceOrSubclassOf(boxedType, targetType)) {
        controller.getOperandStack().box();
        return;
    }
    writeIndyCast(sourceType, targetType);
}
 
开发者ID:apache,项目名称:groovy,代码行数:10,代码来源:InvokeDynamicWriter.java

示例6: box

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
public ClassNode box() {
    MethodVisitor mv = controller.getMethodVisitor();
    int size = stack.size();
    ClassNode type = stack.get(size-1);
    if (ClassHelper.isPrimitiveType(type) && ClassHelper.VOID_TYPE!=type) {
        ClassNode wrapper = ClassHelper.getWrapper(type);
        BytecodeHelper.doCastToWrappedType(mv, type, wrapper);
        type = wrapper;
    } // else nothing to box
    stack.set(size-1, type);
    return type;
}
 
开发者ID:apache,项目名称:groovy,代码行数:13,代码来源:OperandStack.java

示例7: defineVariable

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
public BytecodeVariable defineVariable(Variable v, ClassNode variableType, boolean initFromStack) {
    String name = v.getName();
    BytecodeVariable answer = defineVar(name, variableType, v.isClosureSharedVariable(), v.isClosureSharedVariable());
    stackVariables.put(name, answer);

    MethodVisitor mv = controller.getMethodVisitor();
    Label startLabel  = new Label();
    answer.setStartLabel(startLabel);
    ClassNode type = answer.getType().redirect();
    OperandStack operandStack = controller.getOperandStack();

    if (!initFromStack) {
        if (ClassHelper.isPrimitiveType(v.getOriginType()) && ClassHelper.getWrapper(v.getOriginType()) == variableType) {
            pushInitValue(v.getOriginType(), mv);
            operandStack.push(v.getOriginType());
            operandStack.box();
            operandStack.remove(1);
        } else {
            pushInitValue(type, mv);
        }
    }
    operandStack.push(answer.getType());
    if (answer.isHolder())  {
        operandStack.box();
        operandStack.remove(1);
        createReference(answer);
    } else {
        operandStack.storeVar(answer);
    }

    mv.visitLabel(startLabel);
    return answer;
}
 
开发者ID:apache,项目名称:groovy,代码行数:34,代码来源:CompileStack.java

示例8: evaluateElvisOperatorExpression

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private void evaluateElvisOperatorExpression(ElvisOperatorExpression expression) {
    MethodVisitor mv = controller.getMethodVisitor();
    CompileStack compileStack = controller.getCompileStack();
    OperandStack operandStack = controller.getOperandStack();
    TypeChooser typeChooser = controller.getTypeChooser();
    
    Expression boolPart = expression.getBooleanExpression().getExpression();
    Expression falsePart = expression.getFalseExpression();
    
    ClassNode truePartType = typeChooser.resolveType(boolPart, controller.getClassNode());
    ClassNode falsePartType = typeChooser.resolveType(falsePart, controller.getClassNode());
    ClassNode common = WideningCategories.lowestUpperBound(truePartType, falsePartType);
    
    // x?:y is equal to x?x:y, which evals to 
    //      var t=x; boolean(t)?t:y
    // first we load x, dup it, convert the dupped to boolean, then 
    // jump depending on the value. For true we are done, for false we
    // have to load y, thus we first remove x and then load y. 
    // But since x and y may have different stack lengths, this cannot work
    // Thus we have to have to do the following:
    // Be X the type of x, Y the type of y and S the common supertype of 
    // X and Y, then we have to see x?:y as  
    //      var t=x;boolean(t)?S(t):S(y)
    // so we load x, dup it, store the value in a local variable (t), then 
    // do boolean conversion. In the true part load t and cast it to S, 
    // in the false part load y and cast y to S 

    // load x, dup it, store one in $t and cast the remaining one to boolean
    int mark = operandStack.getStackLength();
    boolPart.visit(controller.getAcg());
    operandStack.dup();
    if (ClassHelper.isPrimitiveType(truePartType) && !ClassHelper.isPrimitiveType(operandStack.getTopOperand())) {
        truePartType = ClassHelper.getWrapper(truePartType);
    }
    int retValueId = compileStack.defineTemporaryVariable("$t", truePartType, true);
    operandStack.castToBool(mark,true);
    
    Label l0 = operandStack.jump(IFEQ);
    // true part: load $t and cast to S
    operandStack.load(truePartType, retValueId);
    operandStack.doGroovyCast(common);
    Label l1 = new Label();
    mv.visitJumpInsn(GOTO, l1);
    
    // false part: load false expression and cast to S
    mv.visitLabel(l0);
    falsePart.visit(controller.getAcg());        
    operandStack.doGroovyCast(common);
    
    // finish and cleanup
    mv.visitLabel(l1);
    compileStack.removeVar(retValueId);
    controller.getOperandStack().replace(common, 2);        
    
}
 
开发者ID:apache,项目名称:groovy,代码行数:56,代码来源:BinaryExpressionHelper.java


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