Search in sources :

Example 1 with AnnotationAnnotationElem

use of soot.tagkit.AnnotationAnnotationElem in project robovm by robovm.

the class Annotations method getMarshalerAnnotations.

public static List<AnnotationTag> getMarshalerAnnotations(SootClass clazz) {
    List<AnnotationTag> tags = new ArrayList<AnnotationTag>();
    AnnotationTag marshaler = getAnnotation(clazz, MARSHALER);
    if (marshaler != null) {
        tags.add(marshaler);
    } else {
        AnnotationTag marshalers = getAnnotation(clazz, MARSHALERS);
        if (marshalers != null) {
            for (AnnotationElem e : ((AnnotationArrayElem) marshalers.getElemAt(0)).getValues()) {
                AnnotationAnnotationElem elem = (AnnotationAnnotationElem) e;
                tags.add(elem.getValue());
            }
        }
    }
    return tags;
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) ArrayList(java.util.ArrayList) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) AnnotationElem(soot.tagkit.AnnotationElem)

Example 2 with AnnotationAnnotationElem

use of soot.tagkit.AnnotationAnnotationElem in project soot by Sable.

the class Util method createElementTags.

private ArrayList<AnnotationElem> createElementTags(int count, ClassFile coffiClass, element_value[] elems) {
    ArrayList<AnnotationElem> list = new ArrayList<AnnotationElem>();
    for (int j = 0; j < count; j++) {
        element_value ev = elems[j];
        char kind = ev.tag;
        String elemName = "default";
        if (ev.name_index != 0) {
            elemName = ((CONSTANT_Utf8_info) coffiClass.constant_pool[ev.name_index]).convert();
        }
        if (kind == 'B' || kind == 'C' || kind == 'I' || kind == 'S' || kind == 'Z' || kind == 'D' || kind == 'F' || kind == 'J' || kind == 's') {
            constant_element_value cev = (constant_element_value) ev;
            if (kind == 'B' || kind == 'C' || kind == 'I' || kind == 'S' || kind == 'Z') {
                cp_info cval = coffiClass.constant_pool[cev.constant_value_index];
                int constant_val = (int) ((CONSTANT_Integer_info) cval).bytes;
                AnnotationIntElem elem = new AnnotationIntElem(constant_val, kind, elemName);
                list.add(elem);
            } else if (kind == 'D') {
                cp_info cval = coffiClass.constant_pool[cev.constant_value_index];
                double constant_val = ((CONSTANT_Double_info) cval).convert();
                AnnotationDoubleElem elem = new AnnotationDoubleElem(constant_val, kind, elemName);
                list.add(elem);
            } else if (kind == 'F') {
                cp_info cval = coffiClass.constant_pool[cev.constant_value_index];
                float constant_val = ((CONSTANT_Float_info) cval).convert();
                AnnotationFloatElem elem = new AnnotationFloatElem(constant_val, kind, elemName);
                list.add(elem);
            } else if (kind == 'J') {
                cp_info cval = coffiClass.constant_pool[cev.constant_value_index];
                CONSTANT_Long_info lcval = (CONSTANT_Long_info) cval;
                long constant_val = (lcval.high << 32) + lcval.low;
                AnnotationLongElem elem = new AnnotationLongElem(constant_val, kind, elemName);
                list.add(elem);
            } else if (kind == 's') {
                cp_info cval = coffiClass.constant_pool[cev.constant_value_index];
                String constant_val = ((CONSTANT_Utf8_info) cval).convert();
                AnnotationStringElem elem = new AnnotationStringElem(constant_val, kind, elemName);
                list.add(elem);
            }
        } else if (kind == 'e') {
            enum_constant_element_value ecev = (enum_constant_element_value) ev;
            cp_info type_val = coffiClass.constant_pool[ecev.type_name_index];
            String type_name = ((CONSTANT_Utf8_info) type_val).convert();
            cp_info name_val = coffiClass.constant_pool[ecev.constant_name_index];
            String constant_name = ((CONSTANT_Utf8_info) name_val).convert();
            AnnotationEnumElem elem = new AnnotationEnumElem(type_name, constant_name, kind, elemName);
            list.add(elem);
        } else if (kind == 'c') {
            class_element_value cev = (class_element_value) ev;
            cp_info cval = coffiClass.constant_pool[cev.class_info_index];
            CONSTANT_Utf8_info sval = (CONSTANT_Utf8_info) cval;
            String desc = sval.convert();
            AnnotationClassElem elem = new AnnotationClassElem(desc, kind, elemName);
            list.add(elem);
        } else if (kind == '[') {
            array_element_value aev = (array_element_value) ev;
            int num_vals = aev.num_values;
            ArrayList<AnnotationElem> elemVals = createElementTags(num_vals, coffiClass, aev.values);
            AnnotationArrayElem elem = new AnnotationArrayElem(elemVals, kind, elemName);
            list.add(elem);
        } else if (kind == '@') {
            annotation_element_value aev = (annotation_element_value) ev;
            annotation annot = aev.annotation_value;
            String annotType = ((CONSTANT_Utf8_info) coffiClass.constant_pool[annot.type_index]).convert();
            AnnotationTag annotTag = new AnnotationTag(annotType, createElementTags(annot.num_element_value_pairs, coffiClass, annot.element_value_pairs));
            AnnotationAnnotationElem elem = new AnnotationAnnotationElem(annotTag, kind, elemName);
            list.add(elem);
        }
    }
    return list;
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) ArrayList(java.util.ArrayList) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) AnnotationElem(soot.tagkit.AnnotationElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) AnnotationEnumElem(soot.tagkit.AnnotationEnumElem) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationClassElem(soot.tagkit.AnnotationClassElem)

