Search in sources :

Example 6 with SmaliModifierList

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

the class SmaliClassModifierListTest method testBasicAnnotation.

public void testBasicAnnotation() {
    final SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public final Lmy/pkg/blah;\n" + ".super Ljava/lang/Object;\n" + ".annotation Lmy/pkg/anno; .end annotation");
    SmaliClass smaliClass = file.getPsiClass();
    SmaliModifierList modifierList = smaliClass.getModifierList();
    SmaliAnnotation[] annotations = modifierList.getAnnotations();
    Assert.assertEquals(1, annotations.length);
    Assert.assertEquals("my.pkg.anno", annotations[0].getQualifiedName());
    SmaliAnnotation[] applicableAnnotations = modifierList.getApplicableAnnotations();
    Assert.assertEquals(1, applicableAnnotations.length);
    Assert.assertEquals(annotations[0], applicableAnnotations[0]);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliAnnotation(org.jf.smalidea.psi.impl.SmaliAnnotation) SmaliModifierList(org.jf.smalidea.psi.impl.SmaliModifierList)

Example 7 with SmaliModifierList

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

the class SmaliFieldTest method testFieldAnnotations.

public void testFieldAnnotations() {
    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)

Aggregations

SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)7 SmaliFile (org.jf.smalidea.psi.impl.SmaliFile)7 SmaliModifierList (org.jf.smalidea.psi.impl.SmaliModifierList)7 PsiField (com.intellij.psi.PsiField)2 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)2 PsiTypeElement (com.intellij.psi.PsiTypeElement)2 SmaliAnnotation (org.jf.smalidea.psi.impl.SmaliAnnotation)2 SmaliField (org.jf.smalidea.psi.impl.SmaliField)2 PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)1