use of org.objectweb.asm.AnnotationVisitor in project robovm by robovm.
the class ObjCBlockPlugin method generateBridgeMethod.
private void generateBridgeMethod(Type[] actualGenericTypes, soot.Type[] unboxedTypes, String[][] targetMethodAnnotations, ClassWriter cw) {
List<Type> genericParamTypes = new ArrayList<>();
genericParamTypes.add(new SootTypeType(LongType.v()));
genericParamTypes.add(new SootTypeType(org_robovm_objc_ObjCBlock.getType()));
for (int i = 1; i < unboxedTypes.length; i++) {
Type t = unboxedTypes[i] instanceof PrimType ? new SootTypeType(unboxedTypes[i]) : actualGenericTypes[i];
genericParamTypes.add(t);
}
Type genericReturnType = unboxedTypes[0] instanceof PrimType ? new SootTypeType(unboxedTypes[0]) : actualGenericTypes[0];
List<soot.Type> rawParamTypes = new ArrayList<>();
rawParamTypes.add(LongType.v());
rawParamTypes.add(org_robovm_objc_ObjCBlock.getType());
rawParamTypes.addAll(Arrays.asList(unboxedTypes).subList(1, unboxedTypes.length));
String name = "invoke";
String signature = getGenericSignature(genericParamTypes, genericReturnType);
String desc = getDescriptor(rawParamTypes, unboxedTypes[0]);
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC | ACC_NATIVE, name, desc, signature, null);
AnnotationVisitor av = mv.visitAnnotation(BRIDGE, true);
av.visit("dynamic", true);
av.visitEnd();
for (String s : targetMethodAnnotations[0]) {
mv.visitAnnotation(s, true).visitEnd();
}
for (int i = 1; i < targetMethodAnnotations.length; i++) {
for (String s : targetMethodAnnotations[i]) {
// We add 2 parameters first so annotations for the first
// parameter must be added at index 2.
mv.visitParameterAnnotation(i + 1, s, true).visitEnd();
}
}
mv.visitParameterAnnotation(0, POINTER, true).visitEnd();
mv.visitEnd();
}
use of org.objectweb.asm.AnnotationVisitor in project quasar by puniverse.
the class CheckInstrumentationVisitor method visitMethod.
@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, String signature, String[] exceptions) {
SuspendableType suspendable = null;
if (suspendableInterface)
suspendable = SuspendableType.SUSPENDABLE_SUPER;
if (suspendable == null)
suspendable = classEntry.check(name, desc);
if (suspendable == null)
suspendable = classifier.isSuspendable(db, sourceName, sourceDebugInfo, isInterface, className, classEntry.getSuperName(), classEntry.getInterfaces(), name, desc, signature, exceptions);
if (suspendable == SuspendableType.SUSPENDABLE) {
hasSuspendable = true;
// synchronized methods can't be made suspendable
if ((access & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED) {
if (!className.equals("clojure/lang/LazySeq") && !db.isAllowMonitors())
throw new UnableToInstrumentException("synchronized method", className, name, desc);
}
}
suspendable = InstrumentClass.suspendableToSuperIfAbstract(access, suspendable);
classEntry.set(name, desc, suspendable);
if (// look for @Suspendable annotation
suspendable == null)
return new MethodVisitor(ASMAPI) {
private boolean susp = false;
@Override
public AnnotationVisitor visitAnnotation(String adesc, boolean visible) {
if (adesc.equals(SUSPENDABLE_DESC))
susp = true;
return null;
}
@Override
public void visitEnd() {
super.visitEnd();
classEntry.set(name, desc, InstrumentClass.suspendableToSuperIfAbstract(access, susp ? SuspendableType.SUSPENDABLE : SuspendableType.NON_SUSPENDABLE));
hasSuspendable = hasSuspendable | susp;
}
};
else
return null;
}
use of org.objectweb.asm.AnnotationVisitor in project LogisticsPipes by RS485.
the class ClassCreator method addMethod.
private static void addMethod(ClassWriter cw, String name, boolean direct, String doc, String newClassName_TYPE) {
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, name, "(Lli/cil/oc/api/machine/Context;Lli/cil/oc/api/machine/Arguments;)[Ljava/lang/Object;", null, new String[] { "java/lang/Exception" });
{
AnnotationVisitor av0 = mv.visitAnnotation("Lli/cil/oc/api/machine/Callback;", true);
if (direct) {
av0.visit("direct", Boolean.TRUE);
} else {
av0.visit("direct", Boolean.FALSE);
}
av0.visit("doc", doc);
av0.visitEnd();
}
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(19, l0);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitLdcInsn(name);
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitVarInsn(Opcodes.ALOAD, 2);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "logisticspipes/proxy/opencomputers/asm/BaseWrapperClass", "invokeMethod", "(Ljava/lang/String;Lli/cil/oc/api/machine/Context;Lli/cil/oc/api/machine/Arguments;)[Ljava/lang/Object;");
mv.visitInsn(Opcodes.ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", newClassName_TYPE, null, l0, l1, 0);
mv.visitLocalVariable("context", "Lli/cil/oc/api/machine/Context;", null, l0, l1, 1);
mv.visitLocalVariable("args", "Lli/cil/oc/api/machine/Arguments;", null, l0, l1, 2);
mv.visitMaxs(4, 3);
mv.visitEnd();
}
use of org.objectweb.asm.AnnotationVisitor in project presto by prestodb.
the class AnnotationDefinition method visitClassAnnotation.
public void visitClassAnnotation(ClassVisitor visitor) {
AnnotationVisitor annotationVisitor = visitor.visitAnnotation(type.getType(), true);
visit(annotationVisitor);
annotationVisitor.visitEnd();
}
use of org.objectweb.asm.AnnotationVisitor in project presto by prestodb.
the class AnnotationDefinition method visit.
private static void visit(AnnotationVisitor visitor, String name, Object value) {
if (value instanceof AnnotationDefinition) {
AnnotationDefinition annotation = (AnnotationDefinition) value;
AnnotationVisitor annotationVisitor = visitor.visitAnnotation(name, annotation.type.getType());
annotation.visit(annotationVisitor);
} else if (value instanceof Enum) {
Enum<?> enumConstant = (Enum<?>) value;
visitor.visitEnum(name, type(enumConstant.getDeclaringClass()).getClassName(), enumConstant.name());
} else if (value instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) value;
visitor.visit(name, Type.getType(parameterizedType.getType()));
} else if (value instanceof Class) {
Class<?> clazz = (Class<?>) value;
visitor.visit(name, Type.getType(clazz));
} else if (value instanceof List) {
AnnotationVisitor arrayVisitor = visitor.visitArray(name);
for (Object element : (List<?>) value) {
visit(arrayVisitor, null, element);
}
arrayVisitor.visitEnd();
} else {
visitor.visit(name, value);
}
}
Aggregations