Example 3 with AnnotationAnnotationElem

use of soot.tagkit.AnnotationAnnotationElem in project soot by Sable.

the class AnnotationElemBuilder method visitAnnotation.

@Override
public AnnotationVisitor visitAnnotation(final String name, final String desc) {
    return new AnnotationElemBuilder() {

        @Override
        public void visitEnd() {
            AnnotationTag tag = new AnnotationTag(desc, elems);
            AnnotationElemBuilder.this.elems.add(new AnnotationAnnotationElem(tag, '@', name));
        }
    };
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem)

Example 4 with AnnotationAnnotationElem

use of soot.tagkit.AnnotationAnnotationElem in project soot by Sable.

the class AbstractASMBackend method generateAnnotationElems.

/**
 * Emits the bytecode for the values of an annotation
 * @param av The AnnotationVisitor to emit the bytecode to
 * @param elements A collection of AnnatiotionElem that are the values of the annotation
 * @param addName True, if the name of the annotation has to be added, false otherwise (should be false only in recursive calls!)
 */
protected void generateAnnotationElems(AnnotationVisitor av, Collection<AnnotationElem> elements, boolean addName) {
    if (av != null) {
        Iterator<AnnotationElem> it = elements.iterator();
        while (it.hasNext()) {
            AnnotationElem elem = it.next();
            if (elem instanceof AnnotationEnumElem) {
                AnnotationEnumElem enumElem = (AnnotationEnumElem) elem;
                av.visitEnum(enumElem.getName(), enumElem.getTypeName(), enumElem.getConstantName());
            } else if (elem instanceof AnnotationArrayElem) {
                AnnotationArrayElem arrayElem = (AnnotationArrayElem) elem;
                AnnotationVisitor arrayVisitor = av.visitArray(arrayElem.getName());
                generateAnnotationElems(arrayVisitor, arrayElem.getValues(), false);
            } else if (elem instanceof AnnotationAnnotationElem) {
                AnnotationAnnotationElem aElem = (AnnotationAnnotationElem) elem;
                AnnotationVisitor aVisitor = av.visitAnnotation(aElem.getName(), aElem.getValue().getType());
                generateAnnotationElems(aVisitor, aElem.getValue().getElems(), true);
            } else {
                Object val = null;
                if (elem instanceof AnnotationIntElem) {
                    AnnotationIntElem intElem = (AnnotationIntElem) elem;
                    int value = intElem.getValue();
                    switch(intElem.getKind()) {
                        case 'B':
                            val = (byte) value;
                            break;
                        case 'Z':
                            val = (value == 1);
                            break;
                        case 'I':
                            val = value;
                            break;
                        case 'S':
                            val = (short) value;
                            break;
                    }
                } else if (elem instanceof AnnotationBooleanElem) {
                    AnnotationBooleanElem booleanElem = (AnnotationBooleanElem) elem;
                    val = booleanElem.getValue();
                } else if (elem instanceof AnnotationFloatElem) {
                    AnnotationFloatElem floatElem = (AnnotationFloatElem) elem;
                    val = floatElem.getValue();
                } else if (elem instanceof AnnotationLongElem) {
                    AnnotationLongElem longElem = (AnnotationLongElem) elem;
                    val = longElem.getValue();
                } else if (elem instanceof AnnotationDoubleElem) {
                    AnnotationDoubleElem doubleElem = (AnnotationDoubleElem) elem;
                    val = doubleElem.getValue();
                } else if (elem instanceof AnnotationStringElem) {
                    AnnotationStringElem stringElem = (AnnotationStringElem) elem;
                    val = stringElem.getValue();
                } else if (elem instanceof AnnotationClassElem) {
                    AnnotationClassElem classElem = (AnnotationClassElem) elem;
                    val = org.objectweb.asm.Type.getType(classElem.getDesc());
                }
                if (addName) {
                    av.visit(elem.getName(), val);
                } else {
                    av.visit(null, val);
                }
            }
        }
        av.visitEnd();
    }
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) AnnotationBooleanElem(soot.tagkit.AnnotationBooleanElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationEnumElem(soot.tagkit.AnnotationEnumElem) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) AnnotationClassElem(soot.tagkit.AnnotationClassElem) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) AnnotationElem(soot.tagkit.AnnotationElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem)

