Search in sources :

Example 1 with SmaliFile

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);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) ClassPrepareRequestor(com.intellij.debugger.requests.ClassPrepareRequestor) DebugProcess(com.intellij.debugger.engine.DebugProcess) Computable(com.intellij.openapi.util.Computable) ReferenceType(com.sun.jdi.ReferenceType)

Example 2 with SmaliFile

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);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) MethodImplementation(org.jf.dexlib2.iface.MethodImplementation) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod) Instruction(org.jf.dexlib2.iface.instruction.Instruction)

Example 3 with SmaliFile

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());
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiClass(com.intellij.psi.PsiClass)

Example 4 with SmaliFile

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));
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiClassType(com.intellij.psi.PsiClassType) PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiClass(com.intellij.psi.PsiClass)

Example 5 with SmaliFile

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());
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiClass(com.intellij.psi.PsiClass)

Aggregations

SmaliFile (org.jf.smalidea.psi.impl.SmaliFile)42 SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)28 PsiElement (com.intellij.psi.PsiElement)7 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)7 SmaliModifierList (org.jf.smalidea.psi.impl.SmaliModifierList)7 PsiClass (com.intellij.psi.PsiClass)5 PsiField (com.intellij.psi.PsiField)5 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)5 SmaliClassType (org.jf.smalidea.psi.impl.SmaliClassType)5 SmaliClassTypeElement (org.jf.smalidea.psi.impl.SmaliClassTypeElement)5 Instruction (org.jf.dexlib2.iface.instruction.Instruction)3 SmaliField (org.jf.smalidea.psi.impl.SmaliField)3 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)2 PsiTypeElement (com.intellij.psi.PsiTypeElement)2 SmaliAnnotation (org.jf.smalidea.psi.impl.SmaliAnnotation)2 SmaliExtendsList (org.jf.smalidea.psi.impl.SmaliExtendsList)2 SmaliImplementsList (org.jf.smalidea.psi.impl.SmaliImplementsList)2 SmaliInstruction (org.jf.smalidea.psi.impl.SmaliInstruction)2 SmaliLiteral (org.jf.smalidea.psi.impl.SmaliLiteral)2 DebugProcess (com.intellij.debugger.engine.DebugProcess)1