Search in sources :

Example 6 with NameValuePair

use of com.android.dx.rop.annotation.NameValuePair in project buck by facebook.

the class ValueEncoder method writeAnnotation.

/**
     * Writes out the encoded form of the given annotation, that is,
     * as an {@code encoded_annotation} and not including a
     * {@code value_type} prefix. If the output stream keeps
     * (debugging) annotations and {@code topLevel} is
     * {@code true}, then this method will write (debugging)
     * annotations.
     *
     * @param annotation {@code non-null;} annotation instance to write
     * @param topLevel {@code true} iff the given annotation is the
     * top-level annotation or {@code false} if it is a sub-annotation
     * of some other annotation
     */
public void writeAnnotation(Annotation annotation, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    StringIdsSection stringIds = file.getStringIds();
    TypeIdsSection typeIds = file.getTypeIds();
    CstType type = annotation.getType();
    int typeIdx = typeIds.indexOf(type);
    if (annotates) {
        out.annotate("  type_idx: " + Hex.u4(typeIdx) + " // " + type.toHuman());
    }
    out.writeUleb128(typeIds.indexOf(annotation.getType()));
    Collection<NameValuePair> pairs = annotation.getNameValuePairs();
    int size = pairs.size();
    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }
    out.writeUleb128(size);
    int at = 0;
    for (NameValuePair pair : pairs) {
        CstString name = pair.getName();
        int nameIdx = stringIds.indexOf(name);
        Constant value = pair.getValue();
        if (annotates) {
            out.annotate(0, "  elements[" + at + "]:");
            at++;
            out.annotate("    name_idx: " + Hex.u4(nameIdx) + " // " + name.toHuman());
        }
        out.writeUleb128(nameIdx);
        if (annotates) {
            out.annotate("    value: " + constantToHuman(value));
        }
        writeConstant(value);
    }
    if (annotates) {
        out.endAnnotation();
    }
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstString(com.android.dx.rop.cst.CstString)

Example 7 with NameValuePair

use of com.android.dx.rop.annotation.NameValuePair in project J2ME-Loader by nikita36078.

the class AnnotationItem method annotateTo.

/**
 * Write a (listing file) annotation for this instance to the given
 * output, that consumes no bytes of output. This is for annotating
 * a reference to this instance at the point of the reference.
 *
 * @param out {@code non-null;} where to output to
 * @param prefix {@code non-null;} prefix for each line of output
 */
public void annotateTo(AnnotatedOutput out, String prefix) {
    out.annotate(0, prefix + "visibility: " + annotation.getVisibility().toHuman());
    out.annotate(0, prefix + "type: " + annotation.getType().toHuman());
    for (NameValuePair pair : annotation.getNameValuePairs()) {
        CstString name = pair.getName();
        Constant value = pair.getValue();
        out.annotate(0, prefix + name.toHuman() + ": " + ValueEncoder.constantToHuman(value));
    }
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Constant(com.android.dx.rop.cst.Constant) CstString(com.android.dx.rop.cst.CstString)

Example 8 with NameValuePair

use of com.android.dx.rop.annotation.NameValuePair in project J2ME-Loader by nikita36078.

the class AnnotationUtils method makeEnclosingClass.

/**
 * Constructs a standard {@code EnclosingClass} annotation.
 *
 * @param clazz {@code non-null;} the enclosing class
 * @return {@code non-null;} the annotation
 */
public static Annotation makeEnclosingClass(CstType clazz) {
    Annotation result = new Annotation(ENCLOSING_CLASS_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, clazz));
    result.setImmutable();
    return result;
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Example 9 with NameValuePair

use of com.android.dx.rop.annotation.NameValuePair in project J2ME-Loader by nikita36078.

the class AnnotationUtils method makeEnclosingMethod.

/**
 * Constructs a standard {@code EnclosingMethod} annotation.
 *
 * @param method {@code non-null;} the enclosing method
 * @return {@code non-null;} the annotation
 */
public static Annotation makeEnclosingMethod(CstMethodRef method) {
    Annotation result = new Annotation(ENCLOSING_METHOD_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, method));
    result.setImmutable();
    return result;
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Example 10 with NameValuePair

use of com.android.dx.rop.annotation.NameValuePair in project J2ME-Loader by nikita36078.

the class AnnotationUtils method makeMemberClasses.

/**
 * 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
 */
public static Annotation makeMemberClasses(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(MEMBER_CLASSES_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) CstArray(com.android.dx.rop.cst.CstArray) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Aggregations

NameValuePair (com.android.dx.rop.annotation.NameValuePair)29 Annotation (com.android.dx.rop.annotation.Annotation)20 CstAnnotation (com.android.dx.rop.cst.CstAnnotation)17 CstString (com.android.dx.rop.cst.CstString)10 Constant (com.android.dx.rop.cst.Constant)8 CstArray (com.android.dx.rop.cst.CstArray)6 CstType (com.android.dx.rop.cst.CstType)6 AttAnnotationDefault (com.android.dx.cf.attrib.AttAnnotationDefault)2 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)2 AttributeList (com.android.dx.cf.iface.AttributeList)2 Method (com.android.dx.cf.iface.Method)2 MethodList (com.android.dx.cf.iface.MethodList)2 TypeList (com.android.dx.rop.type.TypeList)2 ArrayList (java.util.ArrayList)2 ClassDefItem (com.android.dx.dex.file.ClassDefItem)1 Annotations (com.android.dx.rop.annotation.Annotations)1