Example 5 with AnnotationAnnotationElem

use of soot.tagkit.AnnotationAnnotationElem in project robovm by robovm.

the class AttributesEncoder method encodeAnnotationElementValue.

private PackedStructureConstant encodeAnnotationElementValue(AnnotationElem ae) {
    PackedStructureType type = getAnnotationElementType(ae);
    Value kind = new IntegerConstant((byte) ae.getKind());
    if (ae instanceof AnnotationIntElem) {
        AnnotationIntElem aie = (AnnotationIntElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(aie.getValue()));
    } else if (ae instanceof AnnotationLongElem) {
        AnnotationLongElem ale = (AnnotationLongElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(ale.getValue()));
    } else if (ae instanceof AnnotationFloatElem) {
        AnnotationFloatElem afe = (AnnotationFloatElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(afe.getValue()));
    } else if (ae instanceof AnnotationDoubleElem) {
        AnnotationDoubleElem ade = (AnnotationDoubleElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(ade.getValue()));
    } else if (ae instanceof AnnotationStringElem) {
        AnnotationStringElem ase = (AnnotationStringElem) ae;
        return new PackedStructureConstant(type, kind, getStringOrNull(ase.getValue()));
    } else if (ae instanceof AnnotationClassElem) {
        AnnotationClassElem ace = (AnnotationClassElem) ae;
        addDependencyIfNeeded(ace.getDesc());
        return new PackedStructureConstant(type, kind, getStringOrNull(ace.getDesc()));
    } else if (ae instanceof AnnotationEnumElem) {
        AnnotationEnumElem aee = (AnnotationEnumElem) ae;
        addDependencyIfNeeded(aee.getTypeName());
        return new PackedStructureConstant(type, kind, getStringOrNull(aee.getTypeName()), getStringOrNull(aee.getConstantName()));
    } else if (ae instanceof AnnotationArrayElem) {
        AnnotationArrayElem aae = (AnnotationArrayElem) ae;
        Value[] values = new Value[aae.getNumValues() + 2];
        values[0] = kind;
        values[1] = new IntegerConstant((char) aae.getNumValues());
        for (int i = 0; i < aae.getNumValues(); i++) {
            values[i + 2] = encodeAnnotationElementValue(aae.getValueAt(i));
        }
        return new PackedStructureConstant(type, values);
    } else if (ae instanceof AnnotationAnnotationElem) {
        AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
        return new PackedStructureConstant(type, kind, encodeAnnotationTagValue(aae.getValue()));
    }
    throw new IllegalArgumentException("Unknown AnnotationElem type: " + ae.getClass());
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) FloatingPointConstant(org.robovm.compiler.llvm.FloatingPointConstant) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) PackedStructureConstant(org.robovm.compiler.llvm.PackedStructureConstant) AnnotationEnumElem(soot.tagkit.AnnotationEnumElem) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) AnnotationClassElem(soot.tagkit.AnnotationClassElem) Value(org.robovm.compiler.llvm.Value)

Aggregations

AnnotationAnnotationElem (soot.tagkit.AnnotationAnnotationElem)8 AnnotationElem (soot.tagkit.AnnotationElem)6 AnnotationTag (soot.tagkit.AnnotationTag)6 AnnotationArrayElem (soot.tagkit.AnnotationArrayElem)5 VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)5 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)5 ArrayList (java.util.ArrayList)4 AnnotationClassElem (soot.tagkit.AnnotationClassElem)4 AnnotationDoubleElem (soot.tagkit.AnnotationDoubleElem)4 AnnotationEnumElem (soot.tagkit.AnnotationEnumElem)4 AnnotationFloatElem (soot.tagkit.AnnotationFloatElem)4 AnnotationIntElem (soot.tagkit.AnnotationIntElem)4 AnnotationLongElem (soot.tagkit.AnnotationLongElem)4 AnnotationStringElem (soot.tagkit.AnnotationStringElem)4 SootMethod (soot.SootMethod)2 AnnotationDefaultTag (soot.tagkit.AnnotationDefaultTag)2 EnclosingMethodTag (soot.tagkit.EnclosingMethodTag)2 InnerClassAttribute (soot.tagkit.InnerClassAttribute)2 InnerClassTag (soot.tagkit.InnerClassTag)2 ParamNamesTag (soot.tagkit.ParamNamesTag)2