All pastes #404482 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-03-21 01:30 UTC
rendered paste body
    public boolean transform(JavaClass clazz) {
        ClassGen classGen = new ClassGen(clazz);
        classGen.addInterface(interfaceName);
        ConstantPoolGen cpg = classGen.getConstantPool();
        InstructionFactory factory =
                new InstructionFactory(classGen, cpg);
        InstructionList list = new InstructionList();
        MethodGen methodGen =
                new MethodGen(Constants.ACC_PUBLIC, Type.STRING, Type.NO_ARGS,
                        new String[]{}, "getName", className, list, cpg);
        list.append(InstructionFactory.createLoad(STRING_WRAPPER_TYPE, 0));
        list.append(factory.createFieldAccess(className, nameFieldName,
                STRING_WRAPPER_TYPE, Constants.GETFIELD));
        list.append(factory.createInvoke(STRING_WRAPPER_CLASS_NAME,
                "getString", Type.STRING, Type.NO_ARGS,
                Constants.INVOKEVIRTUAL));
        list.append(InstructionFactory.createReturn(Type.OBJECT));
        methodGen.setMaxStack();
        methodGen.setMaxLocals();
        classGen.addMethod(methodGen.getMethod());
        list.dispose();
        clazz = classGen.getJavaClass();
        return true;
    }