Search in sources :

Example 21 with DexBackedClassDef

use of org.jf.dexlib2.dexbacked.DexBackedClassDef in project smali by JesusFreke.

the class ClassDefinition method writeStaticFields.

private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
    boolean wroteHeader = false;
    Set<String> writtenFields = new HashSet<String>();
    Iterable<? extends Field> staticFields;
    if (classDef instanceof DexBackedClassDef) {
        staticFields = ((DexBackedClassDef) classDef).getStaticFields(false);
    } else {
        staticFields = classDef.getStaticFields();
    }
    for (Field field : staticFields) {
        if (!wroteHeader) {
            writer.write("\n\n");
            writer.write("# static fields");
            wroteHeader = true;
        }
        writer.write('\n');
        boolean setInStaticConstructor;
        IndentingWriter fieldWriter = writer;
        String fieldString = ReferenceUtil.getShortFieldDescriptor(field);
        if (!writtenFields.add(fieldString)) {
            writer.write("# duplicate field ignored\n");
            fieldWriter = new CommentingIndentingWriter(writer);
            System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString));
            setInStaticConstructor = false;
        } else {
            setInStaticConstructor = fieldsSetInStaticConstructor.contains(fieldString);
        }
        FieldDefinition.writeTo(options, fieldWriter, field, setInStaticConstructor);
    }
    return writtenFields;
}
Also used : IndentingWriter(org.jf.util.IndentingWriter) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef)

Example 22 with DexBackedClassDef

use of org.jf.dexlib2.dexbacked.DexBackedClassDef in project android by JetBrains.

the class DexParser method getDexStats.

@NotNull
private DexFileStats getDexStats() {
    DexBackedDexFile dexFile;
    try {
        dexFile = myDexFileFuture.get();
    } catch (Exception e) {
        return new DexFileStats(-1, -1, -1);
    }
    int definedMethodCount = 0;
    Set<? extends DexBackedClassDef> classes = dexFile.getClasses();
    for (DexBackedClassDef dexBackedClassDef : classes) {
        definedMethodCount += Iterables.size(dexBackedClassDef.getMethods());
    }
    return new DexFileStats(classes.size(), definedMethodCount, dexFile.getMethodCount());
}
Also used : DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)19 IndentingWriter (org.jf.util.IndentingWriter)9 HashSet (java.util.HashSet)7 File (java.io.File)6 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)6 ClassFileNameHandler (org.jf.util.ClassFileNameHandler)4 IOException (java.io.IOException)3 DexBackedMethod (org.jf.dexlib2.dexbacked.DexBackedMethod)3 Method (org.jf.dexlib2.iface.Method)3 MethodReplaceAnnotation (com.taobao.android.apatch.annotation.MethodReplaceAnnotation)2 PatchException (com.taobao.android.differ.dex.PatchException)2 Set (java.util.Set)2 Nonnull (javax.annotation.Nonnull)2 NotNull (org.jetbrains.annotations.NotNull)2 Field (org.jf.dexlib2.iface.Field)2 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)2 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)2 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)2 DexClassNode (com.googlecode.d2j.node.DexClassNode)1 AndFixFilterImpl (com.taobao.android.apatch.AndFixFilterImpl)1