/** * Appends INVOKESPECIAL. The invoked method must not be a default * method declared in an interface. * * @param clazz the index of <code>CONSTANT_Class_info</code> * structure. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) * @see Descriptor#ofConstructor(CtClass[]) */ public void addInvokespecial(int clazz, String name, String desc) { addInvokespecial(false, clazz, name, desc); }
/** * Appends INVOKESPECIAL. The invoked method must not be a default * method declared in an interface. * * @param clazz the index of <code>CONSTANT_Class_info</code> * structure. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) * @see Descriptor#ofConstructor(CtClass[]) */ public void addInvokespecial(int clazz, String name, String desc) { addInvokespecial(false, clazz, name, desc); }
/** * Appends INVOKESPECIAL. * * @param clazz the target class. * @param name the method name. * @param returnType the return type. * @param paramTypes the parameter types. */ public void addInvokespecial(CtClass clazz, String name, CtClass returnType, CtClass[] paramTypes) { String desc = Descriptor.ofMethod(returnType, paramTypes); addInvokespecial(clazz, name, desc); }
/** * Appends INVOKESPECIAL. The invoked method must not be a default * method declared in an interface. * * @param clazz the fully-qualified class name. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) * @see Descriptor#ofConstructor(CtClass[]) */ public void addInvokespecial(String clazz, String name, String desc) { addInvokespecial(false, constPool.addClassInfo(clazz), name, desc); }
/** * Appends INVOKESPECIAL. * * @param clazz the target class. * @param name the method name. * @param returnType the return type. * @param paramTypes the parameter types. */ public void addInvokespecial(CtClass clazz, String name, CtClass returnType, CtClass[] paramTypes) { String desc = Descriptor.ofMethod(returnType, paramTypes); addInvokespecial(clazz, name, desc); }
/** * Appends INVOKESPECIAL. The invoked method must not be a default * method declared in an interface. * * @param clazz the fully-qualified class name. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) * @see Descriptor#ofConstructor(CtClass[]) */ public void addInvokespecial(String clazz, String name, String desc) { addInvokespecial(false, constPool.addClassInfo(clazz), name, desc); }
protected void insertDefaultSuperCall() throws CompileError { bytecode.addAload(0); bytecode.addInvokespecial(MemberResolver.getSuperclass(thisClass), "<init>", "()V"); }
/** * Appends INVOKESPECIAL. * * @param clazz the target class. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) * @see Descriptor#ofConstructor(CtClass[]) */ public void addInvokespecial(CtClass clazz, String name, String desc) { boolean isInterface = clazz == null ? false : clazz.isInterface(); addInvokespecial(isInterface, constPool.addClassInfo(clazz), name, desc); }
/** * Appends INVOKESPECIAL. * * @param isInterface true if the invoked method is a default method * declared in an interface. * @param clazz the index of <code>CONSTANT_Class_info</code> * structure. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) * @see Descriptor#ofConstructor(CtClass[]) */ public void addInvokespecial(boolean isInterface, int clazz, String name, String desc) { int index; if (isInterface) index = constPool.addInterfaceMethodrefInfo(clazz, name, desc); else index = constPool.addMethodrefInfo(clazz, name, desc); addInvokespecial(index, desc); }
@Override protected void insertDefaultSuperCall() throws CompileError { bytecode.addAload(0); bytecode.addInvokespecial(MemberResolver.getSuperclass(thisClass), "<init>", "()V"); }
/** * Appends INVOKESPECIAL. * * @param clazz the target class. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) * @see Descriptor#ofConstructor(CtClass[]) */ public void addInvokespecial(CtClass clazz, String name, String desc) { boolean isInterface = clazz == null ? false : clazz.isInterface(); addInvokespecial(isInterface, constPool.addClassInfo(clazz), name, desc); }
private static int makeWrapper(Bytecode code, Class type, int regno) { int index = FactoryHelper.typeIndex(type); String wrapper = FactoryHelper.wrapperTypes[index]; code.addNew(wrapper); code.addOpcode(Opcode.DUP); addLoad(code, regno, type); code.addInvokespecial(wrapper, "<init>", FactoryHelper.wrapperDesc[index]); return regno + FactoryHelper.dataSize[index]; }
private MethodInfo makeDelegator(Method meth, String desc, ConstPool cp, Class declClass, String delegatorName) { MethodInfo delegator = new MethodInfo(cp, delegatorName, desc); delegator.setAccessFlags(Modifier.FINAL | Modifier.PUBLIC | (meth.getModifiers() & ~(Modifier.PRIVATE | Modifier.PROTECTED | Modifier.ABSTRACT | Modifier.NATIVE | Modifier.SYNCHRONIZED))); setThrows(delegator, cp, meth); Bytecode code = new Bytecode(cp, 0, 0); code.addAload(0); int s = addLoadParameters(code, meth.getParameterTypes(), 1); Class targetClass = invokespecialTarget(declClass); code.addInvokespecial(targetClass.isInterface(), cp.addClassInfo(targetClass.getName()), meth.getName(), desc); addReturn(code, meth.getReturnType()); code.setMaxLocals(++s); delegator.setCodeAttribute(code.toCodeAttribute()); return delegator; }
void compileInvokeSpecial(ASTree target, int methodIndex, String descriptor, ASTList args) throws CompileError { target.accept(this); int nargs = getMethodArgsLength(args); atMethodArgs(args, new int[nargs], new int[nargs], new String[nargs]); bytecode.addInvokespecial(methodIndex, descriptor); setReturnType(descriptor, false, false); addNullIfVoid(); }
private static int makeWrapper(Bytecode code, Class<?> type, int regno) { int index = FactoryHelper.typeIndex(type); String wrapper = FactoryHelper.wrapperTypes[index]; code.addNew(wrapper); code.addOpcode(Opcode.DUP); addLoad(code, regno, type); code.addInvokespecial(wrapper, "<init>", FactoryHelper.wrapperDesc[index]); return regno + FactoryHelper.dataSize[index]; }
/** * Produces codes for a static field. */ int compileIfStatic(CtClass type, String name, Bytecode code, Javac drv) throws CannotCompileException { String desc; code.addNew(objectType); code.add(Bytecode.DUP); int stacksize = 2; if (stringParams == null) desc = "()V"; else { desc = "([Ljava/lang/String;)V"; stacksize += compileStringParameter(code); } code.addInvokespecial(objectType, "<init>", desc); code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type)); return stacksize; }
void compileInvokeSpecial(ASTree target, int methodIndex, String descriptor, ASTList args) throws CompileError { target.accept(this); int nargs = getMethodArgsLength(args); atMethodArgs(args, new int[nargs], new int[nargs], new String[nargs]); bytecode.addInvokespecial(methodIndex, descriptor); setReturnType(descriptor, false, false); addNullIfVoid(); }
/** * Produces codes in which a new object is created and assigned to * the field as the initial value. */ int compile(CtClass type, String name, Bytecode code, CtClass[] parameters, Javac drv) throws CannotCompileException { int stacksize; code.addAload(0); code.addNew(objectType); code.add(Bytecode.DUP); code.addAload(0); if (stringParams == null) stacksize = 4; else stacksize = compileStringParameter(code) + 4; if (withConstructorParams) stacksize += CtNewWrappedMethod.compileParameterList(code, parameters, 1); code.addInvokespecial(objectType, "<init>", getDescriptor()); code.addPutfield(Bytecode.THIS, name, Descriptor.of(type)); return stacksize; }
/** * Creates a default (public) constructor. * * <p>The created constructor takes no parameter. It calls * <code>super()</code>. */ public static CtConstructor defaultConstructor(CtClass declaring) throws CannotCompileException { CtConstructor cons = new CtConstructor((CtClass[])null, declaring); ConstPool cp = declaring.getClassFile2().getConstPool(); Bytecode code = new Bytecode(cp, 1, 1); code.addAload(0); try { code.addInvokespecial(declaring.getSuperclass(), "<init>", "()V"); } catch (NotFoundException e) { throw new CannotCompileException(e); } code.add(Bytecode.RETURN); // no need to construct a stack map table. cons.getMethodInfo2().setCodeAttribute(code.toCodeAttribute()); return cons; }
protected void atCastToWrapper(CastExpr expr) throws CompileError { expr.getOprand().accept(this); if (isRefType(exprType) || arrayDim > 0) return; // Object type. do nothing. CtClass clazz = resolver.lookupClass(exprType, arrayDim, className); if (clazz instanceof CtPrimitiveType) { CtPrimitiveType pt = (CtPrimitiveType)clazz; String wrapper = pt.getWrapperName(); bytecode.addNew(wrapper); // new <wrapper> bytecode.addOpcode(DUP); // dup if (pt.getDataSize() > 1) bytecode.addOpcode(DUP2_X2); // dup2_x2 else bytecode.addOpcode(DUP2_X1); // dup2_x1 bytecode.addOpcode(POP2); // pop2 bytecode.addInvokespecial(wrapper, "<init>", "(" + pt.getDescriptor() + ")V"); // invokespecial exprType = CLASS; arrayDim = 0; className = jvmJavaLangObject; } }