Search in sources :

Example 36 with AnnotationVisitor

use of org.objectweb.asm.AnnotationVisitor in project groovy-core by groovy.

the class AsmClassGenerator method visitArrayAttributes.

private void visitArrayAttributes(AnnotationNode an, Map<String, ListExpression> arrayAttr, AnnotationVisitor av) {
    if (arrayAttr.isEmpty())
        return;
    for (Map.Entry entry : arrayAttr.entrySet()) {
        AnnotationVisitor av2 = av.visitArray((String) entry.getKey());
        List<Expression> values = ((ListExpression) entry.getValue()).getExpressions();
        if (!values.isEmpty()) {
            int arrayElementType = determineCommonArrayType(values);
            for (Expression exprChild : values) {
                visitAnnotationArrayElement(exprChild, arrayElementType, av2);
            }
        }
        av2.visitEnd();
    }
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 37 with AnnotationVisitor

use of org.objectweb.asm.AnnotationVisitor in project groovy-core by groovy.

the class AsmClassGenerator method visitAnnotationDefaultExpression.

void visitAnnotationDefaultExpression(AnnotationVisitor av, ClassNode type, Expression exp) {
    if (exp instanceof ClosureExpression) {
        ClassNode closureClass = controller.getClosureWriter().getOrAddClosureClass((ClosureExpression) exp, ACC_PUBLIC);
        Type t = Type.getType(BytecodeHelper.getTypeDescription(closureClass));
        av.visit(null, t);
    } else if (type.isArray()) {
        ListExpression list = (ListExpression) exp;
        AnnotationVisitor avl = av.visitArray(null);
        ClassNode componentType = type.getComponentType();
        for (Expression lExp : list.getExpressions()) {
            visitAnnotationDefaultExpression(avl, componentType, lExp);
        }
    } else if (ClassHelper.isPrimitiveType(type) || type.equals(ClassHelper.STRING_TYPE)) {
        ConstantExpression constExp = (ConstantExpression) exp;
        av.visit(null, constExp.getValue());
    } else if (ClassHelper.CLASS_Type.equals(type)) {
        ClassNode clazz = exp.getType();
        Type t = Type.getType(BytecodeHelper.getTypeDescription(clazz));
        av.visit(null, t);
    } else if (type.isDerivedFrom(ClassHelper.Enum_Type)) {
        PropertyExpression pExp = (PropertyExpression) exp;
        ClassExpression cExp = (ClassExpression) pExp.getObjectExpression();
        String desc = BytecodeHelper.getTypeDescription(cExp.getType());
        String name = pExp.getPropertyAsString();
        av.visitEnum(null, desc, name);
    } else if (type.implementsInterface(ClassHelper.Annotation_TYPE)) {
        AnnotationConstantExpression avExp = (AnnotationConstantExpression) exp;
        AnnotationNode value = (AnnotationNode) avExp.getValue();
        AnnotationVisitor avc = av.visitAnnotation(null, BytecodeHelper.getTypeDescription(avExp.getType()));
        visitAnnotationAttributes(value, avc);
    } else {
        throw new GroovyBugError("unexpected annotation type " + type.getName());
    }
    av.visitEnd();
}
Also used : InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) InterfaceHelperClassNode(org.codehaus.groovy.ast.InterfaceHelperClassNode) ClassNode(org.codehaus.groovy.ast.ClassNode) GroovyBugError(org.codehaus.groovy.GroovyBugError) Type(org.objectweb.asm.Type) GenericsType(org.codehaus.groovy.ast.GenericsType) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor)

Example 38 with AnnotationVisitor

use of org.objectweb.asm.AnnotationVisitor in project gradle by gradle.

the class ApiMemberSelector method visitAnnotationValue.

private void visitAnnotationValue(AnnotationVisitor annotationVisitor, AnnotationValue<?> value) {
    String name = value.getName();
    if (value instanceof EnumAnnotationValue) {
        annotationVisitor.visitEnum(name, ((EnumAnnotationValue) value).getTypeDesc(), (String) value.getValue());
    } else if (value instanceof SimpleAnnotationValue) {
        annotationVisitor.visit(name, value.getValue());
    } else if (value instanceof ArrayAnnotationValue) {
        AnnotationVisitor arrayVisitor = annotationVisitor.visitArray(name);
        AnnotationValue<?>[] values = ((ArrayAnnotationValue) value).getValue();
        for (AnnotationValue<?> annotationValue : values) {
            visitAnnotationValue(arrayVisitor, annotationValue);
        }
        arrayVisitor.visitEnd();
    } else if (value instanceof AnnotationAnnotationValue) {
        AnnotationMember annotation = ((AnnotationAnnotationValue) value).getValue();
        AnnotationVisitor annVisitor = annotationVisitor.visitAnnotation(name, annotation.getName());
        visitAnnotationValues(annotation, annVisitor);
    }
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor)

Example 39 with AnnotationVisitor

use of org.objectweb.asm.AnnotationVisitor in project gradle by gradle.

the class ApiMemberSelector method visitAnnotationMembers.

private void visitAnnotationMembers(Set<AnnotationMember> annotationMembers) {
    for (AnnotationMember annotation : annotationMembers) {
        AnnotationVisitor annotationVisitor = apiMemberAdapter.visitAnnotation(annotation.getName(), annotation.isVisible());
        visitAnnotationValues(annotation, annotationVisitor);
    }
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor)

Example 40 with AnnotationVisitor

use of org.objectweb.asm.AnnotationVisitor in project gradle by gradle.

the class ApiMemberSelector method visitAnnotationMembers.

private void visitAnnotationMembers(MethodVisitor mv, Set<AnnotationMember> annotationMembers) {
    for (AnnotationMember annotation : annotationMembers) {
        AnnotationVisitor annotationVisitor;
        if (annotation instanceof ParameterAnnotationMember) {
            annotationVisitor = mv.visitParameterAnnotation(((ParameterAnnotationMember) annotation).getParameter(), annotation.getName(), annotation.isVisible());
        } else {
            annotationVisitor = mv.visitAnnotation(annotation.getName(), annotation.isVisible());
        }
        visitAnnotationValues(annotation, annotationVisitor);
    }
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor)

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