Search in sources :

Example 11 with SmaliFile

use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.

the class SmaliFieldTest method testBasicField.

public void testBasicField() {
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + ".field public myField:I");
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
    SmaliField[] fields = smaliClass.getFields();
    Assert.assertEquals(1, fields.length);
    Assert.assertEquals("myField", fields[0].getName());
    Assert.assertTrue(fields[0].getType() instanceof PsiPrimitiveType);
    Assert.assertEquals("int", fields[0].getType().getCanonicalText());
    PsiTypeElement typeElement = fields[0].getTypeElement();
    Assert.assertNotNull("I", typeElement);
    Assert.assertEquals("I", typeElement.getText());
    SmaliModifierList modifierList = fields[0].getModifierList();
    Assert.assertNotNull(modifierList);
    Assert.assertEquals(AccessFlags.PUBLIC.getValue(), modifierList.getAccessFlags());
    Assert.assertTrue(modifierList.hasExplicitModifier("public"));
    Assert.assertTrue(modifierList.hasModifierProperty("public"));
    Assert.assertTrue(fields[0].hasModifierProperty("public"));
    PsiField[] psifields = smaliClass.getAllFields();
    Assert.assertEquals(1, psifields.length);
    Assert.assertEquals("myField", psifields[0].getName());
    PsiField field = smaliClass.findFieldByName("myField", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField", field.getName());
    field = smaliClass.findFieldByName("nonExistantField", true);
    Assert.assertNull(field);
    field = smaliClass.findFieldByName("nonExistantField", false);
    Assert.assertNull(field);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiTypeElement(com.intellij.psi.PsiTypeElement) PsiField(com.intellij.psi.PsiField) SmaliField(org.jf.smalidea.psi.impl.SmaliField) SmaliModifierList(org.jf.smalidea.psi.impl.SmaliModifierList)

Example 12 with SmaliFile

use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.

the class SmaliFieldTest method testSmaliSuperField.

public void testSmaliSuperField() {
    myFixture.addFileToProject("my/pkg/base.smali", ".class public Lmy/pkg/base; .super Ljava/lang/Object;\n" + ".field public baseField:I");
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Lmy/pkg/base;\n" + ".field public myField:I");
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
    PsiField[] fields = smaliClass.getFields();
    Assert.assertEquals(1, fields.length);
    Assert.assertEquals("myField", fields[0].getName());
    fields = smaliClass.getAllFields();
    Assert.assertEquals(2, fields.length);
    Assert.assertTrue(fields[0].getName().equals("myField") || fields[1].getName().equals("myField"));
    Assert.assertTrue(fields[0].getName().equals("baseField") || fields[1].getName().equals("baseField"));
    PsiField field = smaliClass.findFieldByName("myField", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField", field.getName());
    field = smaliClass.findFieldByName("myField", false);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField", field.getName());
    field = smaliClass.findFieldByName("baseField", false);
    Assert.assertNull(field);
    field = smaliClass.findFieldByName("baseField", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("baseField", field.getName());
    field = smaliClass.findFieldByName("nonExistantField", true);
    Assert.assertNull(field);
    field = smaliClass.findFieldByName("nonExistantField", false);
    Assert.assertNull(field);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiField(com.intellij.psi.PsiField)

Example 13 with SmaliFile

use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.

the class SmaliAnnotationTest method testClassAnnotation.

// TODO: test default values
public void testClassAnnotation() {
    myFixture.addFileToProject("my/TestAnnotation.smali", ".class public interface abstract annotation Lmy/TestAnnotation;\n" + ".super Ljava/lang/Object;\n" + ".implements Ljava/lang/annotation/Annotation;\n" + "\n" + ".method public abstract testBooleanValue()Z\n" + ".end method\n" + "\n" + ".method public abstract testStringArrayValue()[Ljava/lang/String;\n" + ".end method\n" + "\n" + ".method public abstract testStringValue()Ljava/lang/String;\n" + ".end method");
    myFixture.addFileToProject("my/TestAnnotation2.smali", ".class public interface abstract annotation Lmy/TestAnnotation2;\n" + ".super Ljava/lang/Object;\n" + ".implements Ljava/lang/annotation/Annotation;\n");
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + "\n" + ".annotation runtime Lmy/TestAnnotation;\n" + "    testBooleanValue = true\n" + "    testStringValue = \"blah\"\n" + "    testStringArrayValue = {\n" + "        \"blah1\",\n" + "        \"blah2\"\n" + "    }\n" + ".end annotation\n" + "\n" + ".annotation runtime Lmy/TestAnnotation2;\n" + ".end annotation");
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
    doTest(smaliClass);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass)

Example 14 with SmaliFile

use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.

the class SmaliAnnotationTest method testMethodAnnotation.

public void testMethodAnnotation() {
    myFixture.addFileToProject("my/TestAnnotation.smali", ".class public interface abstract annotation Lmy/TestAnnotation;\n" + ".super Ljava/lang/Object;\n" + ".implements Ljava/lang/annotation/Annotation;\n" + "\n" + ".method public abstract testBooleanValue()Z\n" + ".end method\n" + "\n" + ".method public abstract testStringArrayValue()[Ljava/lang/String;\n" + ".end method\n" + "\n" + ".method public abstract testStringValue()Ljava/lang/String;\n" + ".end method");
    myFixture.addFileToProject("my/TestAnnotation2.smali", ".class public interface abstract annotation Lmy/TestAnnotation2;\n" + ".super Ljava/lang/Object;\n" + ".implements Ljava/lang/annotation/Annotation;\n");
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + "\n" + ".method public myMethod()V\n" + "    .annotation runtime Lmy/TestAnnotation;\n" + "        testBooleanValue = true\n" + "        testStringValue = \"blah\"\n" + "        testStringArrayValue = {\n" + "            \"blah1\",\n" + "            \"blah2\"\n" + "        }\n" + "    .end annotation\n" + "    .annotation runtime Lmy/TestAnnotation2;\n" + "    .end annotation\n" + ".end method");
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
    SmaliMethod method = smaliClass.getMethods()[0];
    doTest(method);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod)

Example 15 with SmaliFile

use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.

the class SmaliClassModifierListTest method testRemoveClassAccessFlag.

public void testRemoveClassAccessFlag() {
    final SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public final Lmy/pkg/blah;\n" + ".super Ljava/lang/Object;");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            file.getPsiClass().getModifierList().setModifierProperty("final", false);
        }
    });
    myFixture.checkResult(".class public Lmy/pkg/blah;\n" + ".super Ljava/lang/Object;");
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile)

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