Search in sources :

Example 11 with CstArray

use of com.android.dx.rop.cst.CstArray 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 12 with CstArray

use of com.android.dx.rop.cst.CstArray 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)

Example 13 with CstArray

use of com.android.dx.rop.cst.CstArray in project J2ME-Loader by nikita36078.

the class ClassDefItem method addContents.

/**
 * {@inheritDoc}
 */
@Override
public void addContents(DexFile file) {
    TypeIdsSection typeIds = file.getTypeIds();
    MixedItemSection byteData = file.getByteData();
    MixedItemSection wordData = file.getWordData();
    MixedItemSection typeLists = file.getTypeLists();
    StringIdsSection stringIds = file.getStringIds();
    typeIds.intern(thisClass);
    if (!classData.isEmpty()) {
        MixedItemSection classDataSection = file.getClassData();
        classDataSection.add(classData);
        CstArray staticValues = classData.getStaticValuesConstant();
        if (staticValues != null) {
            staticValuesItem = byteData.intern(new EncodedArrayItem(staticValues));
        }
    }
    if (superclass != null) {
        typeIds.intern(superclass);
    }
    if (interfaces != null) {
        interfaces = typeLists.intern(interfaces);
    }
    if (sourceFile != null) {
        stringIds.intern(sourceFile);
    }
    if (!annotationsDirectory.isEmpty()) {
        if (annotationsDirectory.isInternable()) {
            annotationsDirectory = wordData.intern(annotationsDirectory);
        } else {
            wordData.add(annotationsDirectory);
        }
    }
}
Also used : CstArray(com.android.dx.rop.cst.CstArray)

Example 14 with CstArray

use of com.android.dx.rop.cst.CstArray in project J2ME-Loader by nikita36078.

the class ValueEncoder method writeArray.

/**
 * Writes out the encoded form of the given array, that is, as
 * an {@code encoded_array} 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 array {@code non-null;} array 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 writeArray(CstArray array, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    CstArray.List list = ((CstArray) array).getList();
    int size = list.size();
    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }
    out.writeUleb128(size);
    for (int i = 0; i < size; i++) {
        Constant cst = list.get(i);
        if (annotates) {
            out.annotate("  [" + Integer.toHexString(i) + "] " + constantToHuman(cst));
        }
        writeConstant(cst);
    }
    if (annotates) {
        out.endAnnotation();
    }
}
Also used : CstArray(com.android.dx.rop.cst.CstArray) Constant(com.android.dx.rop.cst.Constant)

Aggregations

CstArray (com.android.dx.rop.cst.CstArray)14 Annotation (com.android.dx.rop.annotation.Annotation)8 CstAnnotation (com.android.dx.rop.cst.CstAnnotation)8 NameValuePair (com.android.dx.rop.annotation.NameValuePair)6 Constant (com.android.dx.rop.cst.Constant)4 CstString (com.android.dx.rop.cst.CstString)4 ArrayList (java.util.ArrayList)4 ParseException (com.android.dx.cf.iface.ParseException)2 AnnotationsList (com.android.dx.rop.annotation.AnnotationsList)2 CstDouble (com.android.dx.rop.cst.CstDouble)2 CstEnumRef (com.android.dx.rop.cst.CstEnumRef)2 CstFloat (com.android.dx.rop.cst.CstFloat)2 CstInteger (com.android.dx.rop.cst.CstInteger)2 CstLiteralBits (com.android.dx.rop.cst.CstLiteralBits)2 CstLong (com.android.dx.rop.cst.CstLong)2 CstNat (com.android.dx.rop.cst.CstNat)2 CstType (com.android.dx.rop.cst.CstType)2 Type (com.android.dx.rop.type.Type)2 TypeList (com.android.dx.rop.type.TypeList)2