All pastes #636978 Raw Edit

Mine

public text v1 · immutable
#636978 ·published 2007-07-28 12:18 UTC
rendered paste body
   ClassGen addMethodToReturnField(ClassGen cg, String methodName, FieldInstruction fi, ConstantPoolGen cpg, short type)
    {
        return addMethodToReturnField(cg, methodName, fi.getFieldType(cpg), fi.getClassName(cpg), fi.getFieldName(cpg), fi.getFieldType(cpg), type);
    }

    ClassGen addMethodToReturnField(ClassGen cg, String methodname, Type methodtype, String classname, String fieldname, Type fieldtype, short type)
    {
	        ConstantPoolGen cpg = cg.getConstantPool();
	        InstructionList il = new InstructionList();
	        InstructionFactory factory = new InstructionFactory(cg, cpg);
	        MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, methodtype, Type.NO_ARGS, new String[]{}, methodname, cg.getClassName(), il, cpg);
	        il.append(new ALOAD(0));
	        il.append(factory.createFieldAccess(classname, fieldname, fieldtype, type));
	        il.append(InstructionFactory.createReturn(fieldtype));
	        mg.setMaxLocals();
	        mg.setMaxStack();
	        cg.addMethod(mg.getMethod());
            System.out.println("Inject " + methodname + " into " + cg.getClassName());
            return cg;
    	}