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


Java ClassHelper.getUnwrapper方法代码示例

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


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

示例1: 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

示例2: visitForLoop

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Override
public void visitForLoop(final ForStatement forLoop) {
    // collect every variable expression used in the loop body
    final Map<VariableExpression, ClassNode> varOrigType = new HashMap<VariableExpression, ClassNode>();
    forLoop.getLoopBlock().visit(new VariableExpressionTypeMemoizer(varOrigType));

    // visit body
    Map<VariableExpression, List<ClassNode>> oldTracker = pushAssignmentTracking();
    Expression collectionExpression = forLoop.getCollectionExpression();
    if (collectionExpression instanceof ClosureListExpression) {
        // for (int i=0; i<...; i++) style loop
        super.visitForLoop(forLoop);
    } else {
        collectionExpression.visit(this);
        final ClassNode collectionType = getType(collectionExpression);
        ClassNode componentType = inferLoopElementType(collectionType);
        ClassNode forLoopVariableType = forLoop.getVariableType();
        if (ClassHelper.getUnwrapper(componentType) == forLoopVariableType) {
            // prefer primitive type over boxed type
            componentType = forLoopVariableType;
        }
        if (!checkCompatibleAssignmentTypes(forLoopVariableType, componentType)) {
            addStaticTypeError("Cannot loop with element of type " + forLoopVariableType.toString(false) + " with collection of type " + collectionType.toString(false), forLoop);
        }
        if (forLoopVariableType != DYNAMIC_TYPE) {
            // user has specified a type, prefer it over the inferred type
            componentType = forLoopVariableType;
        }
        typeCheckingContext.controlStructureVariables.put(forLoop.getVariable(), componentType);
        try {
            super.visitForLoop(forLoop);
        } finally {
            typeCheckingContext.controlStructureVariables.remove(forLoop.getVariable());
        }
    }
    boolean typeChanged = isSecondPassNeededForControlStructure(varOrigType, oldTracker);
    if (typeChanged) visitForLoop(forLoop);
}
 
开发者ID:apache,项目名称:groovy,代码行数:39,代码来源:StaticTypeCheckingVisitor.java


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