Package org.objectweb.asm.util

Examples of org.objectweb.asm.util.CheckClassAdapter


*/
public class AddMethodAdapterTest extends AbstractTestCase {

  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter ca = new CheckClassAdapter(cw);
    AddMethodAdapter am = new AddMethodAdapter(ca);
    generateBasicClass(am);
    checkClass(defineClass("C", cw.toByteArray()));
  }
View Full Code Here


*/
public class RemoveMethodAdapterTest extends AbstractTestCase {

  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter ca = new CheckClassAdapter(cw);
    RemoveMethodAdapter af = new RemoveMethodAdapter(ca, "m", "()V");
    generateBasicClass(af);
    checkClass(defineClass("C", cw.toByteArray()));
  }
View Full Code Here

*/
public class ChangeVersionAdapterTest extends AbstractTestCase {

  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter ca = new CheckClassAdapter(cw);
    ChangeVersionAdapter cv = new ChangeVersionAdapter(ca);
    generateBasicClass(cv);
    defineClass("C", cw.toByteArray());
  }
View Full Code Here

*/
public class AddTimerTransformerTest extends AddTimerAdapterTest {

  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter ca = new CheckClassAdapter(cw);
    ClassNode cn = generateBasicClass();
    new AddTimerTransformer(null).transform(cn);
    cn.accept(ca);
    checkClass(defineClass("C", cw.toByteArray()));
  }
View Full Code Here

*/
public class AddAnnotationAdapterTest extends AbstractTestCase {

  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter ca = new CheckClassAdapter(cw);
    AddAnnotationAdapter aa = new AddAnnotationAdapter(ca,
        "Ljava/lang/Deprecated;");
    generateBasicClass(aa);
    checkClass(defineClass("C", cw.toByteArray()));
  }
View Full Code Here

*/
public class RemoveAnnotationAdapterTest extends AbstractTestCase {

  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter ca = new CheckClassAdapter(cw);
    RemoveAnnotationAdapter ra = new RemoveAnnotationAdapter(ca,
        "Ljava/lang/Deprecated;");
    AddAnnotationAdapter aa = new AddAnnotationAdapter(ra,
        "Ljava/lang/Deprecated;");
    generateBasicClass(aa);
View Full Code Here

public class ComparableGenerator {

  public byte[] generate(PrintWriter printWriter) {
    ClassWriter cw = new ClassWriter(0);
    TraceClassVisitor tcv = new TraceClassVisitor(cw, printWriter);
    CheckClassAdapter cv = new CheckClassAdapter(tcv);
    cv.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE,
        "pkg/Comparable", null, "java/lang/Object",
        new String[] { "pkg/Mesurable" });
    cv.visitSource("Comparable.java", null);
    cv.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "LESS", "I",
        null, new Integer(-1)).visitEnd();
    cv.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "EQUAL", "I",
        null, new Integer(0)).visitEnd();
    cv.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "GREATER", "I",
        null, new Integer(1)).visitEnd();
    cv.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "compareTo",
        "(Ljava/lang/Object;)I", null, null).visitEnd();
    cv.visitEnd();
    byte[] b = cw.toByteArray();
    return b;
  }
View Full Code Here

public class BeanGenerator2 {

