Search in sources :

Example 21 with NameValuePair

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

the class AnnotationParser method parseElement.

/**
 * Parses a {@link NameValuePair}.
 *
 * @return {@code non-null;} the parsed element
 */
private NameValuePair parseElement() throws IOException {
    requireLength(5);
    int elementNameIndex = input.readUnsignedShort();
    CstString elementName = (CstString) pool.get(elementNameIndex);
    if (observer != null) {
        parsed(2, "element_name: " + elementName.toHuman());
        parsed(0, "value: ");
        changeIndent(1);
    }
    Constant value = parseValue();
    if (observer != null) {
        changeIndent(-1);
    }
    return new NameValuePair(elementName, 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 22 with NameValuePair

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

the class AnnotationParser method parseAnnotation.

/**
 * Parses a single annotation.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotation
 * @return {@code non-null;} the parsed annotation
 */
private Annotation parseAnnotation(AnnotationVisibility visibility) throws IOException {
    requireLength(4);
    int typeIndex = input.readUnsignedShort();
    int numElements = input.readUnsignedShort();
    CstString typeString = (CstString) pool.get(typeIndex);
    CstType type = new CstType(Type.intern(typeString.getString()));
    if (observer != null) {
        parsed(2, "type: " + type.toHuman());
        parsed(2, "num_elements: " + numElements);
    }
    Annotation annotation = new Annotation(type, visibility);
    for (int i = 0; i < numElements; i++) {
        if (observer != null) {
            parsed(0, "elements[" + i + "]:");
            changeIndent(1);
        }
        NameValuePair element = parseElement();
        annotation.add(element);
        if (observer != null) {
            changeIndent(-1);
        }
    }
    annotation.setImmutable();
    return annotation;
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) CstType(com.android.dx.rop.cst.CstType) CstString(com.android.dx.rop.cst.CstString) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Example 23 with NameValuePair

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

the class AttributeTranslator method translateAnnotationDefaults.

/**
 * Gets the {@code AnnotationDefault} attributes out of a
 * given class, if any, reforming them as an
 * {@code AnnotationDefault} annotation.
 *
 * @param cf {@code non-null;} the class in question
 * @return {@code null-ok;} an appropriately-constructed
 * {@code AnnotationDefault} annotation, if there were any
 * annotation defaults in the class, or {@code null} if not
 */
private static Annotation translateAnnotationDefaults(DirectClassFile cf) {
    CstType thisClass = cf.getThisClass();
    MethodList methods = cf.getMethods();
    int sz = methods.size();
    Annotation result = new Annotation(thisClass, AnnotationVisibility.EMBEDDED);
    boolean any = false;
    for (int i = 0; i < sz; i++) {
        Method one = methods.get(i);
        AttributeList attribs = one.getAttributes();
        AttAnnotationDefault oneDefault = (AttAnnotationDefault) attribs.findFirst(AttAnnotationDefault.ATTRIBUTE_NAME);
        if (oneDefault != null) {
            NameValuePair pair = new NameValuePair(one.getNat().getName(), oneDefault.getValue());
            result.add(pair);
            any = true;
        }
    }
    if (!any) {
        return null;
    }
    result.setImmutable();
    return AnnotationUtils.makeAnnotationDefault(result);
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) AttributeList(com.android.dx.cf.iface.AttributeList) CstType(com.android.dx.rop.cst.CstType) MethodList(com.android.dx.cf.iface.MethodList) AttEnclosingMethod(com.android.dx.cf.attrib.AttEnclosingMethod) Method(com.android.dx.cf.iface.Method) Annotation(com.android.dx.rop.annotation.Annotation) AttAnnotationDefault(com.android.dx.cf.attrib.AttAnnotationDefault)

Example 24 with NameValuePair

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

the class AnnotationUtils method makeSignature.

/**
 * Constructs a standard {@code Signature} annotation.
 *
 * @param signature {@code non-null;} the signature string
 * @return {@code non-null;} the annotation
 */
public static Annotation makeSignature(CstString signature) {
    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;
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) CstArray(com.android.dx.rop.cst.CstArray) ArrayList(java.util.ArrayList) CstString(com.android.dx.rop.cst.CstString) ArrayList(java.util.ArrayList) TypeList(com.android.dx.rop.type.TypeList) CstString(com.android.dx.rop.cst.CstString) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Example 25 with NameValuePair

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

the class AnnotationUtils method makeThrows.

/**
 * Constructs a standard {@code Throws} annotation.
 *
 * @param types {@code non-null;} the list of thrown types
 * @return {@code non-null;} the annotation
 */
public static Annotation makeThrows(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(THROWS_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