use of com.intellij.psi.PsiField in project android by JetBrains.
the class AndroidInlineLayoutProcessor method findUsages.
@NotNull
@Override
protected UsageInfo[] findUsages() {
if (myUsageElement != null) {
return new UsageInfo[] { new UsageInfo(myUsageElement) };
}
final Set<UsageInfo> usages = new HashSet<UsageInfo>();
AndroidInlineUtil.addReferences(myLayoutFile, usages);
for (PsiField field : AndroidResourceUtil.findResourceFieldsForFileResource(myLayoutFile, false)) {
AndroidInlineUtil.addReferences(field, usages);
}
return usages.toArray(new UsageInfo[usages.size()]);
}
use of com.intellij.psi.PsiField in project android by JetBrains.
the class AndroidResourceUtilTest method testFindResourceFieldsWithMultipleResourceNames.
public void testFindResourceFieldsWithMultipleResourceNames() {
myFixture.copyFileToProject("util/strings.xml", "res/values/strings.xml");
myFixture.copyFileToProject("R.java", "gen/p1/p2/R.java");
PsiField[] fields = AndroidResourceUtil.findResourceFields(myFacet, "string", ImmutableList.of("hello", "goodbye"), false);
Set<String> fieldNames = Sets.newHashSet();
for (PsiField field : fields) {
fieldNames.add(field.getName());
assertEquals("p2", field.getContainingFile().getContainingDirectory().getName());
}
assertEquals(ImmutableSet.of("hello", "goodbye"), fieldNames);
assertEquals(2, fields.length);
}
use of com.intellij.psi.PsiField in project android by JetBrains.
the class AndroidResourceUtilTest method testIsRJavaFileImportedNoManifest.
/** Tests that a module without an Android Manifest can still import a lib's R class */
public void testIsRJavaFileImportedNoManifest() throws Exception {
Module libModule = myAdditionalModules.get(0);
// Remove the current lib 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.
VirtualFile libRFile = 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");
// Remove the manifest from the main module.
deleteManifest(myModule);
// The main module doesn't get a generated R class and inherit fields (lack of manifest)
AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertThat(facet).isNotNull();
PsiField[] mainFields = AndroidResourceUtil.findResourceFields(facet, "string", "lib_hello", false);
assertEmpty(mainFields);
// However, if the main module happens to get a handle on the lib's R class
// (e.g., via "import p1.p2.lib.R;"), then that R class should be recognized
// (e.g., for goto navigation).
PsiManager psiManager = PsiManager.getInstance(getProject());
PsiFile libRClassFile = psiManager.findFile(libRFile);
assertNotNull(libRClassFile);
assertTrue(AndroidResourceUtil.isRJavaFile(myFacet, libRClassFile));
}
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);
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class ExtensionPointImpl method collectMissingWithTags.
@Override
public List<PsiField> collectMissingWithTags() {
PsiClass beanClass = getBeanClass().getValue();
if (beanClass == null) {
return Collections.emptyList();
}
final List<PsiField> result = new SmartList<>();
for (PsiField field : beanClass.getAllFields()) {
if (ExtensionDomExtender.isClassField(field.getName()) && ExtensionDomExtender.findWithElement(getWithElements(), field) == null) {
result.add(field);
}
}
return result;
}
Aggregations