Search in sources :

Example 26 with SmaliClass

use of org.jf.smalidea.psi.impl.SmaliClass 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);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass)

Example 27 with SmaliClass

use of org.jf.smalidea.psi.impl.SmaliClass 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());
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod) SmaliLiteral(org.jf.smalidea.psi.impl.SmaliLiteral)

Example 28 with SmaliClass

use of org.jf.smalidea.psi.impl.SmaliClass 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());
}
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 29 with SmaliClass

use of org.jf.smalidea.psi.impl.SmaliClass 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"));
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliModifierList(org.jf.smalidea.psi.impl.SmaliModifierList)

Example 30 with SmaliClass

use of org.jf.smalidea.psi.impl.SmaliClass 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)

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