Search in sources :

Example 26 with AnnotationTag

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

the class AnnotationsTest method join.

private String join(List<AnnotationTag> annotations) {
    StringBuilder sb = new StringBuilder();
    List<String> l = new ArrayList<>();
    for (AnnotationTag tag : annotations) {
        String type = tag.getType();
        type = type.substring(type.lastIndexOf('$') + 1, type.length() - 1);
        l.add(type);
    }
    Collections.sort(l);
    for (String type : l) {
        if (sb.length() > 0) {
            sb.append(" ");
        }
        sb.append("@" + type);
    }
    return sb.toString();
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) ArrayList(java.util.ArrayList)

Example 27 with AnnotationTag

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

the class Annotations method addRuntimeVisibleParameterAnnotation.

public static void addRuntimeVisibleParameterAnnotation(SootMethod method, int paramIndex, String annotationType) {
    if (!hasParameterAnnotation(method, paramIndex, annotationType)) {
        VisibilityAnnotationTag tag = getOrCreateRuntimeVisibilityAnnotationTag(method, paramIndex);
        tag.addAnnotation(new AnnotationTag(annotationType, 0));
    }
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 28 with AnnotationTag

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

the class Annotations method getParameterAnnotations.

public static List<AnnotationTag>[] getParameterAnnotations(SootMethod method, Visibility visibility) {
    @SuppressWarnings("unchecked") ArrayList<AnnotationTag>[] result = new ArrayList[method.getParameterCount()];
    for (int i = 0; i < result.length; i++) {
        result[i] = new ArrayList<>();
    }
    for (Tag tag : method.getTags()) {
        if (tag instanceof VisibilityParameterAnnotationTag) {
            if (visibility == Visibility.Any || ((VisibilityParameterAnnotationTag) tag).getKind() == visibility.ordinal()) {
                ArrayList<VisibilityAnnotationTag> l = ((VisibilityParameterAnnotationTag) tag).getVisibilityAnnotations();
                if (l != null) {
                    int i = 0;
                    for (VisibilityAnnotationTag t : l) {
                        ArrayList<AnnotationTag> annotations = t.getAnnotations();
                        if (annotations != null) {
                            result[i].addAll(annotations);
                        }
                        i++;
                    }
                }
            }
        }
    }
    return result;
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ArrayList(java.util.ArrayList) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) Tag(soot.tagkit.Tag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 29 with AnnotationTag

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

the class Annotations method addRuntimeVisibleAnnotation.

public static void addRuntimeVisibleAnnotation(Host host, String annotationType) {
    if (!hasAnnotation(host, annotationType)) {
        VisibilityAnnotationTag tag = getOrCreateRuntimeVisibilityAnnotationTag(host);
        tag.addAnnotation(new AnnotationTag(annotationType, 0));
    }
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 30 with AnnotationTag

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

the class Annotations method copyParameterAnnotations.

private static void copyParameterAnnotations(SootMethod fromMethod, SootMethod toMethod, int start, int end, int shift, int visibility) {
    List<AnnotationTag>[] fromAnnos = getParameterAnnotations(fromMethod, Visibility.values()[visibility]);
    List<AnnotationTag>[] toAnnos = getParameterAnnotations(toMethod, Visibility.values()[visibility]);
    for (int i = start; i < end; i++) {
        toAnnos[i + shift].addAll(fromAnnos[i]);
    }
    for (Iterator<Tag> it = toMethod.getTags().iterator(); it.hasNext(); ) {
        Tag tag = it.next();
        if (tag instanceof VisibilityParameterAnnotationTag) {
            if (((VisibilityParameterAnnotationTag) tag).getKind() == visibility) {
                it.remove();
            }
        }
    }
    VisibilityParameterAnnotationTag vpaTag = new VisibilityParameterAnnotationTag(toAnnos.length, visibility);
    for (List<AnnotationTag> annos : toAnnos) {
        VisibilityAnnotationTag vaTag = new VisibilityAnnotationTag(visibility);
        for (AnnotationTag anno : annos) {
            vaTag.addAnnotation(anno);
        }
        vpaTag.addVisibilityAnnotation(vaTag);
    }
    toMethod.addTag(vpaTag);
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) ArrayList(java.util.ArrayList) List(java.util.List) Tag(soot.tagkit.Tag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Aggregations

AnnotationTag (soot.tagkit.AnnotationTag)37 VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)22 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)20 ArrayList (java.util.ArrayList)15 AnnotationAnnotationElem (soot.tagkit.AnnotationAnnotationElem)11 AnnotationElem (soot.tagkit.AnnotationElem)11 Tag (soot.tagkit.Tag)10 AnnotationClassElem (soot.tagkit.AnnotationClassElem)7 AnnotationDefaultTag (soot.tagkit.AnnotationDefaultTag)7 AnnotationStringElem (soot.tagkit.AnnotationStringElem)7 EnclosingMethodTag (soot.tagkit.EnclosingMethodTag)7 InnerClassTag (soot.tagkit.InnerClassTag)7 SignatureTag (soot.tagkit.SignatureTag)7 AnnotationArrayElem (soot.tagkit.AnnotationArrayElem)6 SootMethod (soot.SootMethod)4 HashSet (java.util.HashSet)3 List (java.util.List)3 AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)3 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)3 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)3