Search in sources :

Example 51 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project openj9 by eclipse.

the class IntLongObjectAlignmentTestGenerator method makeExample.

public static byte[] makeExample(String parent, String args) throws Throwable {
    ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv = null;
    MethodVisitor mv;
    cw.visit(V1_7, ACC_SUPER, className, null, parent, null);
    char[] argsArr = args.toCharArray();
    for (char ch : argsArr) {
        switch(ch) {
            case 'i':
                fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
                break;
            case 'j':
                fv = cw.visitField(ACC_PRIVATE, "l", "J", null, null);
                break;
            case 'o':
                fv = cw.visitField(ACC_PRIVATE, "o", "Ljava/lang/Object;", null, null);
                break;
            default:
        }
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(0, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, parent, "<init>", "()V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor) ClassWriter(org.objectweb.asm.ClassWriter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 52 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project openj9 by eclipse.

the class SyntheticTestGenerator method generateClassData.

public static byte[] generateClassData() {
    ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;
    MethodVisitor mv;
    cw.visit(V1_1, ACC_PUBLIC, "com/ibm/j9/recreateclasscompare/testclasses/SyntheticTest", null, "java/lang/Object", null);
    cw.visitAttribute(new SyntheticAttribute());
    {
        fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
        fv.visitAttribute(new SyntheticAttribute());
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, 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 = cw.visitMethod(ACC_PUBLIC, "foo", "()V", null, null);
        mv.visitAttribute(new SyntheticAttribute());
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 1);
        mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor) ClassWriter(org.objectweb.asm.ClassWriter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 53 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project drill by axbaretto.

the class CheckClassVisitorFsm method visitField.

@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
    fsmCursor.transition("visitField");
    final FieldVisitor fieldVisitor = super.visitField(access, name, desc, signature, value);
    // TODO: add CheckFieldVisitorFsm
    return fieldVisitor;
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor)

Example 54 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project motech by motech.

the class EnumBuilderImpl method visitFields.

private void visitFields(ClassWriter classWriter, ClassHelper helper) {
    FieldVisitor fieldVisitor;
    for (String value : helper.values) {
        String prefixedValue = EnumHelper.prefixEnumValue(value);
        fieldVisitor = classWriter.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM, prefixedValue, helper.genericParam, null, null);
        fieldVisitor.visitEnd();
    }
    fieldVisitor = classWriter.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC, "$VALUES", helper.arrayGenericParam, null, null);
    fieldVisitor.visitEnd();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor)

Example 55 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project soot by Sable.

the class EnumTest method generate.

@Override
protected void generate(TraceClassVisitor cw) {
    FieldVisitor fv;
    MethodVisitor mv;
    cw.visit(V1_5, ACC_PUBLIC + ACC_FINAL + ACC_SUPER + ACC_ENUM, "soot/asm/backend/targets/MyEnum", "Ljava/lang/Enum<Lsoot/asm/backend/targets/MyEnum;>;", "java/lang/Enum", null);
    cw.visitSource("MyEnum.java", null);
    {
        fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM, "JA", "Lsoot/asm/backend/targets/MyEnum;", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM, "NEIN", "Lsoot/asm/backend/targets/MyEnum;", null, null);
        fv.visitEnd();
    }
    {
        if (targetCompiler == TargetCompiler.eclipse)
            fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC, "ENUM$VALUES", "[Lsoot/asm/backend/targets/MyEnum;", null, null);
        else
            fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC, "$VALUES", "[Lsoot/asm/backend/targets/MyEnum;", null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
        mv.visitCode();
        mv.visitTypeInsn(NEW, "soot/asm/backend/targets/MyEnum");
        mv.visitInsn(DUP);
        mv.visitLdcInsn("JA");
        mv.visitInsn(ICONST_0);
        mv.visitMethodInsn(INVOKESPECIAL, "soot/asm/backend/targets/MyEnum", "<init>", "(Ljava/lang/String;I)V", false);
        mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "JA", "Lsoot/asm/backend/targets/MyEnum;");
        mv.visitTypeInsn(NEW, "soot/asm/backend/targets/MyEnum");
        mv.visitInsn(DUP);
        mv.visitLdcInsn("NEIN");
        mv.visitInsn(ICONST_1);
        mv.visitMethodInsn(INVOKESPECIAL, "soot/asm/backend/targets/MyEnum", "<init>", "(Ljava/lang/String;I)V", false);
        mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "NEIN", "Lsoot/asm/backend/targets/MyEnum;");
        mv.visitInsn(ICONST_2);
        mv.visitTypeInsn(ANEWARRAY, "soot/asm/backend/targets/MyEnum");
        mv.visitVarInsn(ASTORE, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_0);
        mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "JA", "Lsoot/asm/backend/targets/MyEnum;");
        mv.visitInsn(AASTORE);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "NEIN", "Lsoot/asm/backend/targets/MyEnum;");
        mv.visitInsn(AASTORE);
        mv.visitVarInsn(ALOAD, 0);
        if (targetCompiler == TargetCompiler.eclipse)
            mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "ENUM$VALUES", "[Lsoot/asm/backend/targets/MyEnum;");
        else
            mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "$VALUES", "[Lsoot/asm/backend/targets/MyEnum;");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        if (targetCompiler == TargetCompiler.eclipse)
            mv = cw.visitMethod(ACC_PRIVATE, "<init>", "(Ljava/lang/String;I)V", null, null);
        else
            mv = cw.visitMethod(ACC_PRIVATE, "<init>", "(Ljava/lang/String;I)V", "()V", null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitVarInsn(ILOAD, 2);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "valueOf", "(Ljava/lang/String;)Lsoot/asm/backend/targets/MyEnum;", null, null);
        mv.visitCode();
        mv.visitLdcInsn(Type.getType("Lsoot/asm/backend/targets/MyEnum;"));
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;", false);
        mv.visitTypeInsn(CHECKCAST, "soot/asm/backend/targets/MyEnum");
        mv.visitInsn(ARETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (targetCompiler == TargetCompiler.eclipse) {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "values", "()[Lsoot/asm/backend/targets/MyEnum;", null, null);
        mv.visitCode();
        mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "ENUM$VALUES", "[Lsoot/asm/backend/targets/MyEnum;");
        mv.visitInsn(DUP);
        mv.visitInsn(ARRAYLENGTH);
        mv.visitInsn(DUP);
        mv.visitVarInsn(ISTORE, 0);
        mv.visitTypeInsn(ANEWARRAY, "soot/asm/backend/targets/MyEnum");
        mv.visitVarInsn(ASTORE, 1);
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ILOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V", false);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    } else {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "values", "()[Lsoot/asm/backend/targets/MyEnum;", null, null);
        mv.visitCode();
        mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "$VALUES", "[Lsoot/asm/backend/targets/MyEnum;");
        // mv.visitMethodInsn(INVOKEVIRTUAL, "[Lsoot/asm/backend/targets/MyEnum;", "clone", "()Ljava/lang/Object;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "clone", "()Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, "[Lsoot/asm/backend/targets/MyEnum;");
        mv.visitInsn(ARETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

FieldVisitor (org.objectweb.asm.FieldVisitor)90 MethodVisitor (org.objectweb.asm.MethodVisitor)59 Label (org.objectweb.asm.Label)33 ClassWriter (org.objectweb.asm.ClassWriter)28 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)9 ClassReader (org.objectweb.asm.ClassReader)8 Type (org.objectweb.asm.Type)7 Method (java.lang.reflect.Method)6 ClassVisitor (org.objectweb.asm.ClassVisitor)6 IOException (java.io.IOException)4 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LitString (lucee.transformer.expression.literal.LitString)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintWriter (java.io.PrintWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2