本文整理汇总了Java中org.codehaus.groovy.ast.ClassHelper.isPrimitiveType方法的典型用法代码示例。如果您正苦于以下问题:Java ClassHelper.isPrimitiveType方法的具体用法?Java ClassHelper.isPrimitiveType怎么用?Java ClassHelper.isPrimitiveType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.ClassHelper
的用法示例。
在下文中一共展示了ClassHelper.isPrimitiveType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitField
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
static void visitField(ErrorCollecting xform, AnnotationNode node, FieldNode fieldNode) {
final Expression soft = node.getMember("soft");
final Expression init = getInitExpr(xform, fieldNode);
String backingFieldName = "$" + fieldNode.getName();
fieldNode.rename(backingFieldName);
fieldNode.setModifiers(ACC_PRIVATE | (fieldNode.getModifiers() & (~(ACC_PUBLIC | ACC_PROTECTED))));
PropertyNode pNode = fieldNode.getDeclaringClass().getProperty(backingFieldName);
if (pNode != null) {
fieldNode.getDeclaringClass().getProperties().remove(pNode);
}
if (soft instanceof ConstantExpression && ((ConstantExpression) soft).getValue().equals(true)) {
createSoft(fieldNode, init);
} else {
create(fieldNode, init);
// @Lazy not meaningful with primitive so convert to wrapper if needed
if (ClassHelper.isPrimitiveType(fieldNode.getType())) {
fieldNode.setType(ClassHelper.getWrapper(fieldNode.getType()));
}
}
}
示例2: createConstructorStatementDefault
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
public static Statement createConstructorStatementDefault(FieldNode fNode) {
final String name = fNode.getName();
final ClassNode fType = fNode.getType();
final Expression fieldExpr = propX(varX("this"), name);
Expression initExpr = fNode.getInitialValueExpression();
Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression)initExpr).isNullExpression())) {
if (ClassHelper.isPrimitiveType(fType)) {
assignInit = EmptyStatement.INSTANCE;
} else {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
}
} else {
assignInit = assignS(fieldExpr, initExpr);
}
fNode.setInitialValueExpression(null);
Expression value = findArg(name);
return ifElseS(equalsNullX(value), assignInit, assignS(fieldExpr, castX(fType, value)));
}
示例3: checkReturnType
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
public void checkReturnType(ClassNode attrType, ASTNode node) {
if (attrType.isArray()) {
checkReturnType(attrType.getComponentType(), node);
} else if (ClassHelper.isPrimitiveType(attrType)) {
return;
} else if (ClassHelper.STRING_TYPE.equals(attrType)) {
return;
} else if (ClassHelper.CLASS_Type.equals(attrType)) {
return;
} else if (attrType.isDerivedFrom(ClassHelper.Enum_Type)) {
return;
} else if (isValidAnnotationClass(attrType)) {
return;
} else {
addError("Unexpected return type " + attrType.getName(), node);
}
}
示例4: loadThis
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private void loadThis(VariableExpression thisExpression) {
MethodVisitor mv = controller.getMethodVisitor();
mv.visitVarInsn(ALOAD, 0);
if (controller.isInClosure() && !controller.getCompileStack().isImplicitThis()) {
mv.visitMethodInsn(INVOKEVIRTUAL, "groovy/lang/Closure", "getThisObject", "()Ljava/lang/Object;", false);
ClassNode expectedType = thisExpression!=null?controller.getTypeChooser().resolveType(thisExpression, controller.getOutermostClass()):null;
if (!ClassHelper.OBJECT_TYPE.equals(expectedType) && !ClassHelper.isPrimitiveType(expectedType)) {
BytecodeHelper.doCast(mv, expectedType);
controller.getOperandStack().push(expectedType);
} else {
controller.getOperandStack().push(ClassHelper.OBJECT_TYPE);
}
} else {
controller.getOperandStack().push(controller.getClassNode());
}
}
示例5: providedOrDefaultInitialValue
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private static Expression providedOrDefaultInitialValue(FieldNode fNode) {
Expression initialExp = fNode.getInitialExpression() != null ? fNode.getInitialExpression() : ConstantExpression.NULL;
final ClassNode paramType = fNode.getType();
if (ClassHelper.isPrimitiveType(paramType) && initialExp.equals(ConstantExpression.NULL)) {
initialExp = primitivesInitialValues.get(paramType.getTypeClass());
}
return initialExp;
}
示例6: 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;
}
示例7: visit
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Override
public void visit(final GroovyCodeVisitor visitor) {
if (visitor instanceof AsmClassGenerator) {
AsmClassGenerator acg = (AsmClassGenerator) visitor;
WriterController controller = acg.getController();
MethodVisitor mv = controller.getMethodVisitor();
objectExpression.visit(acg);
ClassNode top = controller.getOperandStack().getTopOperand();
if (ClassHelper.isPrimitiveType(top)) {
controller.getOperandStack().pop();
mv.visitInsn(equalsNull ? ICONST_0 : ICONST_1);
controller.getOperandStack().push(ClassHelper.boolean_TYPE);
return;
}
Label zero = new Label();
mv.visitJumpInsn(equalsNull ? IFNONNULL : IFNULL, zero);
mv.visitInsn(ICONST_1);
Label end = new Label();
mv.visitJumpInsn(GOTO, end);
mv.visitLabel(zero);
mv.visitInsn(ICONST_0);
mv.visitLabel(end);
controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
} else {
super.visit(visitor);
}
}
示例8: isOptimizable
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private static boolean isOptimizable(final ClassNode exprInferredType, final ClassNode castType) {
if (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(exprInferredType, castType)) {
return true;
}
if (ClassHelper.isPrimitiveType(exprInferredType) && ClassHelper.isPrimitiveType(castType)) {
return true;
}
return false;
}
示例9: pushInitValue
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private static void pushInitValue(ClassNode type, MethodVisitor mv) {
if (ClassHelper.isPrimitiveType(type)) {
if (type== ClassHelper.long_TYPE) {
mv.visitInsn(LCONST_0);
} else if (type== ClassHelper.double_TYPE) {
mv.visitInsn(DCONST_0);
} else if (type== ClassHelper.float_TYPE) {
mv.visitInsn(FCONST_0);
} else {
mv.visitLdcInsn(0);
}
} else {
mv.visitInsn(ACONST_NULL);
}
}
示例10: castToBool
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
/**
* ensure last marked parameter on the stack is a primitive boolean
* if mark==stack size, we assume an empty expression or statement.
* was used and we will use the value given in emptyDefault as boolean
* if mark==stack.size()-1 the top element will be cast to boolean using
* Groovy truth.
* In other cases we throw a GroovyBugError
*/
public void castToBool(int mark, boolean emptyDefault) {
int size = stack.size();
MethodVisitor mv = controller.getMethodVisitor();
if (mark==size) {
// no element, so use emptyDefault
if (emptyDefault) {
mv.visitIntInsn(BIPUSH, 1);
} else {
mv.visitIntInsn(BIPUSH, 0);
}
stack.add(null);
} else if (mark==stack.size()-1) {
ClassNode last = stack.get(size-1);
// nothing to do in that case
if (last == ClassHelper.boolean_TYPE) return;
// not a primitive type, so call booleanUnbox
if (!ClassHelper.isPrimitiveType(last)) {
controller.getInvocationWriter().castNonPrimitiveToBool(last);
} else {
BytecodeHelper.convertPrimitiveToBoolean(mv, last);
}
} else {
throw new GroovyBugError(
"operand stack contains "+stack.size()+
" elements, but we expected only "+mark
);
}
stack.set(mark,ClassHelper.boolean_TYPE);
}
示例11: doCast
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
public static void doCast(MethodVisitor mv, ClassNode type) {
if (type == ClassHelper.OBJECT_TYPE) return;
if (ClassHelper.isPrimitiveType(type) && type != ClassHelper.VOID_TYPE) {
unbox(mv, type);
} else {
mv.visitTypeInsn(
CHECKCAST,
type.isArray() ?
BytecodeHelper.getTypeDescription(type) :
BytecodeHelper.getClassInternalName(type.getName()));
}
}
示例12: printTypeName
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private void printTypeName(PrintWriter out, ClassNode type) {
if (ClassHelper.isPrimitiveType(type)) {
if (type == ClassHelper.boolean_TYPE) {
out.print("boolean");
} else if (type == ClassHelper.char_TYPE) {
out.print("char");
} else if (type == ClassHelper.int_TYPE) {
out.print("int");
} else if (type == ClassHelper.short_TYPE) {
out.print("short");
} else if (type == ClassHelper.long_TYPE) {
out.print("long");
} else if (type == ClassHelper.float_TYPE) {
out.print("float");
} else if (type == ClassHelper.double_TYPE) {
out.print("double");
} else if (type == ClassHelper.byte_TYPE) {
out.print("byte");
} else {
out.print("void");
}
} else {
String name = type.getName();
// check for an alias
ClassNode alias = currentModule.getImportType(name);
if (alias != null) name = alias.getName();
out.print(name.replace('$', '.'));
}
}
示例13: evaluateCompareExpression
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
protected void evaluateCompareExpression(MethodCaller compareMethod, BinaryExpression expression) {
Expression leftExp = expression.getLeftExpression();
TypeChooser typeChooser = controller.getTypeChooser();
ClassNode cn = controller.getClassNode();
ClassNode leftType = typeChooser.resolveType(leftExp,cn);
Expression rightExp = expression.getRightExpression();
ClassNode rightType = typeChooser.resolveType(rightExp,cn);
boolean done = false;
if ( ClassHelper.isPrimitiveType(leftType) &&
ClassHelper.isPrimitiveType(rightType))
{
BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(getController());
done = helper.doPrimitiveCompare(leftType, rightType, expression);
}
if (!done) {
AsmClassGenerator acg = controller.getAcg();
OperandStack operandStack = controller.getOperandStack();
leftExp.visit(acg);
operandStack.box();
rightExp.visit(acg);
operandStack.box();
compareMethod.call(controller.getMethodVisitor());
ClassNode resType = ClassHelper.boolean_TYPE;
if (compareMethod==findRegexMethod) {
resType = ClassHelper.OBJECT_TYPE;
}
operandStack.replace(resType,2);
}
}
示例14: visit
import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Override
public void visit(final GroovyCodeVisitor visitor) {
if (visitor instanceof AsmClassGenerator) {
AsmClassGenerator acg = (AsmClassGenerator) visitor;
WriterController controller = acg.getController();
OperandStack os = controller.getOperandStack();
if (type.equals(ClassHelper.boolean_TYPE)) {
expression.visit(visitor);
os.doGroovyCast(ClassHelper.boolean_TYPE);
return;
}
if (type.equals(ClassHelper.Boolean_TYPE)) {
MethodVisitor mv = controller.getMethodVisitor();
expression.visit(visitor);
Label unbox = new Label();
Label exit = new Label();
// check for null
mv.visitInsn(DUP);
mv.visitJumpInsn(IFNONNULL, unbox);
mv.visitInsn(POP);
mv.visitInsn(ICONST_0);
mv.visitJumpInsn(GOTO, exit);
mv.visitLabel(unbox);
// unbox
// GROOVY-6270
if (!os.getTopOperand().equals(type)) BytecodeHelper.doCast(mv, type);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
mv.visitLabel(exit);
os.replace(ClassHelper.boolean_TYPE);
return;
}
ClassNode top = type;
if (ClassHelper.isPrimitiveType(top)) {
expression.visit(visitor);
// in case of null safe invocation, it is possible that what was supposed to be a primitive type
// becomes the "null" constant, so we need to recheck
top = controller.getOperandStack().getTopOperand();
if (ClassHelper.isPrimitiveType(top)) {
BytecodeHelper.convertPrimitiveToBoolean(controller.getMethodVisitor(), top);
controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
return;
}
}
List<MethodNode> asBoolean = findDGMMethodsByNameAndArguments(controller.getSourceUnit().getClassLoader(), top, "asBoolean", ClassNode.EMPTY_ARRAY);
if (asBoolean.size() == 1) {
MethodNode node = asBoolean.get(0);
if (node instanceof ExtensionMethodNode) {
MethodNode dgmNode = ((ExtensionMethodNode) node).getExtensionMethodNode();
ClassNode owner = dgmNode.getParameters()[0].getType();
if (ClassHelper.OBJECT_TYPE.equals(owner)) {
// we may inline a var!=null check instead of calling a helper method iff
// (1) the class doesn't define an asBoolean method (already tested)
// (2) no subclass defines an asBoolean method
// For (2), we check that we are in one of those cases
// (a) a final class
// (b) a private inner class without subclass
if (Modifier.isFinal(top.getModifiers())
|| (top instanceof InnerClassNode
&& Modifier.isPrivate(top.getModifiers())
&& !isExtended(top, top.getOuterClass().getInnerClasses()))
) {
CompareToNullExpression expr = new CompareToNullExpression(
expression, false
);
expr.visit(acg);
return;
}
}
}
}
super.visit(visitor);
} else {
super.visit(visitor);
}
}
示例15: 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);
}