Search in sources :

Example 31 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

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.taobao.android.dx.rop.annotation.NameValuePair) CstType(com.taobao.android.dx.rop.cst.CstType) CstString(com.taobao.android.dx.rop.cst.CstString) Annotation(com.taobao.android.dx.rop.annotation.Annotation) CstAnnotation(com.taobao.android.dx.rop.cst.CstAnnotation)

Example 32 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class AnnotationParser method parseConstant.

/**
     * Helper for {@link #parseValue}, which parses a constant reference
     * and returns the referred-to constant value.
     *
     * @return {@code non-null;} the parsed value
     */
private Constant parseConstant() throws IOException {
    int constValueIndex = input.readUnsignedShort();
    Constant value = (Constant) pool.get(constValueIndex);
    if (observer != null) {
        String human = (value instanceof CstString) ? ((CstString) value).toQuoted() : value.toHuman();
        parsed(2, "constant_value: " + human);
    }
    return value;
}
Also used : Constant(com.taobao.android.dx.rop.cst.Constant) CstString(com.taobao.android.dx.rop.cst.CstString) CstString(com.taobao.android.dx.rop.cst.CstString)

Example 33 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class AnnotationParser method parseValue.

/**
     * Parses an annotation value.
     *
     * @return {@code non-null;} the parsed value
     */
private Constant parseValue() throws IOException {
    int tag = input.readUnsignedByte();
    if (observer != null) {
        CstString humanTag = new CstString(Character.toString((char) tag));
        parsed(1, "tag: " + humanTag.toQuoted());
    }
    switch(tag) {
        case 'B':
            {
                CstInteger value = (CstInteger) parseConstant();
                return CstByte.make(value.getValue());
            }
        case 'C':
            {
                CstInteger value = (CstInteger) parseConstant();
                int intValue = value.getValue();
                return CstChar.make(value.getValue());
            }
        case 'D':
            {
                CstDouble value = (CstDouble) parseConstant();
                return value;
            }
        case 'F':
            {
                CstFloat value = (CstFloat) parseConstant();
                return value;
            }
        case 'I':
            {
                CstInteger value = (CstInteger) parseConstant();
                return value;
            }
        case 'J':
            {
                CstLong value = (CstLong) parseConstant();
                return value;
            }
        case 'S':
            {
                CstInteger value = (CstInteger) parseConstant();
                return CstShort.make(value.getValue());
            }
        case 'Z':
            {
                CstInteger value = (CstInteger) parseConstant();
                return CstBoolean.make(value.getValue());
            }
        case 'c':
            {
                int classInfoIndex = input.readUnsignedShort();
                CstString value = (CstString) pool.get(classInfoIndex);
                Type type = Type.internReturnType(value.getString());
                if (observer != null) {
                    parsed(2, "class_info: " + type.toHuman());
                }
                return new CstType(type);
            }
        case 's':
            {
                return parseConstant();
            }
        case 'e':
            {
                requireLength(4);
                int typeNameIndex = input.readUnsignedShort();
                int constNameIndex = input.readUnsignedShort();
                CstString typeName = (CstString) pool.get(typeNameIndex);
                CstString constName = (CstString) pool.get(constNameIndex);
                if (observer != null) {
                    parsed(2, "type_name: " + typeName.toHuman());
                    parsed(2, "const_name: " + constName.toHuman());
                }
                return new CstEnumRef(new CstNat(constName, typeName));
            }
        case '@':
            {
                Annotation annotation = parseAnnotation(AnnotationVisibility.EMBEDDED);
                return new CstAnnotation(annotation);
            }
        case '[':
            {
                requireLength(2);
                int numValues = input.readUnsignedShort();
                CstArray.List list = new CstArray.List(numValues);
                if (observer != null) {
                    parsed(2, "num_values: " + numValues);
                    changeIndent(1);
                }
                for (int i = 0; i < numValues; i++) {
                    if (observer != null) {
                        changeIndent(-1);
                        parsed(0, "element_value[" + i + "]:");
                        changeIndent(1);
                    }
                    list.set(i, parseValue());
                }
                if (observer != null) {
                    changeIndent(-1);
                }
                list.setImmutable();
                return new CstArray(list);
            }
        default:
            {
                throw new ParseException("unknown annotation tag: " + Hex.u1(tag));
            }
    }
}
Also used : CstFloat(com.taobao.android.dx.rop.cst.CstFloat) CstNat(com.taobao.android.dx.rop.cst.CstNat) CstArray(com.taobao.android.dx.rop.cst.CstArray) CstLong(com.taobao.android.dx.rop.cst.CstLong) CstString(com.taobao.android.dx.rop.cst.CstString) CstAnnotation(com.taobao.android.dx.rop.cst.CstAnnotation) CstDouble(com.taobao.android.dx.rop.cst.CstDouble) CstEnumRef(com.taobao.android.dx.rop.cst.CstEnumRef) Annotation(com.taobao.android.dx.rop.annotation.Annotation) CstAnnotation(com.taobao.android.dx.rop.cst.CstAnnotation) CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) CstInteger(com.taobao.android.dx.rop.cst.CstInteger) CstType(com.taobao.android.dx.rop.cst.CstType) AnnotationsList(com.taobao.android.dx.rop.annotation.AnnotationsList) ParseException(com.taobao.android.dx.cf.iface.ParseException)

Aggregations

CstString (com.taobao.android.dx.rop.cst.CstString)33 CstType (com.taobao.android.dx.rop.cst.CstType)14 Constant (com.taobao.android.dx.rop.cst.Constant)12 ConstantPool (com.taobao.android.dx.rop.cst.ConstantPool)6 ByteArray (com.taobao.android.dx.util.ByteArray)6 NameValuePair (com.taobao.android.dx.rop.annotation.NameValuePair)5 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)5 Annotation (com.taobao.android.dx.rop.annotation.Annotation)4 CstFieldRef (com.taobao.android.dx.rop.cst.CstFieldRef)4 CstNat (com.taobao.android.dx.rop.cst.CstNat)4 Type (com.taobao.android.dx.rop.type.Type)4 ParseException (com.taobao.android.dx.cf.iface.ParseException)3 ClassDefItem (com.taobao.android.dx.dex.file.ClassDefItem)3 CstAnnotation (com.taobao.android.dx.rop.cst.CstAnnotation)3 Attribute (com.taobao.android.dx.cf.iface.Attribute)2 CstInsn (com.taobao.android.dx.dex.code.CstInsn)2 Annotations (com.taobao.android.dx.rop.annotation.Annotations)2 AnnotationsList (com.taobao.android.dx.rop.annotation.AnnotationsList)2 LocalItem (com.taobao.android.dx.rop.code.LocalItem)2 RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)2