use of org.jf.smalidea.psi.impl.SmaliFile 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);
}
use of org.jf.smalidea.psi.impl.SmaliFile in project smali by JesusFreke.
the class SmaliInstructionTest method testSingleInstruction.
public void testSingleInstruction() {
String text = ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + ".method blah(IJLjava/lang/String;)V\n" + " .locals 0\n" + " r<ref>eturn-void\n" + ".end method";
SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", text.replace("<ref>", ""));
PsiElement leafElement = file.findElementAt(text.indexOf("<ref>"));
Assert.assertNotNull(leafElement);
SmaliInstruction instructionElement = (SmaliInstruction) leafElement.getParent();
Assert.assertNotNull(instructionElement);
Assert.assertEquals(Opcode.RETURN_VOID, instructionElement.getOpcode());
Assert.assertEquals(0, instructionElement.getOffset());
}
Aggregations