Search in sources :

Example 6 with TypeProto

use of org.jf.dexlib2.analysis.TypeProto in project smali by JesusFreke.

the class SuperclassChainTest method testGetSuperclassChain_Unresolved.

@Test
public void testGetSuperclassChain_Unresolved() throws IOException {
    // Ltest/one; isn't defined
    ClassDef twoClassDef = TestUtils.makeClassDef("Ltest/two;", "Ltest/one;");
    ClassDef threeClassDef = TestUtils.makeClassDef("Ltest/three;", "Ltest/two;");
    ImmutableSet<ClassDef> classes = ImmutableSet.<ClassDef>of(twoClassDef, threeClassDef);
    ClassPath classPath = new ClassPath(new DexClassProvider(new ImmutableDexFile(Opcodes.getDefault(), classes)));
    TypeProto unknownClassProto = classPath.getUnknownClass();
    TypeProto oneClassProto = classPath.getClass("Ltest/one;");
    TypeProto twoClassProto = classPath.getClass("Ltest/two;");
    TypeProto threeClassProto = classPath.getClass("Ltest/three;");
    Assert.assertEquals(ImmutableList.<TypeProto>of(oneClassProto, unknownClassProto), ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(twoClassProto)));
    Assert.assertEquals(ImmutableList.<TypeProto>of(twoClassProto, oneClassProto, unknownClassProto), ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(threeClassProto)));
}
Also used : ClassPath(org.jf.dexlib2.analysis.ClassPath) ClassDef(org.jf.dexlib2.iface.ClassDef) DexClassProvider(org.jf.dexlib2.analysis.DexClassProvider) TypeProto(org.jf.dexlib2.analysis.TypeProto) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) Test(org.junit.Test)

Example 7 with TypeProto

use of org.jf.dexlib2.analysis.TypeProto in project smali by JesusFreke.

the class SuperclassChainTest method testGetSuperclassChain.

@Test
public void testGetSuperclassChain() throws IOException {
    ClassDef objectClassDef = TestUtils.makeClassDef("Ljava/lang/Object;", null);
    ClassDef oneClassDef = TestUtils.makeClassDef("Ltest/one;", "Ljava/lang/Object;");
    ClassDef twoClassDef = TestUtils.makeClassDef("Ltest/two;", "Ltest/one;");
    ClassDef threeClassDef = TestUtils.makeClassDef("Ltest/three;", "Ltest/two;");
    ImmutableSet<ClassDef> classes = ImmutableSet.<ClassDef>of(objectClassDef, oneClassDef, twoClassDef, threeClassDef);
    ClassPath classPath = new ClassPath(new DexClassProvider(new ImmutableDexFile(Opcodes.getDefault(), classes)));
    TypeProto objectClassProto = classPath.getClass("Ljava/lang/Object;");
    TypeProto oneClassProto = classPath.getClass("Ltest/one;");
    TypeProto twoClassProto = classPath.getClass("Ltest/two;");
    TypeProto threeClassProto = classPath.getClass("Ltest/three;");
    Assert.assertEquals(ImmutableList.<TypeProto>of(), ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(objectClassProto)));
    Assert.assertEquals(ImmutableList.<TypeProto>of(objectClassProto), ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(oneClassProto)));
    Assert.assertEquals(ImmutableList.<TypeProto>of(oneClassProto, objectClassProto), ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(twoClassProto)));
    Assert.assertEquals(ImmutableList.<TypeProto>of(twoClassProto, oneClassProto, objectClassProto), ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(threeClassProto)));
}
Also used : ClassPath(org.jf.dexlib2.analysis.ClassPath) ClassDef(org.jf.dexlib2.iface.ClassDef) DexClassProvider(org.jf.dexlib2.analysis.DexClassProvider) TypeProto(org.jf.dexlib2.analysis.TypeProto) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) Test(org.junit.Test)

Aggregations

ClassDef (org.jf.dexlib2.iface.ClassDef)4 TypeProto (org.jf.dexlib2.analysis.TypeProto)3 Nonnull (javax.annotation.Nonnull)2 Opcode (org.jf.dexlib2.Opcode)2 ClassPath (org.jf.dexlib2.analysis.ClassPath)2 DexClassProvider (org.jf.dexlib2.analysis.DexClassProvider)2 ImmutableDexFile (org.jf.dexlib2.immutable.ImmutableDexFile)2 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)2 ExceptionWithContext (org.jf.util.ExceptionWithContext)2 Test (org.junit.Test)2 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Matcher (java.util.regex.Matcher)1 BaseMethodReference (org.jf.dexlib2.base.reference.BaseMethodReference)1 Method (org.jf.dexlib2.iface.Method)1 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)1 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)1 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)1 ImmutableMethodParameter (org.jf.dexlib2.immutable.ImmutableMethodParameter)1 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)1