/** * Returns whether or not this type is a normal java reference, i.e. it is or extends java.lang.Object. * * @return true if a java reference, false if a primitive or special */ public boolean isReference() { return !special && (clazz == null || !clazz.isPrimitive()); }
/** * Returns whether or not this type is a normal java reference, i.e. it is or extends java.lang.Object. * * @return true if a java reference, false if a primitive or special */ public boolean isReference() { return !special && (clazz == null || !clazz.isPrimitive()); }
ret.append('['); ret.append(getDesc(c.getComponentType())); } else if (c.isPrimitive()) { String t = c.getName(); if ("void".equals(t)) {
ret.append('['); ret.append(getDesc(c.getComponentType())); } else if (c.isPrimitive()) { String t = c.getName(); if ("void".equals(t)) {
private static void toDescriptor(StringBuffer desc, CtClass type) { if (type.isArray()) { desc.append('['); try { toDescriptor(desc, type.getComponentType()); } catch (NotFoundException e) { desc.append('L'); String name = type.getName(); desc.append(toJvmName(name.substring(0, name.length() - 2))); desc.append(';'); } } else if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; desc.append(pt.getDescriptor()); } else { // class type desc.append('L'); desc.append(type.getName().replace('.', '/')); desc.append(';'); } }
private void addNewarray(Bytecode code) { if (type.isPrimitive()) code.addNewarray(((CtPrimitiveType)type).getArrayType(), size); else code.addAnewarray(type, size); }
private void addNewarray(Bytecode code) { if (type.isPrimitive()) code.addNewarray(((CtPrimitiveType)type).getArrayType(), size); else code.addAnewarray(type, size); }
/** * Appends ARETURN, IRETURN, .., or RETURN. * * @param type the return type. */ public void addReturn(CtClass type) { if (type == null) addOpcode(RETURN); else if (type.isPrimitive()) { CtPrimitiveType ptype = (CtPrimitiveType)type; addOpcode(ptype.getReturnOp()); } else addOpcode(ARETURN); }
/** * Finds the most specific common super class of the given classes * by considering array types. */ public static CtClass commonSuperClassEx(CtClass one, CtClass two) throws NotFoundException { if (one == two) return one; else if (one.isArray() && two.isArray()) { CtClass ele1 = one.getComponentType(); CtClass ele2 = two.getComponentType(); CtClass element = commonSuperClassEx(ele1, ele2); if (element == ele1) return one; else if (element == ele2) return two; else return one.getClassPool().get(element == null ? "java.lang.Object" : element.getName() + "[]"); } else if (one.isPrimitive() || two.isPrimitive()) return null; // TOP else if (one.isArray() || two.isArray()) // but !(one.isArray() && two.isArray()) return one.getClassPool().get("java.lang.Object"); else return commonSuperClass(one, two); }
/** * Appends an instruction for pushing zero or null on the stack. * If the type is void, this method does not append any instruction. * * @param type the type of the zero value (or null). */ public void addConstZero(CtClass type) { if (type.isPrimitive()) { if (type == CtClass.longType) addOpcode(LCONST_0); else if (type == CtClass.floatType) addOpcode(FCONST_0); else if (type == CtClass.doubleType) addOpcode(DCONST_0); else if (type == CtClass.voidType) throw new RuntimeException("void type?"); else addOpcode(ICONST_0); } else addOpcode(ACONST_NULL); }
private void setType(CtClass type, int dim) throws CompileError { if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; exprType = MemberResolver.descToType(pt.getDescriptor()); arrayDim = dim; className = null; } else if (type.isArray()) try { setType(type.getComponentType(), dim + 1); } catch (NotFoundException e) { throw new CompileError("undefined type: " + type.getName()); } else { exprType = CLASS; arrayDim = dim; className = MemberResolver.javaToJvmName(type.getName()); } }
/** * Determines whether this type is assignable, to the passed type. * A type is assignable to another if it is either the same type, or * a sub-type. * * @param type the type to test assignability to * @return true if this is assignable to type, otherwise false */ public boolean isAssignableFrom(Type type) { if (this == type) return true; if ((type == UNINIT && isReference()) || this == UNINIT && type.isReference()) return true; if (type instanceof MultiType) return ((MultiType)type).isAssignableTo(this); if (type instanceof MultiArrayType) return ((MultiArrayType)type).isAssignableTo(this); // Primitives and Special types must be identical if (clazz == null || clazz.isPrimitive()) return false; try { return type.clazz.subtypeOf(clazz); } catch (Exception e) { throw new RuntimeException(e); } }
private void setType(CtClass type, int dim) throws CompileError { if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; exprType = MemberResolver.descToType(pt.getDescriptor()); arrayDim = dim; className = null; } else if (type.isArray()) try { setType(type.getComponentType(), dim + 1); } catch (NotFoundException e) { throw new CompileError("undefined type: " + type.getName()); } else { exprType = CLASS; arrayDim = dim; className = MemberResolver.javaToJvmName(type.getName()); } } }
if (type.isPrimitive()) { if (type == CtClass.booleanType || type == CtClass.charType || type == CtClass.byteType || type == CtClass.shortType
if (type.isPrimitive()) { if (type == CtClass.booleanType || type == CtClass.charType || type == CtClass.byteType || type == CtClass.shortType
/** * Appends ARETURN, IRETURN, .., or RETURN. * * @param type the return type. */ public void addReturn(CtClass type) { if (type == null) addOpcode(RETURN); else if (type.isPrimitive()) { CtPrimitiveType ptype = (CtPrimitiveType)type; addOpcode(ptype.getReturnOp()); } else addOpcode(ARETURN); }
int getConstantValue2(ConstPool cp, CtClass type, ASTree tree) { if (type.isPrimitive()) { if (tree instanceof IntConst) { long value = ((IntConst)tree).get(); if (type == CtClass.doubleType) return cp.addDoubleInfo((double)value); else if (type == CtClass.floatType) return cp.addFloatInfo((float)value); else if (type == CtClass.longType) return cp.addLongInfo(value); else if (type != CtClass.voidType) return cp.addIntegerInfo((int)value); } else if (tree instanceof DoubleConst) { double value = ((DoubleConst)tree).get(); if (type == CtClass.floatType) return cp.addFloatInfo((float)value); else if (type == CtClass.doubleType) return cp.addDoubleInfo(value); } } else if (tree instanceof StringL && type.getName().equals(javaLangString)) return cp.addStringInfo(((StringL)tree).get()); return 0; } }
private static void compileReturn(Bytecode code, CtClass type) { if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; if (pt != CtClass.voidType) { String wrapper = pt.getWrapperName(); code.addCheckcast(wrapper); code.addInvokevirtual(wrapper, pt.getGetMethodName(), pt.getGetMethodDescriptor()); } code.addOpcode(pt.getReturnOp()); } else { code.addCheckcast(type); code.addOpcode(Bytecode.ARETURN); } } }
private int insertAfterAdvice(Bytecode code, Javac jv, String src, ConstPool cp, CtClass rtype, int varNo) throws CompileError { int pc = code.currentPc(); if (rtype == CtClass.voidType) { code.addOpcode(Opcode.ACONST_NULL); code.addAstore(varNo); jv.compileStmnt(src); code.addOpcode(Opcode.RETURN); if (code.getMaxLocals() < 1) code.setMaxLocals(1); } else { code.addStore(varNo, rtype); jv.compileStmnt(src); code.addLoad(varNo, rtype); if (rtype.isPrimitive()) code.addOpcode(((CtPrimitiveType)rtype).getReturnOp()); else code.addOpcode(Opcode.ARETURN); } return code.currentPc() - pc; }
char typeDesc = 'L'; int classInfo = 0; if (type.isPrimitive()) { CtPrimitiveType cpt = (CtPrimitiveType)type; size = cpt.getDataSize();