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();
}
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();
}
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;
}
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();
}
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();
}
Aggregations