/** * Appends INVOKEVIRTUAL. * * <p>The specified method must not be an inherited method. * It must be directly declared in the class specified * in <code>clazz</code>. * * @param clazz the target class. * @param name the method name * @param returnType the return type. * @param paramTypes the parameter types. */ public void addInvokevirtual(CtClass clazz, String name, CtClass returnType, CtClass[] paramTypes) { String desc = Descriptor.ofMethod(returnType, paramTypes); addInvokevirtual(clazz, name, desc); }
/** * Appends INVOKEVIRTUAL. * * <p>The specified method must not be an inherited method. * It must be directly declared in the class specified * in <code>clazz</code>. * * @param clazz the target class. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) */ public void addInvokevirtual(CtClass clazz, String name, String desc) { addInvokevirtual(constPool.addClassInfo(clazz), name, desc); }
/** * Appends INVOKEVIRTUAL. * * <p>The specified method must not be an inherited method. * It must be directly declared in the class specified * in <code>classname</code>. * * @param classname the fully-qualified class name. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) */ public void addInvokevirtual(String classname, String name, String desc) { addInvokevirtual(constPool.addClassInfo(classname), name, desc); }
/** * Appends INVOKEVIRTUAL. * * <p>The specified method must not be an inherited method. * It must be directly declared in the class specified * in <code>clazz</code>. * * @param clazz the target class. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) */ public void addInvokevirtual(CtClass clazz, String name, String desc) { addInvokevirtual(constPool.addClassInfo(clazz), name, desc); }
/** * Appends INVOKEVIRTUAL. * * <p>The specified method must not be an inherited method. * It must be directly declared in the class specified * in <code>classname</code>. * * @param classname the fully-qualified class name. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) */ public void addInvokevirtual(String classname, String name, String desc) { addInvokevirtual(constPool.addClassInfo(classname), name, desc); }
/** * Appends INVOKEVIRTUAL. * * <p>The specified method must not be an inherited method. * It must be directly declared in the class specified * in <code>clazz</code>. * * @param clazz the target class. * @param name the method name * @param returnType the return type. * @param paramTypes the parameter types. */ public void addInvokevirtual(CtClass clazz, String name, CtClass returnType, CtClass[] paramTypes) { String desc = Descriptor.ofMethod(returnType, paramTypes); addInvokevirtual(clazz, name, desc); }
/** * Appends instructions for executing * <code>java.lang.System.println(<i>message</i>)</code>. * * @param message printed message. */ public void addPrintln(String message) { addGetstatic("java.lang.System", "err", "Ljava/io/PrintStream;"); addLdc(message); addInvokevirtual("java.io.PrintStream", "println", "(Ljava/lang/String;)V"); } }
private void addUnwrapper(Bytecode code, Class type) { final int index = FactoryHelper.typeIndex( type ); final String wrapperType = FactoryHelper.wrapperTypes[index]; // checkcast code.addCheckcast( wrapperType ); // invokevirtual code.addInvokevirtual( wrapperType, FactoryHelper.unwarpMethods[index], FactoryHelper.unwrapDesc[index] ); }
private static void addUnwrapper(Bytecode code, Class type) { if (type.isPrimitive()) { if (type == Void.TYPE) code.addOpcode(Opcode.POP); else { int index = FactoryHelper.typeIndex(type); String wrapper = FactoryHelper.wrapperTypes[index]; code.addCheckcast(wrapper); code.addInvokevirtual(wrapper, FactoryHelper.unwarpMethods[index], FactoryHelper.unwrapDesc[index]); } } else code.addCheckcast(type.getName()); }
/** * Appends instructions for executing * <code>java.lang.System.println(<i>message</i>)</code>. * * @param message printed message. */ public void addPrintln(String message) { addGetstatic("java.lang.System", "err", "Ljava/io/PrintStream;"); addLdc(message); addInvokevirtual("java.io.PrintStream", "println", "(Ljava/lang/String;)V"); } }
private void atStringPlusEq(Expr expr, int type, int dim, String cname, ASTree right) throws CompileError { if (!jvmJavaLangString.equals(cname)) badAssign(expr); convToString(type, dim); // the value might be null. right.accept(this); convToString(exprType, arrayDim); bytecode.addInvokevirtual(javaLangString, "concat", "(Ljava/lang/String;)Ljava/lang/String;"); exprType = CLASS; arrayDim = 0; className = jvmJavaLangString; }
private static void addUnwrapper(Bytecode code, Class<?> type) { if (type.isPrimitive()) { if (type == Void.TYPE) code.addOpcode(Opcode.POP); else { int index = FactoryHelper.typeIndex(type); String wrapper = FactoryHelper.wrapperTypes[index]; code.addCheckcast(wrapper); code.addInvokevirtual(wrapper, FactoryHelper.unwarpMethods[index], FactoryHelper.unwrapDesc[index]); } } else code.addCheckcast(type.getName()); }
private void atStringPlusEq(Expr expr, int type, int dim, String cname, ASTree right) throws CompileError { if (!jvmJavaLangString.equals(cname)) badAssign(expr); convToString(type, dim); // the value might be null. right.accept(this); convToString(exprType, arrayDim); bytecode.addInvokevirtual(javaLangString, "concat", "(Ljava/lang/String;)Ljava/lang/String;"); exprType = CLASS; arrayDim = 0; className = jvmJavaLangString; }
protected void atCflow(ASTList cname) throws CompileError { StringBuffer sbuf = new StringBuffer(); if (cname == null || cname.tail() != null) throw new CompileError("bad " + cflowName); makeCflowName(sbuf, cname.head()); String name = sbuf.toString(); Object[] names = resolver.getClassPool().lookupCflow(name); if (names == null) throw new CompileError("no such " + cflowName + ": " + name); bytecode.addGetstatic((String)names[0], (String)names[1], "Ljavassist/runtime/Cflow;"); bytecode.addInvokevirtual("javassist.runtime.Cflow", "value", "()I"); exprType = INT; arrayDim = 0; className = null; }
protected void atCflow(ASTList cname) throws CompileError { StringBuffer sbuf = new StringBuffer(); if (cname == null || cname.tail() != null) throw new CompileError("bad " + cflowName); makeCflowName(sbuf, cname.head()); String name = sbuf.toString(); Object[] names = resolver.getClassPool().lookupCflow(name); if (names == null) throw new CompileError("no such " + cflowName + ": " + name); bytecode.addGetstatic((String)names[0], (String)names[1], "Ljavassist/runtime/Cflow;"); bytecode.addInvokevirtual("javassist.runtime.Cflow", "value", "()I"); exprType = INT; arrayDim = 0; className = null; }
private void atStringConcatExpr(Expr expr, int type1, int dim1, String cname1) throws CompileError { int type2 = exprType; int dim2 = arrayDim; boolean type2Is2 = is2word(type2, dim2); boolean type2IsString = (type2 == CLASS && jvmJavaLangString.equals(className)); if (type2Is2) convToString(type2, dim2); if (is2word(type1, dim1)) { bytecode.addOpcode(DUP_X2); bytecode.addOpcode(POP); } else bytecode.addOpcode(SWAP); // even if type1 is String, the left operand might be null. convToString(type1, dim1); bytecode.addOpcode(SWAP); if (!type2Is2 && !type2IsString) convToString(type2, dim2); bytecode.addInvokevirtual(javaLangString, "concat", "(Ljava/lang/String;)Ljava/lang/String;"); exprType = CLASS; arrayDim = 0; className = jvmJavaLangString; }
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); } } }
protected void compileUnwrapValue(CtClass type, Bytecode code) throws CompileError { if (type == CtClass.voidType) { addNullIfVoid(); return; } if (exprType == VOID) throw new CompileError("invalid type for " + returnCastName); if (type instanceof CtPrimitiveType) { CtPrimitiveType pt = (CtPrimitiveType)type; // pt is not voidType. String wrapper = pt.getWrapperName(); code.addCheckcast(wrapper); code.addInvokevirtual(wrapper, pt.getGetMethodName(), pt.getGetMethodDescriptor()); setType(type); } else { code.addCheckcast(type); setType(type); } }
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); } } }
protected void compileUnwrapValue(CtClass type, Bytecode code) throws CompileError { if (type == CtClass.voidType) { addNullIfVoid(); return; } if (exprType == VOID) throw new CompileError("invalid type for " + returnCastName); if (type instanceof CtPrimitiveType) { CtPrimitiveType pt = (CtPrimitiveType)type; // pt is not voidType. String wrapper = pt.getWrapperName(); code.addCheckcast(wrapper); code.addInvokevirtual(wrapper, pt.getGetMethodName(), pt.getGetMethodDescriptor()); setType(type); } else { code.addCheckcast(type); setType(type); } }