Search in sources :

Example 1 with SmaliLiteral

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

the class SmaliLiteralTest method doTest.

private void doTest(long expectedValue, String literalValue) {
    String text = ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + ".method blah()V\n" + "    .registers <ref>" + literalValue + "\n" + "    return-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);
    SmaliLiteral literalElement = (SmaliLiteral) leafElement.getParent();
    Assert.assertNotNull(literalElement);
    Assert.assertEquals(expectedValue, literalElement.getIntegralValue());
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliLiteral(org.jf.smalidea.psi.impl.SmaliLiteral) PsiElement(com.intellij.psi.PsiElement)

Example 2 with SmaliLiteral

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

Aggregations

SmaliFile (org.jf.smalidea.psi.impl.SmaliFile)2 SmaliLiteral (org.jf.smalidea.psi.impl.SmaliLiteral)2 PsiElement (com.intellij.psi.PsiElement)1 SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)1 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)1