use of com.intellij.psi.PsiManager in project android by JetBrains.
the class ProjectResourceRepositoryTest method testDependencies.
// Regression test for https://code.google.com/p/android/issues/detail?id=65140
public void testDependencies() throws Exception {
myFixture.copyFileToProject(LAYOUT, "res/layout/layout1.xml");
Module lib1 = null;
Module lib2 = null;
Module sharedLib = null;
Module app = null;
for (Module module : ModuleManager.getInstance(getProject()).getModules()) {
if (module != myModule) {
VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
assertEquals(1, contentRoots.length);
String name = contentRoots[0].getName();
switch(name) {
case "lib1":
lib1 = module;
break;
case "lib2":
lib2 = module;
break;
case "sharedlib":
sharedLib = module;
break;
case "app":
app = module;
break;
default:
fail(name);
break;
}
}
}
assertNotNull(lib1);
assertNotNull(lib2);
assertNotNull(sharedLib);
assertNotNull(app);
renameModule(lib1, "lib1");
renameModule(lib2, "lib2");
renameModule(sharedLib, "sharedLib");
renameModule(app, "app");
AndroidFacet lib1Facet = AndroidFacet.getInstance(lib1);
AndroidFacet lib2Facet = AndroidFacet.getInstance(lib2);
AndroidFacet sharedLibFacet = AndroidFacet.getInstance(sharedLib);
AndroidFacet appFacet = AndroidFacet.getInstance(app);
assertNotNull(lib1Facet);
assertNotNull(lib2Facet);
assertNotNull(sharedLibFacet);
assertNotNull(appFacet);
// Set up project dependencies
addModuleDependency(lib1, sharedLib);
addModuleDependency(lib2, sharedLib);
addModuleDependency(app, lib1);
addModuleDependency(app, lib2);
assertTrue(ModuleRootManager.getInstance(app).isDependsOn(lib1));
assertTrue(ModuleRootManager.getInstance(lib1).isDependsOn(sharedLib));
assertFalse(ModuleRootManager.getInstance(sharedLib).isDependsOn(lib1));
assertFalse(ModuleRootManager.getInstance(lib2).isDependsOn(lib1));
// Note that these are currently direct dependencies only, so app.isDependsOn(sharedLib) is false
// Test AndroidUtils#getallAndroidDependencies
List<AndroidFacet> appDependsOn = AndroidUtils.getAllAndroidDependencies(app, true);
assertTrue(appDependsOn.contains(lib1Facet));
assertTrue(appDependsOn.contains(lib2Facet));
assertTrue(appDependsOn.contains(sharedLibFacet));
assertFalse(appDependsOn.contains(appFacet));
List<AndroidFacet> lib1DependsOn = AndroidUtils.getAllAndroidDependencies(lib1, true);
assertTrue(lib1DependsOn.contains(sharedLibFacet));
assertFalse(lib1DependsOn.contains(appFacet));
assertFalse(lib1DependsOn.contains(lib1Facet));
assertFalse(lib1DependsOn.contains(lib2Facet));
// Set up resources so we can check which values are inherited through module dependencies
VirtualFile v1 = myFixture.copyFileToProject(VALUES, "additionalModules/sharedlib/res/values/sharedvalues.xml");
VirtualFile v2 = myFixture.copyFileToProject(VALUES_OVERLAY1, "additionalModules/lib2/res/values/lib2values.xml");
assertNotNull(v1);
assertNotNull(v2);
PsiManager manager = PsiManager.getInstance(getProject());
PsiFile sharedLibValues = manager.findFile(v1);
PsiFile lib2Values = manager.findFile(v2);
assertNotNull(sharedLibValues);
assertNotNull(lib2Values);
final AppResourceRepository lib1Resources = lib1Facet.getAppResources(true);
final AppResourceRepository lib2Resources = lib2Facet.getAppResources(true);
assertNotNull(lib1Resources);
assertNotNull(lib2Resources);
assertNotSame(lib1Resources, lib2Resources);
assertFalse(lib1Resources.isScanPending(sharedLibValues));
assertFalse(lib1Resources.isScanPending(lib2Values));
assertFalse(lib2Resources.isScanPending(sharedLibValues));
assertFalse(lib2Resources.isScanPending(lib2Values));
assertTrue(lib1Resources.hasResourceItem(ResourceType.PLURALS, "my_plural"));
assertTrue(lib1Resources.hasResourceItem(ResourceType.STRING, "ellipsis"));
assertTrue(lib1Resources.hasResourceItem(ResourceType.ARRAY, "security_questions"));
List<ResourceItem> items = lib1Resources.getResourceItem(ResourceType.STRING, "ellipsis");
assertNotNull(items);
ResourceValue firstValue = items.get(0).getResourceValue(false);
assertNotNull(firstValue);
assertEquals("Here it is: …!", firstValue.getValue());
assertTrue(lib2Resources.hasResourceItem(ResourceType.ARRAY, "security_questions"));
assertTrue(lib2Resources.hasResourceItem(ResourceType.PLURALS, "my_plural"));
assertTrue(lib2Resources.hasResourceItem(ResourceType.STRING, "ellipsis"));
// ONLY defined in lib2: should not be visible from lib1
assertTrue(lib2Resources.hasResourceItem(ResourceType.STRING, "unique_string"));
items = lib2Resources.getResourceItem(ResourceType.STRING, "unique_string");
assertNotNull(items);
firstValue = items.get(0).getResourceValue(false);
assertNotNull(firstValue);
assertEquals("Unique", firstValue.getValue());
assertFalse(lib1Resources.hasResourceItem(ResourceType.STRING, "unique_string"));
}
use of com.intellij.psi.PsiManager in project intellij-plugins by JetBrains.
the class FlexXmlBackedClassesIndex method searchClassInheritors.
public static Collection<JSClass> searchClassInheritors(ID<String, Void> indexId, String name, Project project, final GlobalSearchScope scope) {
final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(indexId, name, scope);
final PsiManager psiManager = PsiManager.getInstance(project);
Collection<JSClass> classes = new ArrayList<>(files.size());
for (VirtualFile file : files) {
PsiFile psifile = psiManager.findFile(file);
if (!(psifile instanceof XmlFile))
continue;
classes.addAll(XmlBackedJSClassImpl.getClasses((XmlFile) psifile));
}
if (FlexNameAlias.CONTAINER_TYPE_NAME.equals(name)) {
classes.addAll(searchClassInheritors(indexId, FlexNameAlias.COMPONENT_TYPE_NAME, project, scope));
}
return classes;
}
use of com.intellij.psi.PsiManager in project intellij-plugins by JetBrains.
the class SocketInputHandlerImpl method getResourceBundleFromModuleSource.
private static PropertiesFile getResourceBundleFromModuleSource(Module module, final String bundleName) {
final AccessToken token = ReadAction.start();
try {
final PsiManager psiManager = PsiManager.getInstance(module.getProject());
final List<VirtualFile> result = new ArrayList<>();
FileTypeIndex.processFiles(PropertiesFileType.INSTANCE, file -> {
if (file.getNameWithoutExtension().equals(bundleName)) {
result.add(file);
if (file.getParent().getName().equals("en_US")) {
return false;
}
}
return true;
}, module.getModuleScope(false));
PropertiesFile defaultResourceBundle = null;
for (VirtualFile file : result) {
PsiFile psiFile = psiManager.findFile(file);
if (psiFile != null) {
if (file.getParent().getName().equals("en_US")) {
defaultResourceBundle = (PropertiesFile) psiFile;
} else {
return (PropertiesFile) psiFile;
}
}
}
return defaultResourceBundle;
} finally {
token.finish();
}
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class EmptyDirectoryInspection method runInspection.
@Override
public void runInspection(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager, @NotNull final GlobalInspectionContext context, @NotNull final ProblemDescriptionsProcessor processor) {
final Project project = context.getProject();
final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
final SearchScope searchScope = scope.toSearchScope();
if (!(searchScope instanceof GlobalSearchScope)) {
return;
}
final GlobalSearchScope globalSearchScope = (GlobalSearchScope) searchScope;
final PsiManager psiManager = PsiManager.getInstance(project);
index.iterateContent(fileOrDir -> {
if (!fileOrDir.isDirectory()) {
return true;
}
if (!globalSearchScope.contains(fileOrDir)) {
return true;
}
if (onlyReportDirectoriesUnderSourceRoots && !index.isInSourceContent(fileOrDir)) {
return true;
}
final VirtualFile[] children = fileOrDir.getChildren();
if (children.length != 0) {
return true;
}
final PsiDirectory directory = ReadAction.compute(() -> psiManager.findDirectory(fileOrDir));
final RefElement refDirectory = context.getRefManager().getReference(directory);
if (refDirectory == null || context.shouldCheck(refDirectory, this)) {
return true;
}
final String relativePath = getPathRelativeToModule(fileOrDir, project);
if (relativePath == null) {
return true;
}
processor.addProblemElement(refDirectory, manager.createProblemDescriptor(InspectionGadgetsBundle.message("empty.directories.problem.descriptor", relativePath), new EmptyPackageFix(fileOrDir.getUrl(), fileOrDir.getName())));
return true;
});
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class AntPathConverter method fromString.
@Override
public PsiFileSystemItem fromString(@Nullable @NonNls String s, ConvertContext context) {
final GenericAttributeValue attribValue = context.getInvocationElement().getParentOfType(GenericAttributeValue.class, false);
if (attribValue == null) {
return null;
}
String path = attribValue.getStringValue();
if (path == null) {
path = getAttributeDefaultValue(context, attribValue);
}
if (path == null) {
return null;
}
File file = new File(path);
if (!file.isAbsolute()) {
final AntDomProject antProject = getEffectiveAntProject(attribValue);
if (antProject == null) {
return null;
}
file = new File(getPathResolveRoot(context, antProject), path);
}
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(file.getAbsolutePath()));
if (vFile == null) {
return null;
}
final PsiManager psiManager = context.getPsiManager();
return vFile.isDirectory() ? psiManager.findDirectory(vFile) : psiManager.findFile(vFile);
}
Aggregations