Search in sources :

Example 86 with PsiField

use of com.intellij.psi.PsiField in project android by JetBrains.

the class AndroidResourceUtilTest method testFindResourceFieldsWithInheritance.

/** Tests that "inherited" resource references are found (R fields in generated in dependent modules). */
public void testFindResourceFieldsWithInheritance() throws Exception {
    myFixture.copyFileToProject("R.java", "gen/p1/p2/R.java");
    Module libModule = myAdditionalModules.get(0);
    // Remove the current manifest (has wrong package name) and copy a manifest with proper package into the lib module.
    deleteManifest(libModule);
    myFixture.copyFileToProject("util/lib/AndroidManifest.xml", "additionalModules/lib/AndroidManifest.xml");
    // Copy an empty R class with the proper package into the lib module.
    myFixture.copyFileToProject("util/lib/R.java", "additionalModules/lib/gen/p1/p2/lib/R.java");
    // Add some lib string resources.
    myFixture.copyFileToProject("util/lib/strings.xml", "additionalModules/lib/res/values/strings.xml");
    AndroidFacet facet = AndroidFacet.getInstance(libModule);
    assertThat(facet).isNotNull();
    PsiField[] fields = AndroidResourceUtil.findResourceFields(facet, "string", "lib_hello", false);
    Set<String> dirNames = Sets.newHashSet();
    for (PsiField field : fields) {
        assertEquals("lib_hello", field.getName());
        dirNames.add(field.getContainingFile().getContainingDirectory().getName());
    }
    assertEquals(ImmutableSet.of("p2", "lib"), dirNames);
    assertEquals(2, fields.length);
}
Also used : PsiField(com.intellij.psi.PsiField) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

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