Search in sources :

Example 41 with AnnotationVisitor

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();
}
Also used : RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) WildcardType(org.robovm.compiler.util.generic.WildcardType) SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootClassType(org.robovm.compiler.util.generic.SootClassType) ByteType(soot.ByteType) Type(org.robovm.compiler.util.generic.Type) DoubleType(soot.DoubleType) GenericArrayType(org.robovm.compiler.util.generic.GenericArrayType) FloatType(soot.FloatType) IntType(soot.IntType) ImplForType(org.robovm.compiler.util.generic.ImplForType) CharType(soot.CharType) LongType(soot.LongType) ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) PrimType(soot.PrimType) VoidType(soot.VoidType) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) ArrayList(java.util.ArrayList) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) PrimType(soot.PrimType) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 42 with AnnotationVisitor

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;
}
Also used : SuspendableType(co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 43 with AnnotationVisitor

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();
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) Label(org.objectweb.asm.Label) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 44 with AnnotationVisitor

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();
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor)

Example 45 with AnnotationVisitor

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);
    }
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) List(java.util.List)

Aggregations

AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)64 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)12 ArrayList (java.util.ArrayList)9 Type (org.objectweb.asm.Type)9 MethodVisitor (org.objectweb.asm.MethodVisitor)7 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 ClassNode (org.codehaus.groovy.ast.ClassNode)6 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)6 InterfaceHelperClassNode (org.codehaus.groovy.ast.InterfaceHelperClassNode)6 ClassVisitor (org.objectweb.asm.ClassVisitor)6 ClassReader (org.objectweb.asm.ClassReader)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 FieldVisitor (org.objectweb.asm.FieldVisitor)3 Label (org.objectweb.asm.Label)3 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2 InputStream (java.io.InputStream)2 List (java.util.List)2 GroovyBugError (org.codehaus.groovy.GroovyBugError)2 GenericsType (org.codehaus.groovy.ast.GenericsType)2