  public byte[] generate(PrintWriter printWriter) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    TraceClassVisitor tcv = new TraceClassVisitor(cw, printWriter);
    CheckClassAdapter cv = new CheckClassAdapter(tcv);
    cv.visit(V1_6, ACC_PUBLIC, "pkg/Bean", null, "java/lang/Object",
        null);
    cv.visitSource("Bean.java", null);
    FieldVisitor fv = cv.visitField(ACC_PRIVATE, "f", "I", null, null);
    if (fv != null) {
      fv.visitEnd();
    }
    MethodVisitor mv;
    mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    if (mv != null) {
      Method m = Method.getMethod("void <init>()");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
      ga.loadThis();
      ga.invokeConstructor(Type.getType("Ljava/lang/Object;"), m);
      ga.returnValue();
      ga.endMethod();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "getF", "()I", null, null);
    if (mv != null) {
      Type bean = Type.getType("Lpkg/Bean;");
      Method m = Method.getMethod("int getF()");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
      ga.loadThis();
      ga.getField(bean, "f", Type.INT_TYPE);
      ga.returnValue();
      ga.endMethod();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "setF", "(I)V", null, null);
    if (mv != null) {
      Type bean = Type.getType("Lpkg/Bean;");
      Method m = Method.getMethod("void setF(int)");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
      ga.loadThis();
      ga.loadArg(0);
      ga.putField(bean, "f", Type.INT_TYPE);
      ga.returnValue();
      ga.endMethod();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "checkAndSetF", "(I)V", null, null);
    if (mv != null) {
      Type bean = Type.getType("Lpkg/Bean;");
      Method m = Method.getMethod("void checkAndSetF(int)");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
      ga.loadArg(0);
      Label label = new Label();
      ga.ifZCmp(GeneratorAdapter.LT, label);
      ga.loadThis();
      ga.loadArg(0);
      ga.putField(bean, "f", Type.INT_TYPE);
      Label end = new Label();
      ga.goTo(end);
      ga.mark(label);
      ga.throwException(Type.getType(IllegalArgumentException.class),
          "f");
      ga.mark(end);
      ga.returnValue();
      ga.endMethod();
    }
    cv.visitEnd();
    byte[] b = cw.toByteArray();
    return b;
  }
View Full Code Here

public class BeanGenerator {

  public byte[] generate(PrintWriter printWriter) {
    ClassWriter cw = new ClassWriter(0);
    TraceClassVisitor tcv = new TraceClassVisitor(cw, printWriter);
    CheckClassAdapter cv = new CheckClassAdapter(tcv);
    cv.visit(V1_6, ACC_PUBLIC, "pkg/Bean", null, "java/lang/Object",
        null);
    cv.visitSource("Bean.java", null);
    FieldVisitor fv = cv.visitField(ACC_PRIVATE, "f", "I", null, null);
    if (fv != null) {
      fv.visitEnd();
    }
    MethodVisitor mv;
    mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    if (mv != null) {
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>",
          "()V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "getF", "()I", null, null);
    if (mv != null) {
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, "pkg/Bean", "f", "I");
      mv.visitInsn(IRETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "setF", "(I)V", null, null);
    if (mv != null) {
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitVarInsn(ILOAD, 1);
      mv.visitFieldInsn(PUTFIELD, "pkg/Bean", "f", "I");
      mv.visitInsn(RETURN);
      mv.visitMaxs(2, 2);
      mv.visitEnd();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "checkAndSetF", "(I)V", null, null);
    if (mv != null) {
      mv.visitCode();
      mv.visitVarInsn(ILOAD, 1);
      Label label = new Label();
      mv.visitJumpInsn(IFLT, label);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitVarInsn(ILOAD, 1);
      mv.visitFieldInsn(PUTFIELD, "pkg/Bean", "f", "I");
      Label end = new Label();
      mv.visitJumpInsn(GOTO, end);
      mv.visitLabel(label);
      mv.visitFrame(F_SAME, 0, null, 0, null);
      mv.visitTypeInsn(NEW, "java/lang/IllegalArgumentException");
      mv.visitInsn(DUP);
      mv.visitMethodInsn(INVOKESPECIAL,
          "java/lang/IllegalArgumentException", "<init>", "()V");
      mv.visitInsn(ATHROW);
      mv.visitLabel(end);
      mv.visitFrame(F_SAME, 0, null, 0, null);
      mv.visitInsn(RETURN);
      mv.visitMaxs(2, 2);
      mv.visitEnd();
    }
    cv.visitEnd();
    return cw.toByteArray();
  }
View Full Code Here

public class RemoveAnnotationTransformerTest extends
    RemoveAnnotationAdapterTest {

  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter ca = new CheckClassAdapter(cw);
    ClassNode cn = generateBasicClass();
    ClassTransformer ct = null;
    ct = new RemoveAnnotationTransformer(ct, "Ljava/lang/Deprecated;");
    ct = new AddAnnotationTransformer(ct, "Ljava/lang/Deprecated;");
    ct.transform(cn);
View Full Code Here

TOP

Related Classes of org.objectweb.asm.util.CheckClassAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.