use of org.jf.smalidea.psi.impl.SmaliClass in project smali by JesusFreke.
the class SmalideaMethodTest method testSparseSwitch.
public void testSparseSwitch() {
String text = ".class public LFormat31t;\n" + ".super Ljava/lang/Object;\n" + ".source \"Format31t.smali\"" + "\n" + ".method public test_sparse-switch()V\n" + " .registers 1\n" + " .annotation runtime Lorg/junit/Test;\n" + " .end annotation\n" + "\n" + " const v0, 13\n" + "\n" + ":switch\n" + " sparse-switch v0, :SparseSwitch\n" + "\n" + ":Label10\n" + " invoke-static {}, Lorg/junit/Assert;->fail()V\n" + " return-void\n" + "\n" + ":Label20\n" + " invoke-static {}, Lorg/junit/Assert;->fail()V\n" + " return-void\n" + "\n" + ":Label15\n" + " invoke-static {}, Lorg/junit/Assert;->fail()V\n" + " return-void\n" + "\n" + ":Label13\n" + " return-void\n" + "\n" + ":Label99\n" + " invoke-static {}, Lorg/junit/Assert;->fail()V\n" + " return-void\n" + "\n" + ":SparseSwitch\n" + " .sparse-switch\n" + " 10 -> :Label10\n" + " 13 -> :Label13\n" + " 15 -> :Label15\n" + " 20 -> :Label20\n" + " 99 -> :Label99\n" + " .end sparse-switch\n" + ".end method";
SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", text);
SmaliClass smaliClass = file.getPsiClass();
SmaliMethod smaliMethod = smaliClass.getMethods()[0];
SmalideaMethod method = new SmalideaMethod(smaliMethod);
MethodImplementation impl = method.getImplementation();
Assert.assertNotNull(impl);
List<Instruction> instructions = Lists.newArrayList(impl.getInstructions());
SparseSwitchPayload sparseSwitchPayload = (SparseSwitchPayload) instructions.get(11);
List<? extends SwitchElement> switchElements = sparseSwitchPayload.getSwitchElements();
Assert.assertEquals(5, switchElements.size());
checkSwitchElement(switchElements.get(0), 10, 6);
checkSwitchElement(switchElements.get(1), 13, 30);
checkSwitchElement(switchElements.get(2), 15, 22);
checkSwitchElement(switchElements.get(3), 20, 14);
checkSwitchElement(switchElements.get(4), 99, 32);
}
use of org.jf.smalidea.psi.impl.SmaliClass in project smali by JesusFreke.
the class SmaliClassTest method testGetSuperclass.
public void testGetSuperclass() {
myFixture.addFileToProject("base.smali", ".class public interface Lbase; .super Ljava/lang/Object;");
myFixture.addFileToProject("iface.smali", ".class public interface Liface; .super Ljava/lang/Object;");
SmaliFile file = (SmaliFile) myFixture.addFileToProject("blah.smali", ".class public Lblah; .super Lbase; .implements Liface;");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("blah", smaliClass.getQualifiedName());
PsiClass superClass = smaliClass.getSuperClass();
Assert.assertNotNull(superClass);
Assert.assertEquals("base", smaliClass.getSuperClass().getQualifiedName());
Assert.assertEquals(2, smaliClass.getSupers().length);
Assert.assertEquals("base", smaliClass.getSupers()[0].getQualifiedName());
Assert.assertEquals("iface", smaliClass.getSupers()[1].getQualifiedName());
Assert.assertEquals(2, smaliClass.getSuperTypes().length);
Assert.assertEquals("base", smaliClass.getSuperTypes()[0].getCanonicalText());
Assert.assertEquals("iface", smaliClass.getSuperTypes()[1].getCanonicalText());
Assert.assertEquals(1, smaliClass.getInterfaces().length);
Assert.assertEquals("iface", smaliClass.getInterfaces()[0].getQualifiedName());
}
use of org.jf.smalidea.psi.impl.SmaliClass in project smali by JesusFreke.
the class SmaliClassTest method testIsInheritor.
public void testIsInheritor() {
SmaliFile file = (SmaliFile) myFixture.addFileToProject("blah.smali", ".class public Lblah; .super Ljava/lang/Exception;");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("blah", smaliClass.getQualifiedName());
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiClassType throwableType = factory.createTypeByFQClassName("java.lang.Throwable", file.getResolveScope());
PsiClass throwableClass = throwableType.resolve();
Assert.assertNotNull(throwableClass);
PsiClassType exceptionType = factory.createTypeByFQClassName("java.lang.Exception", file.getResolveScope());
PsiClass exceptionClass = exceptionType.resolve();
Assert.assertNotNull(exceptionClass);
PsiClassType objectType = factory.createTypeByFQClassName("java.lang.Object", file.getResolveScope());
PsiClass objectClass = objectType.resolve();
Assert.assertNotNull(objectClass);
Assert.assertTrue(smaliClass.isInheritor(exceptionClass, true));
Assert.assertTrue(smaliClass.isInheritor(throwableClass, true));
Assert.assertTrue(smaliClass.isInheritor(objectClass, true));
Assert.assertTrue(smaliClass.isInheritorDeep(exceptionClass, null));
Assert.assertTrue(smaliClass.isInheritorDeep(throwableClass, null));
Assert.assertTrue(smaliClass.isInheritorDeep(objectClass, null));
Assert.assertTrue(smaliClass.isInheritor(exceptionClass, false));
Assert.assertFalse(smaliClass.isInheritor(throwableClass, false));
Assert.assertFalse(smaliClass.isInheritor(objectClass, false));
}
use of org.jf.smalidea.psi.impl.SmaliClass in project smali by JesusFreke.
the class SmaliClassTest method testGetSuperclassForInterface.
public void testGetSuperclassForInterface() {
myFixture.addFileToProject("iface.smali", ".class public interface Liface; .super Ljava/lang/Object;");
SmaliFile file = (SmaliFile) myFixture.addFileToProject("blah.smali", ".class public interface Lblah; .super Ljava/lang/Object; .implements Liface;");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("blah", smaliClass.getQualifiedName());
PsiClass superClass = smaliClass.getSuperClass();
Assert.assertNotNull(superClass);
Assert.assertEquals("java.lang.Object", smaliClass.getSuperClass().getQualifiedName());
Assert.assertEquals(2, smaliClass.getSupers().length);
Assert.assertEquals("java.lang.Object", smaliClass.getSupers()[0].getQualifiedName());
Assert.assertEquals("iface", smaliClass.getSupers()[1].getQualifiedName());
Assert.assertEquals(1, smaliClass.getSuperTypes().length);
Assert.assertEquals("iface", smaliClass.getSuperTypes()[0].getCanonicalText());
Assert.assertEquals(1, smaliClass.getInterfaces().length);
Assert.assertEquals("iface", smaliClass.getInterfaces()[0].getQualifiedName());
}
use of org.jf.smalidea.psi.impl.SmaliClass in project smali by JesusFreke.
the class SmaliClassTypeElementTest method testGetType.
public void testGetType() {
myFixture.addFileToProject("my/blarg.smali", ".class public Lmy/blarg; " + ".super Ljava/lang/Object;");
String text = ".class public Lmy/pkg/blah; " + ".super Lmy/bl<ref>arg;";
SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", text.replace("<ref>", ""));
SmaliClassTypeElement typeElement = (SmaliClassTypeElement) file.findReferenceAt(text.indexOf("<ref>"));
Assert.assertNotNull(typeElement);
SmaliClassType type = typeElement.getType();
Assert.assertEquals("blarg", typeElement.getName());
Assert.assertEquals("my.blarg", typeElement.getCanonicalText());
Assert.assertEquals("blarg", type.getClassName());
Assert.assertEquals("my.blarg", type.getCanonicalText());
SmaliClass resolvedClass = (SmaliClass) typeElement.resolve();
Assert.assertNotNull(resolvedClass);
Assert.assertEquals("my.blarg", resolvedClass.getQualifiedName());
resolvedClass = (SmaliClass) type.resolve();
Assert.assertNotNull(resolvedClass);
Assert.assertEquals("my.blarg", resolvedClass.getQualifiedName());
}
Aggregations