use of org.jf.smalidea.psi.impl.SmaliModifierList 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);
}
use of org.jf.smalidea.psi.impl.SmaliModifierList 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);
}
use of org.jf.smalidea.psi.impl.SmaliModifierList 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"));
}
use of org.jf.smalidea.psi.impl.SmaliModifierList in project smali by JesusFreke.
the class SmaliClassModifierListTest method testFindAnnotation.
public void testFindAnnotation() {
final SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public final Lmy/pkg/blah;\n" + ".annotation Lanno; .end annotation\n" + ".super Ljava/lang/Object;\n" + ".annotation Lmy/pkg/anno; .end annotation\n" + ".annotation Lmy/pkg/anno2; .end annotation\n" + ".annotation Lmy/pkg/anno3; .end annotation\n");
SmaliClass smaliClass = file.getPsiClass();
SmaliModifierList modifierList = smaliClass.getModifierList();
SmaliAnnotation smaliAnnotation = modifierList.findAnnotation("my.pkg.anno2");
Assert.assertNotNull(smaliAnnotation);
Assert.assertEquals("my.pkg.anno2", smaliAnnotation.getQualifiedName());
}
use of org.jf.smalidea.psi.impl.SmaliModifierList in project smali by JesusFreke.
the class SmaliClassModifierListTest method testNoClassAccessFlags.
public void testNoClassAccessFlags() {
SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class Lmy/pkg/blah; " + ".super Ljava/lang/Object;");
SmaliClass smaliClass = file.getPsiClass();
SmaliModifierList modifierList = smaliClass.getModifierList();
Assert.assertEquals(0, modifierList.getAccessFlags());
Assert.assertFalse(modifierList.hasModifierProperty("public"));
Assert.assertFalse(modifierList.hasModifierProperty("final"));
Assert.assertFalse(modifierList.hasModifierProperty("interface"));
Assert.assertFalse(modifierList.hasModifierProperty("abstract"));
Assert.assertFalse(modifierList.hasModifierProperty("synthetic"));
Assert.assertFalse(modifierList.hasModifierProperty("enum"));
Assert.assertFalse(modifierList.hasModifierProperty("annotation"));
Assert.assertFalse(modifierList.hasExplicitModifier("public"));
Assert.assertFalse(modifierList.hasExplicitModifier("final"));
Assert.assertFalse(modifierList.hasExplicitModifier("interface"));
Assert.assertFalse(modifierList.hasExplicitModifier("abstract"));
Assert.assertFalse(modifierList.hasExplicitModifier("synthetic"));
Assert.assertFalse(modifierList.hasExplicitModifier("enum"));
Assert.assertFalse(modifierList.hasExplicitModifier("annotation"));
}
Aggregations