Search in sources :

Example 6 with PsiField

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

Example 7 with PsiField

use of com.intellij.psi.PsiField in project smali by JesusFreke.

the class SmaliFieldTest method testMultipleField.

public void testMultipleField() {
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + ".field public myField:I\n" + ".field public myField2:Ljava/lang/String;\n" + ".field public myField3:[Ljava/lang/String;\n" + ".field public myField4:[[[Ljava/lang/String;\n");
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
    SmaliField[] fields = smaliClass.getFields();
    Assert.assertEquals(4, fields.length);
    Assert.assertEquals("myField", fields[0].getName());
    Assert.assertEquals("myField2", fields[1].getName());
    Assert.assertEquals("myField3", fields[2].getName());
    Assert.assertEquals("myField4", fields[3].getName());
    Assert.assertEquals("int", fields[0].getType().getCanonicalText());
    Assert.assertEquals("java.lang.String", fields[1].getType().getCanonicalText());
    Assert.assertEquals("java.lang.String[]", fields[2].getType().getCanonicalText());
    Assert.assertEquals("java.lang.String[][][]", fields[3].getType().getCanonicalText());
    PsiField field = smaliClass.findFieldByName("myField", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField", field.getName());
    field = smaliClass.findFieldByName("myField2", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField2", field.getName());
    field = smaliClass.findFieldByName("myField3", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField3", field.getName());
    field = smaliClass.findFieldByName("myField4", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField4", field.getName());
    field = smaliClass.findFieldByName("nonExistantField", true);
    Assert.assertNull(field);
    field = smaliClass.findFieldByName("nonExistantField", false);
    Assert.assertNull(field);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiField(com.intellij.psi.PsiField) SmaliField(org.jf.smalidea.psi.impl.SmaliField)

Example 8 with PsiField

use of com.intellij.psi.PsiField in project smali by JesusFreke.

the class SmaliFieldTest method testJavaSuperField.

public void testJavaSuperField() {
    myFixture.addFileToProject("my/pkg/base.java", "package my.pkg; public class base { public int baseField; }");
    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);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiField(com.intellij.psi.PsiField)

Example 9 with PsiField

use of com.intellij.psi.PsiField in project smali by JesusFreke.

the class FieldReferenceTest method testJavaReferenceFromSmali.

/**
     * Test a reference to a java field from a smali class
     */
public void testJavaReferenceFromSmali() throws Exception {
    String text = ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + ".method public blah()V\n" + "    .locals 1\n" + "    sget-object v0, Ljava/lang/System;->o<ref>ut:Ljava/io/PrintStream;\n" + "    return-void\n" + ".end method";
    SmaliFieldReference fieldReference = (SmaliFieldReference) configureByFileText(text, "blah.smali");
    Assert.assertNotNull(fieldReference);
    Assert.assertEquals("out", fieldReference.getName());
    Assert.assertNotNull(fieldReference.getFieldType());
    Assert.assertEquals("java.io.PrintStream", fieldReference.getFieldType().getType().getCanonicalText());
    PsiField resolvedField = fieldReference.resolve();
    Assert.assertNotNull(resolvedField);
    Assert.assertEquals("out", resolvedField.getName());
    Assert.assertNotNull(resolvedField.getContainingClass());
    Assert.assertEquals("java.lang.System", resolvedField.getContainingClass().getQualifiedName());
    Assert.assertEquals("java.io.PrintStream", resolvedField.getType().getCanonicalText());
}
Also used : SmaliFieldReference(org.jf.smalidea.psi.impl.SmaliFieldReference) PsiField(com.intellij.psi.PsiField)

Example 10 with PsiField

use of com.intellij.psi.PsiField in project smali by JesusFreke.

the class FieldRenameTest method doRename.

private void doRename(String containingClass, String oldFieldName, String newFieldName) throws Exception {
    PsiClass testClass = myJavaFacade.findClass(containingClass, GlobalSearchScope.allScope(getProject()));
    PsiField field = testClass.findFieldByName(oldFieldName, false);
    RenameProcessor processor = new RenameProcessor(getProject(), field, newFieldName, false, false);
    processor.run();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass)

Aggregations

PsiField (com.intellij.psi.PsiField)86 PsiClass (com.intellij.psi.PsiClass)34 PsiElement (com.intellij.psi.PsiElement)27 ArrayList (java.util.ArrayList)13 PsiMethod (com.intellij.psi.PsiMethod)11 NotNull (org.jetbrains.annotations.NotNull)11 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)8 PsiReference (com.intellij.psi.PsiReference)7 PsiType (com.intellij.psi.PsiType)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 Nullable (org.jetbrains.annotations.Nullable)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpression (com.intellij.psi.PsiExpression)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 ResourceType (com.android.resources.ResourceType)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)4 PsiFile (com.intellij.psi.PsiFile)4