use of org.jf.dexlib2.iface.DexFile in project smali by JesusFreke.
the class DexWriterTest method testAnnotationElementOrder.
@Test
public void testAnnotationElementOrder() {
// Elements are out of order wrt to the element name
ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE));
ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements);
ImmutableClassDef classDef = new ImmutableClassDef("Lorg/test/blah;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null);
MemoryDataStore dataStore = new MemoryDataStore();
try {
DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef)));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getData());
ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null);
Assert.assertNotNull(dbClassDef);
Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null);
Assert.assertNotNull(dbAnnotation);
List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotation.getElements());
// Ensure that the elements were written out in sorted order
Assert.assertEquals(2, dbElements.size());
Assert.assertEquals("blah", dbElements.get(0).getName());
Assert.assertEquals("zabaglione", dbElements.get(1).getName());
}
use of org.jf.dexlib2.iface.DexFile 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());
}
use of org.jf.dexlib2.iface.DexFile in project android by JetBrains.
the class DexParserTest method simpleMethodReferenceTree.
@Test
public void simpleMethodReferenceTree() throws IOException {
DexBackedDexFile dexFile = getTestDexFile();
PackageTreeNode packageTreeNode = DexParser.constructMethodRefTreeForDex(dexFile);
StringBuffer sb = new StringBuffer(100);
dumpTree(sb, packageTreeNode, 0);
assertEquals("root: 3,6\n" + " Test: 3,3\n" + " void <init>(): 1,1\n" + " java.lang.Integer get(): 1,1\n" + " java.util.List getList(): 1,1\n" + " java: 0,3\n" + " lang: 0,2\n" + " Integer: 0,1\n" + " java.lang.Integer valueOf(int): 0,1\n" + " Object: 0,1\n" + " void <init>(): 0,1\n" + " util: 0,1\n" + " Collections: 0,1\n" + " java.util.List emptyList(): 0,1\n", sb.toString());
assertEquals(6, dexFile.getMethodCount());
}
Aggregations