Search in sources :

Example 1 with Annotation

use of com.taobao.android.dx.rop.annotation.Annotation in project atlas by alibaba.

the class Main method dumpMethod.

/**
 * Dumps any method with the given name in the given file.
 *
 * @param dex {@code non-null;} the dex file
 * @param fqName {@code non-null;} the fully-qualified name of the
 * method(s)
 * @param out {@code non-null;} where to dump to
 */
private void dumpMethod(DexFile dex, String fqName, OutputStreamWriter out) {
    boolean wildcard = fqName.endsWith("*");
    int lastDot = fqName.lastIndexOf('.');
    if ((lastDot <= 0) || (lastDot == (fqName.length() - 1))) {
        DxConsole.err.println("bogus fully-qualified method name: " + fqName);
        return;
    }
    String className = fqName.substring(0, lastDot).replace('.', '/');
    String methodName = fqName.substring(lastDot + 1);
    ClassDefItem clazz = dex.getClassOrNull(className);
    if (clazz == null) {
        DxConsole.err.println("no such class: " + className);
        return;
    }
    if (wildcard) {
        methodName = methodName.substring(0, methodName.length() - 1);
    }
    ArrayList<EncodedMethod> allMeths = clazz.getMethods();
    TreeMap<CstNat, EncodedMethod> meths = new TreeMap<CstNat, EncodedMethod>();
    /*
         * Figure out which methods to include in the output, and get them
         * all sorted, so that the printout code is robust with respect to
         * changes in the underlying order.
         */
    for (EncodedMethod meth : allMeths) {
        String methName = meth.getName().getString();
        if ((wildcard && methName.startsWith(methodName)) || (!wildcard && methName.equals(methodName))) {
            meths.put(meth.getRef().getNat(), meth);
        }
    }
    if (meths.size() == 0) {
        DxConsole.err.println("no such method: " + fqName);
        return;
    }
    PrintWriter pw = new PrintWriter(out);
    for (EncodedMethod meth : meths.values()) {
        // TODO: Better stuff goes here, perhaps.
        meth.debugPrint(pw, args.verboseDump);
        /*
             * The (default) source file is an attribute of the class, but
             * it's useful to see it in method dumps.
             */
        CstString sourceFile = clazz.getSourceFile();
        if (sourceFile != null) {
            pw.println("  source file: " + sourceFile.toQuoted());
        }
        Annotations methodAnnotations = clazz.getMethodAnnotations(meth.getRef());
        AnnotationsList parameterAnnotations = clazz.getParameterAnnotations(meth.getRef());
        if (methodAnnotations != null) {
            pw.println("  method annotations:");
            for (Annotation a : methodAnnotations.getAnnotations()) {
                pw.println("    " + a);
            }
        }
        if (parameterAnnotations != null) {
            pw.println("  parameter annotations:");
            int sz = parameterAnnotations.size();
            for (int i = 0; i < sz; i++) {
                pw.println("    parameter " + i);
                Annotations annotations = parameterAnnotations.get(i);
                for (Annotation a : annotations.getAnnotations()) {
                    pw.println("      " + a);
                }
            }
        }
    }
    pw.flush();
}
Also used : CstNat(com.taobao.android.dx.rop.cst.CstNat) CstString(com.taobao.android.dx.rop.cst.CstString) AnnotationsList(com.taobao.android.dx.rop.annotation.AnnotationsList) CstString(com.taobao.android.dx.rop.cst.CstString) Annotation(com.taobao.android.dx.rop.annotation.Annotation) Annotations(com.taobao.android.dx.rop.annotation.Annotations) ClassDefItem(com.taobao.android.dx.dex.file.ClassDefItem) EncodedMethod(com.taobao.android.dx.dex.file.EncodedMethod)

Example 2 with Annotation

use of com.taobao.android.dx.rop.annotation.Annotation in project atlas by alibaba.

the class AttributeTranslator method getMethodAnnotations.

/**
 * Gets the annotations out of a given method, similar to {@link
 * #getAnnotations}, also including an annotation for the translation
 * of the method-specific attribute {@code Exceptions}.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getMethodAnnotations(Method method) {
    Annotations result = getAnnotations(method.getAttributes());
    TypeList exceptions = getExceptions(method);
    if (exceptions.size() != 0) {
        Annotation throwsAnnotation = AnnotationUtils.makeThrows(exceptions);
        result = Annotations.combine(result, throwsAnnotation);
    }
    return result;
}
Also used : AttRuntimeVisibleParameterAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations) AttRuntimeInvisibleParameterAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations) AttRuntimeInvisibleAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations) Annotations(com.taobao.android.dx.rop.annotation.Annotations) AttRuntimeVisibleAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeVisibleAnnotations) StdTypeList(com.taobao.android.dx.rop.type.StdTypeList) TypeList(com.taobao.android.dx.rop.type.TypeList) Annotation(com.taobao.android.dx.rop.annotation.Annotation)

Example 3 with Annotation

use of com.taobao.android.dx.rop.annotation.Annotation in project atlas by alibaba.

the class AttributeTranslator method getAnnotations.

/**
 * Gets the annotations out of a given {@link AttributeList}. This
 * combines both visible and invisible annotations into a single
 * result set and also adds in a system annotation for the
 * {@code Signature} attribute if present.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getAnnotations(AttributeList attribs) {
    Annotations result = getAnnotations0(attribs);
    Annotation signature = getSignature(attribs);
    if (signature != null) {
        result = Annotations.combine(result, signature);
    }
    return result;
}
Also used : AttRuntimeVisibleParameterAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations) AttRuntimeInvisibleParameterAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations) AttRuntimeInvisibleAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations) Annotations(com.taobao.android.dx.rop.annotation.Annotations) AttRuntimeVisibleAnnotations(com.taobao.android.dx.cf.attrib.AttRuntimeVisibleAnnotations) Annotation(com.taobao.android.dx.rop.annotation.Annotation)

Example 4 with Annotation

use of com.taobao.android.dx.rop.annotation.Annotation in project atlas by alibaba.

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

Example 5 with Annotation

use of com.taobao.android.dx.rop.annotation.Annotation in project atlas by alibaba.

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

Aggregations

Annotation (com.taobao.android.dx.rop.annotation.Annotation)16 CstAnnotation (com.taobao.android.dx.rop.cst.CstAnnotation)10 NameValuePair (com.taobao.android.dx.rop.annotation.NameValuePair)9 Annotations (com.taobao.android.dx.rop.annotation.Annotations)5 CstArray (com.taobao.android.dx.rop.cst.CstArray)4 CstString (com.taobao.android.dx.rop.cst.CstString)4 CstType (com.taobao.android.dx.rop.cst.CstType)4 AttRuntimeInvisibleAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)3 AttRuntimeInvisibleParameterAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)3 AttRuntimeVisibleAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeVisibleAnnotations)3 AttRuntimeVisibleParameterAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations)3 AttributeList (com.taobao.android.dx.cf.iface.AttributeList)2 AnnotationsList (com.taobao.android.dx.rop.annotation.AnnotationsList)2 CstNat (com.taobao.android.dx.rop.cst.CstNat)2 TypeList (com.taobao.android.dx.rop.type.TypeList)2 AttAnnotationDefault (com.taobao.android.dx.cf.attrib.AttAnnotationDefault)1 AttEnclosingMethod (com.taobao.android.dx.cf.attrib.AttEnclosingMethod)1 Method (com.taobao.android.dx.cf.iface.Method)1 MethodList (com.taobao.android.dx.cf.iface.MethodList)1 ParseException (com.taobao.android.dx.cf.iface.ParseException)1