use of org.jf.smalidea.psi.impl.SmaliFile 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.SmaliFile in project smali by JesusFreke.
the class SmaliFieldTest method testSmaliSuperField.
public void testSmaliSuperField() {
myFixture.addFileToProject("my/pkg/base.smali", ".class public Lmy/pkg/base; .super Ljava/lang/Object;\n" + ".field public baseField:I");
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);
}
use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.
the class SmaliAnnotationTest method testClassAnnotation.
// TODO: test default values
public void testClassAnnotation() {
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" + ".annotation runtime Lmy/TestAnnotation;\n" + " testBooleanValue = true\n" + " testStringValue = \"blah\"\n" + " testStringArrayValue = {\n" + " \"blah1\",\n" + " \"blah2\"\n" + " }\n" + ".end annotation\n" + "\n" + ".annotation runtime Lmy/TestAnnotation2;\n" + ".end annotation");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
doTest(smaliClass);
}
use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.
the class SmaliAnnotationTest method testMethodAnnotation.
public void testMethodAnnotation() {
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" + ".method public myMethod()V\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 method");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
SmaliMethod method = smaliClass.getMethods()[0];
doTest(method);
}
use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.
the class SmaliClassModifierListTest method testRemoveClassAccessFlag.
public void testRemoveClassAccessFlag() {
final SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public final Lmy/pkg/blah;\n" + ".super Ljava/lang/Object;");
myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
file.getPsiClass().getModifierList().setModifierProperty("final", false);
}
});
myFixture.checkResult(".class public Lmy/pkg/blah;\n" + ".super Ljava/lang/Object;");
}
Aggregations