use of org.objectweb.asm.FieldVisitor in project soot by Sable.
the class MonitorTest method generate.
@Override
protected void generate(TraceClassVisitor cw) {
FieldVisitor fv;
MethodVisitor mv;
cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/Monitor", null, "java/lang/Object", null);
cw.visitSource("Monitor.java", null);
{
fv = cw.visitField(0, "o", "Ljava/lang/Object;", null, null);
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", false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
if (targetCompiler == TargetCompiler.eclipse) {
mv = cw.visitMethod(ACC_PUBLIC, "doSth", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/Monitor", "o", "Ljava/lang/Object;");
mv.visitInsn(DUP);
mv.visitInsn(MONITORENTER);
mv.visitInsn(MONITOREXIT);
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
} else {
mv = cw.visitMethod(ACC_PUBLIC, "doSth", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable");
Label l3 = new Label();
mv.visitTryCatchBlock(l2, l3, l2, "java/lang/Throwable");
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/Monitor", "o", "Ljava/lang/Object;");
mv.visitVarInsn(ASTORE, 0);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(MONITORENTER);
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l1);
Label l4 = new Label();
mv.visitJumpInsn(GOTO, l4);
mv.visitLabel(l2);
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l3);
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(ATHROW);
mv.visitLabel(l4);
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
cw.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project CodenameOne by codenameone.
the class DefaultWeaveListener method visitEnd.
public void visitEnd() {
if (isEnum) {
cv.visitField(ACC_PRIVATE + ACC_STATIC + ACC_FINAL + ACC_SYNTHETIC, SERIAL_ID_FIELD, SERIAL_ID_SIGNATURE, null, new Long(0L));
}
if (!classLiteralCalls.isEmpty()) {
// generate synthetic fields and class$ method
for (String fieldName : classLiteralCalls) {
FieldVisitor fv = visitField(ACC_STATIC + ACC_SYNTHETIC + (isInterface ? ACC_PUBLIC : ACC_PRIVATE), fieldName, CLASS_FIELD_DESC, null, null);
fv.visitEnd();
}
if (!isInterface) {
// "class$" method
MethodVisitor mv = cv.visitMethod(ACC_STATIC + ACC_SYNTHETIC, "class$", "(Ljava/lang/String;)Ljava/lang/Class;", null, null);
/*mv.visitCode();
Label beginTry = new Label();
Label endTry = new Label();
Label catchBlock = new Label();
Label finished = new Label();
mv.visitTryCatchBlock(beginTry, endTry, catchBlock, "java/lang/Exception");
mv.visitLabel(beginTry);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
mv.visitLabel(endTry);
mv.visitJumpInsn(GOTO, finished);
mv.visitLabel(catchBlock);
mv.visitInsn(POP);
mv.visitLabel(finished);
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();*/
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/ClassNotFoundException");
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
mv.visitVarInsn(ASTORE, 1);
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
/*mv.visitTypeInsn(NEW, "java/lang/NoClassDefFoundError");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NoClassDefFoundError", "<init>", "()V");
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoClassDefFoundError", "initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
mv.visitInsn(ATHROW);*/
mv.visitMaxs(2, 2);
mv.visitEnd();
}
}
if (!stripAttributes) {
RetroWeaverAttribute a = new RetroWeaverAttribute(Weaver.getBuildNumber(), originalClassVersion);
cv.visitAttribute(a);
}
cv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project soot by Sable.
the class AbstractASMBackend method generateAnnotations.
/**
* Emits the bytecode for all annotations of a class, field or method
* @param visitor A ClassVisitor, FieldVisitor or MethodVisitor to emit the bytecode to
* @param host A Host (SootClass, SootField or SootMethod) the bytecode is to be emitted for, has to match the visitor
*/
protected void generateAnnotations(Object visitor, Host host) {
for (Tag t : host.getTags()) {
// Find all VisibilityAnnotationTags
if (t instanceof VisibilityAnnotationTag) {
VisibilityAnnotationTag vat = (VisibilityAnnotationTag) t;
boolean runTimeVisible = (vat.getVisibility() == AnnotationConstants.RUNTIME_VISIBLE);
for (AnnotationTag at : vat.getAnnotations()) {
AnnotationVisitor av = null;
if (visitor instanceof ClassVisitor) {
av = ((ClassVisitor) visitor).visitAnnotation(at.getType(), runTimeVisible);
} else if (visitor instanceof FieldVisitor) {
av = ((FieldVisitor) visitor).visitAnnotation(at.getType(), runTimeVisible);
} else if (visitor instanceof MethodVisitor) {
av = ((MethodVisitor) visitor).visitAnnotation(at.getType(), runTimeVisible);
}
generateAnnotationElems(av, at.getElems(), true);
}
} else // Visit AnnotationDefault on methods
if (host instanceof SootMethod && t instanceof AnnotationDefaultTag) {
AnnotationDefaultTag adt = (AnnotationDefaultTag) t;
AnnotationVisitor av = ((MethodVisitor) visitor).visitAnnotationDefault();
generateAnnotationElems(av, Collections.singleton(adt.getDefaultVal()), true);
}
}
}
use of org.objectweb.asm.FieldVisitor in project drill by apache.
the class TestIcebergTableSchema method testPartitionedPartitionSpec.
@Test
public void testPartitionedPartitionSpec() {
Class<?> clazz = new ClassGenerator(getClass().getSimpleName() + "PartitionedPartitionSpec") {
@Override
void addFields(ClassWriter classWriter) {
FieldVisitor partKey1 = addField(classWriter, Opcodes.ACC_PRIVATE, MetastoreColumn.STORAGE_PLUGIN, String.class);
annotate(partKey1, MetastoreColumn.STORAGE_PLUGIN, MetadataType.ALL);
FieldVisitor partKey2 = addField(classWriter, Opcodes.ACC_PRIVATE, MetastoreColumn.WORKSPACE, String.class);
annotate(partKey2, MetastoreColumn.WORKSPACE, MetadataType.ALL);
FieldVisitor partKey3 = addField(classWriter, Opcodes.ACC_PRIVATE, MetastoreColumn.TABLE_NAME, String.class);
annotate(partKey3, MetastoreColumn.TABLE_NAME, MetadataType.ALL);
FieldVisitor integerField = addField(classWriter, Opcodes.ACC_PRIVATE, MetastoreColumn.ROW_GROUP_INDEX, Integer.class);
annotate(integerField, MetastoreColumn.ROW_GROUP_INDEX, MetadataType.ROW_GROUP);
FieldVisitor stringField = addField(classWriter, Opcodes.ACC_PRIVATE, MetastoreColumn.OWNER, Boolean.class);
annotate(stringField, MetastoreColumn.OWNER, MetadataType.TABLE);
}
}.generate();
IcebergTableSchema schema = IcebergTableSchema.of(clazz, Arrays.asList(MetastoreColumn.STORAGE_PLUGIN, MetastoreColumn.WORKSPACE, MetastoreColumn.TABLE_NAME));
Types.NestedField partKey1 = schema.tableSchema().findField(MetastoreColumn.STORAGE_PLUGIN.columnName());
assertNotNull(partKey1);
Types.NestedField partKey2 = schema.tableSchema().findField(MetastoreColumn.WORKSPACE.columnName());
assertNotNull(partKey2);
Types.NestedField partKey3 = schema.tableSchema().findField(MetastoreColumn.TABLE_NAME.columnName());
assertNotNull(partKey3);
assertNotNull(schema.tableSchema().findField(MetastoreColumn.ROW_GROUP_INDEX.columnName()));
assertNotNull(schema.tableSchema().findField(MetastoreColumn.OWNER.columnName()));
Schema partitionSchema = new Schema(partKey1, partKey2, partKey3);
PartitionSpec expectedPartitionSpec = PartitionSpec.builderFor(partitionSchema).identity(partKey1.name()).identity(partKey2.name()).identity(partKey3.name()).build();
assertEquals(expectedPartitionSpec, schema.partitionSpec());
}
use of org.objectweb.asm.FieldVisitor in project presto by prestodb.
the class FieldDefinition method visit.
public void visit(ClassVisitor visitor) {
FieldVisitor fieldVisitor = visitor.visitField(toAccessModifier(access), name, type.getType(), type.getGenericSignature(), null);
if (fieldVisitor == null) {
return;
}
for (AnnotationDefinition annotation : annotations) {
annotation.visitFieldAnnotation(fieldVisitor);
}
fieldVisitor.visitEnd();
}
Aggregations