本文整理汇总了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;
}
示例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);
}