use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.
the class SmaliPositionManager method createPrepareRequest.
@Override
public ClassPrepareRequest createPrepareRequest(@NotNull final ClassPrepareRequestor requestor, @NotNull final SourcePosition position) throws NoDataException {
Computable<Boolean> isSmaliFile = new Computable<Boolean>() {
@Override
public Boolean compute() {
return position.getFile() instanceof SmaliFile;
}
};
ApplicationManager.getApplication().runReadAction(isSmaliFile);
if (!isSmaliFile.compute()) {
throw NoDataException.INSTANCE;
}
String className = getClassFromPosition(position);
return debugProcess.getRequestsManager().createClassPrepareRequest(new ClassPrepareRequestor() {
@Override
public void processClassPrepare(DebugProcess debuggerProcess, ReferenceType referenceType) {
requestor.processClassPrepare(debuggerProcess, referenceType);
}
}, className);
}
use of org.jf.smalidea.psi.impl.SmaliFile 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.SmaliFile 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.SmaliFile 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.SmaliFile 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());
}
Aggregations