use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.
the class SmaliAnnotationTest method testFieldAnnotation.
public void testFieldAnnotation() {
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" + ".field public myField:I\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 field");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
PsiField field = smaliClass.findFieldByName("myField", false);
doTest((PsiAnnotationOwner) field);
}
use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.
the class SmaliAnnotationTest method testDefaultValue.
public void testDefaultValue() {
SmaliFile file = (SmaliFile) myFixture.addFileToProject("AnnotationWithDefaultValue.smali", "" + ".class public abstract interface annotation LAnnotationWithValues;\n" + ".super Ljava/lang/Object;\n" + ".implements Ljava/lang/annotation/Annotation;\n" + "\n" + ".method public abstract intValue()I\n" + ".end method\n" + "\n" + ".annotation system Ldalvik/annotation/AnnotationDefault;\n" + " value = .subannotation LAnnotationWithValues;\n" + " intValue = 4\n" + " .end subannotation\n" + ".end annotation\n" + "\n");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertNotNull(smaliClass);
SmaliMethod method = smaliClass.getMethods()[0];
Assert.assertEquals("intValue", method.getName());
PsiAnnotationMemberValue defaultValue = method.getDefaultValue();
Assert.assertTrue(defaultValue instanceof SmaliLiteral);
Assert.assertEquals(4, ((SmaliLiteral) defaultValue).getIntegralValue());
}
use of org.jf.smalidea.psi.impl.SmaliFile 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.SmaliFile 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"));
}
use of org.jf.smalidea.psi.impl.SmaliFile 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]);
}
Aggregations