FileDocCategorySizeDatePackage
AnnotationUtils.javaAPI DocAndroid 5.1 API8996Thu Mar 12 22:18:30 GMT 2015com.android.dx.dex.file

AnnotationUtils

public final class AnnotationUtils extends Object
Utility class for dealing with annotations.

Fields Summary
private static final com.android.dx.rop.cst.CstType
ANNOTATION_DEFAULT_TYPE
{@code non-null;} type for {@code AnnotationDefault} annotations
private static final com.android.dx.rop.cst.CstType
ENCLOSING_CLASS_TYPE
{@code non-null;} type for {@code EnclosingClass} annotations
private static final com.android.dx.rop.cst.CstType
ENCLOSING_METHOD_TYPE
{@code non-null;} type for {@code EnclosingMethod} annotations
private static final com.android.dx.rop.cst.CstType
INNER_CLASS_TYPE
{@code non-null;} type for {@code InnerClass} annotations
private static final com.android.dx.rop.cst.CstType
MEMBER_CLASSES_TYPE
{@code non-null;} type for {@code MemberClasses} annotations
private static final com.android.dx.rop.cst.CstType
SIGNATURE_TYPE
{@code non-null;} type for {@code Signature} annotations
private static final com.android.dx.rop.cst.CstType
THROWS_TYPE
{@code non-null;} type for {@code Throws} annotations
private static final com.android.dx.rop.cst.CstString
ACCESS_FLAGS_STRING
{@code non-null;} the UTF-8 constant {@code "accessFlags"}
private static final com.android.dx.rop.cst.CstString
NAME_STRING
{@code non-null;} the UTF-8 constant {@code "name"}
private static final com.android.dx.rop.cst.CstString
VALUE_STRING
{@code non-null;} the UTF-8 constant {@code "value"}
Constructors Summary
private AnnotationUtils()
This class is uninstantiable.


             
      
        // This space intentionally left blank.
    
Methods Summary
public static com.android.dx.rop.annotation.AnnotationmakeAnnotationDefault(com.android.dx.rop.annotation.Annotation defaults)
Constructs a standard {@code AnnotationDefault} annotation.

param
defaults {@code non-null;} the defaults, itself as an annotation
return
{@code non-null;} the constructed annotation

        Annotation result = new Annotation(ANNOTATION_DEFAULT_TYPE, SYSTEM);

        result.put(new NameValuePair(VALUE_STRING, new CstAnnotation(defaults)));
        result.setImmutable();
        return result;
    
private static com.android.dx.rop.cst.CstArraymakeCstArray(com.android.dx.rop.type.TypeList types)
Converts a {@link TypeList} to a {@link CstArray}.

param
types {@code non-null;} the type list
return
{@code non-null;} the corresponding array constant

        int size = types.size();
        CstArray.List list = new CstArray.List(size);

        for (int i = 0; i < size; i++) {
            list.set(i, CstType.intern(types.getType(i)));
        }

        list.setImmutable();
        return new CstArray(list);
    
public static com.android.dx.rop.annotation.AnnotationmakeEnclosingClass(com.android.dx.rop.cst.CstType clazz)
Constructs a standard {@code EnclosingClass} annotation.

param
clazz {@code non-null;} the enclosing class
return
{@code non-null;} the annotation

        Annotation result = new Annotation(ENCLOSING_CLASS_TYPE, SYSTEM);

        result.put(new NameValuePair(VALUE_STRING, clazz));
        result.setImmutable();
        return result;
    
public static com.android.dx.rop.annotation.AnnotationmakeEnclosingMethod(com.android.dx.rop.cst.CstMethodRef method)
Constructs a standard {@code EnclosingMethod} annotation.

param
method {@code non-null;} the enclosing method
return
{@code non-null;} the annotation

        Annotation result = new Annotation(ENCLOSING_METHOD_TYPE, SYSTEM);

        result.put(new NameValuePair(VALUE_STRING, method));
        result.setImmutable();
        return result;
    
public static com.android.dx.rop.annotation.AnnotationmakeInnerClass(com.android.dx.rop.cst.CstString name, int accessFlags)
Constructs a standard {@code InnerClass} annotation.

param
name {@code null-ok;} the original name of the class, or {@code null} to represent an anonymous class
param
accessFlags the original access flags
return
{@code non-null;} the annotation

        Annotation result = new Annotation(INNER_CLASS_TYPE, SYSTEM);
        Constant nameCst = (name != null) ? name : CstKnownNull.THE_ONE;

        result.put(new NameValuePair(NAME_STRING, nameCst));
        result.put(new NameValuePair(ACCESS_FLAGS_STRING,
                        CstInteger.make(accessFlags)));
        result.setImmutable();
        return result;
    
public static com.android.dx.rop.annotation.AnnotationmakeMemberClasses(com.android.dx.rop.type.TypeList types)
Constructs a standard {@code MemberClasses} annotation.

param
types {@code non-null;} the list of (the types of) the member classes
return
{@code non-null;} the annotation

        CstArray array = makeCstArray(types);
        Annotation result = new Annotation(MEMBER_CLASSES_TYPE, SYSTEM);
        result.put(new NameValuePair(VALUE_STRING, array));
        result.setImmutable();
        return result;
    
public static com.android.dx.rop.annotation.AnnotationmakeSignature(com.android.dx.rop.cst.CstString signature)
Constructs a standard {@code Signature} annotation.

param
signature {@code non-null;} the signature string
return
{@code non-null;} the annotation

        Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);

        /*
         * Split the string into pieces that are likely to be common
         * across many signatures and the rest of the file.
         */

        String raw = signature.getString();
        int rawLength = raw.length();
        ArrayList<String> pieces = new ArrayList<String>(20);

        for (int at = 0; at < rawLength; /*at*/) {
            char c = raw.charAt(at);
            int endAt = at + 1;
            if (c == 'L") {
                // Scan to ';' or '<'. Consume ';' but not '<'.
                while (endAt < rawLength) {
                    c = raw.charAt(endAt);
                    if (c == ';") {
                        endAt++;
                        break;
                    } else if (c == '<") {
                        break;
                    }
                    endAt++;
                }
            } else {
                // Scan to 'L' without consuming it.
                while (endAt < rawLength) {
                    c = raw.charAt(endAt);
                    if (c == 'L") {
                        break;
                    }
                    endAt++;
                }
            }

            pieces.add(raw.substring(at, endAt));
            at = endAt;
        }

        int size = pieces.size();
        CstArray.List list = new CstArray.List(size);

        for (int i = 0; i < size; i++) {
            list.set(i, new CstString(pieces.get(i)));
        }

        list.setImmutable();

        result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
        result.setImmutable();
        return result;
    
public static com.android.dx.rop.annotation.AnnotationmakeThrows(com.android.dx.rop.type.TypeList types)
Constructs a standard {@code Throws} annotation.

param
types {@code non-null;} the list of thrown types
return
{@code non-null;} the annotation

        CstArray array = makeCstArray(types);
        Annotation result = new Annotation(THROWS_TYPE, SYSTEM);
        result.put(new NameValuePair(VALUE_STRING, array));
        result.setImmutable();
        return result;