Java Code Examples for org.codehaus.groovy.ast.ClassHelper#int_TYPE()
The following examples show how to use
org.codehaus.groovy.ast.ClassHelper#int_TYPE() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyVirtualSourceProvider.java From netbeans with Apache License 2.0 | 6 votes |
private void printTypeName(ClassNode type, PrintWriter out) { 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 { out.print(type.redirect().getName().replace('$', '.')); } }
Example 2
Source File: OperandStack.java From groovy with Apache License 2.0 | 6 votes |
private boolean convertFromLong(ClassNode target) { MethodVisitor mv = controller.getMethodVisitor(); if (target==ClassHelper.int_TYPE){ mv.visitInsn(L2I); return true; } else if ( target==ClassHelper.char_TYPE || target==ClassHelper.byte_TYPE || target==ClassHelper.short_TYPE) { mv.visitInsn(L2I); return convertFromInt(target); } else if (target==ClassHelper.double_TYPE){ mv.visitInsn(L2D); return true; } else if (target==ClassHelper.float_TYPE){ mv.visitInsn(L2F); return true; } return false; }
Example 3
Source File: OperandStack.java From groovy with Apache License 2.0 | 6 votes |
private boolean convertFromDouble(ClassNode target) { MethodVisitor mv = controller.getMethodVisitor(); if (target==ClassHelper.int_TYPE){ mv.visitInsn(D2I); return true; } else if ( target==ClassHelper.char_TYPE || target==ClassHelper.byte_TYPE || target==ClassHelper.short_TYPE) { mv.visitInsn(D2I); return convertFromInt(target); } else if (target==ClassHelper.long_TYPE){ mv.visitInsn(D2L); return true; } else if (target==ClassHelper.float_TYPE){ mv.visitInsn(D2F); return true; } return false; }
Example 4
Source File: OperandStack.java From groovy with Apache License 2.0 | 6 votes |
private boolean convertFromFloat(ClassNode target) { MethodVisitor mv = controller.getMethodVisitor(); if (target==ClassHelper.int_TYPE){ mv.visitInsn(F2I); return true; } else if ( target==ClassHelper.char_TYPE || target==ClassHelper.byte_TYPE || target==ClassHelper.short_TYPE) { mv.visitInsn(F2I); return convertFromInt(target); } else if (target==ClassHelper.long_TYPE){ mv.visitInsn(F2L); return true; } else if (target==ClassHelper.double_TYPE){ mv.visitInsn(F2D); return true; } return false; }
Example 5
Source File: OperandStack.java From groovy with Apache License 2.0 | 6 votes |
private boolean convertPrimitive(ClassNode top, ClassNode target) { if (top==target) return true; if (top==ClassHelper.int_TYPE) { return convertFromInt(target); } else if ( top==ClassHelper.char_TYPE || top==ClassHelper.byte_TYPE || top==ClassHelper.short_TYPE) { return target == ClassHelper.int_TYPE || convertFromInt(target); } else if ( top==ClassHelper.float_TYPE) { return convertFromFloat(target); } else if ( top==ClassHelper.double_TYPE) { return convertFromDouble(target); } else if ( top==ClassHelper.long_TYPE) { return convertFromLong(target); } return false; }
Example 6
Source File: IndexedPropertyASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
private static void addGetter(FieldNode fNode, ClassNode componentType) { ClassNode cNode = fNode.getDeclaringClass(); BlockStatement body = new BlockStatement(); Parameter[] params = new Parameter[1]; params[0] = new Parameter(ClassHelper.int_TYPE, "index"); body.addStatement(stmt(indexX(varX(fNode), varX(params[0])))); addGeneratedMethod(cNode, makeName(fNode, "get"), getModifiers(fNode), componentType, params, null, body); }
Example 7
Source File: ExternalizeMethodsASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
private static String suffixForField(FieldNode fNode) { // use primitives for efficiency if (fNode.getType() == ClassHelper.int_TYPE) return "Int"; if (fNode.getType() == ClassHelper.boolean_TYPE) return "Boolean"; // currently char isn't found due to a bug, so go with Object // if (fNode.getType() == ClassHelper.char_TYPE) return "Char"; if (fNode.getType() == ClassHelper.long_TYPE) return "Long"; if (fNode.getType() == ClassHelper.short_TYPE) return "Short"; if (fNode.getType() == ClassHelper.byte_TYPE) return "Byte"; if (fNode.getType() == ClassHelper.float_TYPE) return "Float"; if (fNode.getType() == ClassHelper.double_TYPE) return "Double"; return "Object"; }
Example 8
Source File: PrimitiveHelper.java From groovy with Apache License 2.0 | 5 votes |
public static Expression getDefaultValueForPrimitive(ClassNode type) { if (type == ClassHelper.int_TYPE) { return new ConstantExpression(0); } if (type == ClassHelper.long_TYPE) { return new ConstantExpression(0L); } if (type == ClassHelper.double_TYPE) { return new ConstantExpression(0.0); } if (type == ClassHelper.float_TYPE) { return new ConstantExpression(0.0F); } if (type == ClassHelper.boolean_TYPE) { return ConstantExpression.FALSE; } if (type == ClassHelper.short_TYPE) { return new ConstantExpression((short) 0); } if (type == ClassHelper.byte_TYPE) { return new ConstantExpression((byte) 0); } if (type == ClassHelper.char_TYPE) { return new ConstantExpression((char) 0); } return null; }
Example 9
Source File: JavaStubGenerator.java From groovy with Apache License 2.0 | 5 votes |
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('$', '.')); } }
Example 10
Source File: MapEntryOrKeyValue.java From groovy with Apache License 2.0 | 5 votes |
public List<ClassNode[]> getClosureSignatures(final MethodNode node, final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final String[] options, final ASTNode usage) { Options opt; try { opt = Options.parse(node, usage, options); } catch (IncorrectTypeHintException e) { sourceUnit.addError(e); return Collections.emptyList(); } GenericsType[] genericsTypes = node.getParameters()[opt.parameterIndex].getOriginType().getGenericsTypes(); if (genericsTypes==null) { // would happen if you have a raw Map type for example genericsTypes = new GenericsType[] { new GenericsType(ClassHelper.OBJECT_TYPE), new GenericsType(ClassHelper.OBJECT_TYPE) }; } ClassNode[] firstSig; ClassNode[] secondSig; ClassNode mapEntry = MAPENTRY_TYPE.getPlainNodeReference(); mapEntry.setGenericsTypes(genericsTypes); if (opt.generateIndex) { firstSig = new ClassNode[] {genericsTypes[0].getType(), genericsTypes[1].getType(), ClassHelper.int_TYPE}; secondSig = new ClassNode[] {mapEntry, ClassHelper.int_TYPE}; } else { firstSig = new ClassNode[] {genericsTypes[0].getType(), genericsTypes[1].getType()}; secondSig = new ClassNode[] {mapEntry}; } return Arrays.asList(firstSig, secondSig); }
Example 11
Source File: AsmClassGenerator.java From groovy with Apache License 2.0 | 4 votes |
@Override public void visitArrayExpression(final ArrayExpression expression) { MethodVisitor mv = controller.getMethodVisitor(); ClassNode elementType = expression.getElementType(); String arrayTypeName = BytecodeHelper.getClassInternalName(elementType); List<Expression> sizeExpression = expression.getSizeExpression(); int size = 0; int dimensions = 0; if (sizeExpression != null) { for (Expression element : sizeExpression) { if (element == ConstantExpression.EMPTY_EXPRESSION) break; dimensions += 1; // let's convert to an int element.visit(this); controller.getOperandStack().doGroovyCast(ClassHelper.int_TYPE); } controller.getOperandStack().remove(dimensions); } else { size = expression.getExpressions().size(); BytecodeHelper.pushConstant(mv, size); } int storeIns = AASTORE; if (sizeExpression != null) { arrayTypeName = BytecodeHelper.getTypeDescription(expression.getType()); mv.visitMultiANewArrayInsn(arrayTypeName, dimensions); } else if (ClassHelper.isPrimitiveType(elementType)) { int primType = 0; if (elementType == ClassHelper.boolean_TYPE) { primType = T_BOOLEAN; storeIns = BASTORE; } else if (elementType == ClassHelper.char_TYPE) { primType = T_CHAR; storeIns = CASTORE; } else if (elementType == ClassHelper.float_TYPE) { primType = T_FLOAT; storeIns = FASTORE; } else if (elementType == ClassHelper.double_TYPE) { primType = T_DOUBLE; storeIns = DASTORE; } else if (elementType == ClassHelper.byte_TYPE) { primType = T_BYTE; storeIns = BASTORE; } else if (elementType == ClassHelper.short_TYPE) { primType = T_SHORT; storeIns = SASTORE; } else if (elementType == ClassHelper.int_TYPE) { primType = T_INT; storeIns = IASTORE; } else if (elementType == ClassHelper.long_TYPE) { primType = T_LONG; storeIns = LASTORE; } mv.visitIntInsn(NEWARRAY, primType); } else { mv.visitTypeInsn(ANEWARRAY, arrayTypeName); } for (int i = 0; i < size; i += 1) { mv.visitInsn(DUP); BytecodeHelper.pushConstant(mv, i); Expression elementExpression = expression.getExpression(i); if (elementExpression == null) { ConstantExpression.NULL.visit(this); } else { elementExpression.visit(this); controller.getOperandStack().doGroovyCast(elementType); } mv.visitInsn(storeIns); controller.getOperandStack().remove(1); } controller.getOperandStack().push(expression.getType()); }
Example 12
Source File: BinaryIntExpressionHelper.java From groovy with Apache License 2.0 | 4 votes |
protected ClassNode getNormalOpResultType() { return ClassHelper.int_TYPE; }
Example 13
Source File: BinaryIntExpressionHelper.java From groovy with Apache License 2.0 | 4 votes |
protected ClassNode getDevisionOpResultType() { return ClassHelper.int_TYPE; }