Search in sources :

Example 11 with SmaliClass

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

the class SmaliClassModifierListTest method testNoAnnotation.

public void testNoAnnotation() {
    final SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public final Lmy/pkg/blah;\n" + ".super Ljava/lang/Object;");
    SmaliClass smaliClass = file.getPsiClass();
    SmaliModifierList modifierList = smaliClass.getModifierList();
    // Ensures that the parent of the modifier list is a PsiModifierListOwner
    // e.g. for code like JavaSuppressionUtil.getInspectionIdsSuppressedInAnnotation,
    // which assumes the parent is a PsiModifierListOwner
    Assert.assertTrue(modifierList.getParent() instanceof PsiModifierListOwner);
    Assert.assertEquals(0, modifierList.getAnnotations().length);
    Assert.assertEquals(0, modifierList.getApplicableAnnotations().length);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) SmaliModifierList(org.jf.smalidea.psi.impl.SmaliModifierList)

Example 12 with SmaliClass

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

the class SmaliClassModifierListTest method testAllClassAccessFlags.

public void testAllClassAccessFlags() {
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public final interface abstract synthetic enum annotation Lmy/pkg/blah; " + ".super Ljava/lang/Object;");
    SmaliClass smaliClass = file.getPsiClass();
    SmaliModifierList modifierList = smaliClass.getModifierList();
    Assert.assertEquals(AccessFlags.PUBLIC.getValue() | AccessFlags.FINAL.getValue() | AccessFlags.INTERFACE.getValue() | AccessFlags.ABSTRACT.getValue() | AccessFlags.SYNTHETIC.getValue() | AccessFlags.ENUM.getValue() | AccessFlags.ANNOTATION.getValue(), modifierList.getAccessFlags());
    Assert.assertTrue(modifierList.hasModifierProperty("public"));
    Assert.assertTrue(modifierList.hasModifierProperty("final"));
    Assert.assertTrue(modifierList.hasModifierProperty("interface"));
    Assert.assertTrue(modifierList.hasModifierProperty("abstract"));
    Assert.assertTrue(modifierList.hasModifierProperty("synthetic"));
    Assert.assertTrue(modifierList.hasModifierProperty("enum"));
    Assert.assertTrue(modifierList.hasModifierProperty("annotation"));
    Assert.assertTrue(modifierList.hasExplicitModifier("public"));
    Assert.assertTrue(modifierList.hasExplicitModifier("final"));
    Assert.assertTrue(modifierList.hasExplicitModifier("interface"));
    Assert.assertTrue(modifierList.hasExplicitModifier("abstract"));
    Assert.assertTrue(modifierList.hasExplicitModifier("synthetic"));
    Assert.assertTrue(modifierList.hasExplicitModifier("enum"));
    Assert.assertTrue(modifierList.hasExplicitModifier("annotation"));
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliModifierList(org.jf.smalidea.psi.impl.SmaliModifierList)

Example 13 with SmaliClass

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

the class SmaliFieldTest method testMultipleField.

public void testMultipleField() {
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + ".field public myField:I\n" + ".field public myField2:Ljava/lang/String;\n" + ".field public myField3:[Ljava/lang/String;\n" + ".field public myField4:[[[Ljava/lang/String;\n");
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
    SmaliField[] fields = smaliClass.getFields();
    Assert.assertEquals(4, fields.length);
    Assert.assertEquals("myField", fields[0].getName());
    Assert.assertEquals("myField2", fields[1].getName());
    Assert.assertEquals("myField3", fields[2].getName());
    Assert.assertEquals("myField4", fields[3].getName());
    Assert.assertEquals("int", fields[0].getType().getCanonicalText());
    Assert.assertEquals("java.lang.String", fields[1].getType().getCanonicalText());
    Assert.assertEquals("java.lang.String[]", fields[2].getType().getCanonicalText());
    Assert.assertEquals("java.lang.String[][][]", fields[3].getType().getCanonicalText());
    PsiField field = smaliClass.findFieldByName("myField", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField", field.getName());
    field = smaliClass.findFieldByName("myField2", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField2", field.getName());
    field = smaliClass.findFieldByName("myField3", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField3", field.getName());
    field = smaliClass.findFieldByName("myField4", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField4", 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) SmaliField(org.jf.smalidea.psi.impl.SmaliField)

Example 14 with SmaliClass

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

the class SmaliFieldTest method testJavaSuperField.

public void testJavaSuperField() {
    myFixture.addFileToProject("my/pkg/base.java", "package my.pkg; public class base { public int baseField; }");
    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 15 with SmaliClass

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

the class SmaliFileTest method testFile.

public void testFile() {
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Ljava/lang/Object;");
    Assert.assertEquals(SmaliFileType.INSTANCE, file.getFileType());
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertNotNull(smaliClass);
    SmaliClass[] smaliClasses = file.getClasses();
    Assert.assertNotNull(smaliClasses);
    Assert.assertEquals(1, smaliClasses.length);
    Assert.assertEquals(smaliClass, smaliClasses[0]);
    String packageName = file.getPackageName();
    Assert.assertEquals("my.pkg", packageName);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass)

Aggregations

SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)31 SmaliFile (org.jf.smalidea.psi.impl.SmaliFile)28 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 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 SmaliClassTypeElement (org.jf.smalidea.psi.impl.SmaliClassTypeElement)2 SmaliExtendsList (org.jf.smalidea.psi.impl.SmaliExtendsList)2 SmaliImplementsList (org.jf.smalidea.psi.impl.SmaliImplementsList)2 JavaResolveResult (com.intellij.psi.JavaResolveResult)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiElementFactory (com.intellij.psi.PsiElementFactory)1 PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)1 PsiReference (com.intellij.psi.PsiReference)1