use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.
the class ProjectScopeBuilderImpl method buildAllScope.
@NotNull
@Override
public GlobalSearchScope buildAllScope() {
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
if (projectRootManager == null)
return new EverythingGlobalScope(myProject);
boolean searchOutsideRootModel = false;
for (SearchScopeEnlarger each : Extensions.getExtensions(SearchScopeEnlarger.EXTENSION)) {
searchOutsideRootModel = each.allScopeSearchesOutsideRootModel(myProject);
if (searchOutsideRootModel)
break;
}
return new ProjectAndLibrariesScope(myProject, searchOutsideRootModel);
}
use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.
the class NavBarModel method updateModel.
protected void updateModel(final PsiElement psiElement) {
final Set<VirtualFile> roots = new HashSet<>();
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
final ProjectFileIndex projectFileIndex = projectRootManager.getFileIndex();
for (VirtualFile root : projectRootManager.getContentRoots()) {
VirtualFile parent = root.getParent();
if (parent == null || !projectFileIndex.isInContent(parent)) {
roots.add(root);
}
}
for (final NavBarModelExtension modelExtension : Extensions.getExtensions(NavBarModelExtension.EP_NAME)) {
for (VirtualFile root : modelExtension.additionalRoots(psiElement.getProject())) {
VirtualFile parent = root.getParent();
if (parent == null || !projectFileIndex.isInContent(parent)) {
roots.add(root);
}
}
}
final List<Object> updatedModel = new ArrayList<>();
ApplicationManager.getApplication().runReadAction(() -> traverseToRoot(psiElement, roots, updatedModel));
setModel(ContainerUtil.reverse(updatedModel));
}
use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.
the class SaveProjectAsTemplateAction method collectStructure.
@NotNull
private static List<LocalArchivedTemplate.RootDescription> collectStructure(Project project, Module moduleToSave) {
List<LocalArchivedTemplate.RootDescription> result = new ArrayList<>();
if (moduleToSave != null) {
PathMacroManager macroManager = PathMacroManager.getInstance(moduleToSave);
ModuleRootManager rootManager = ModuleRootManager.getInstance(moduleToSave);
int i = 0;
for (VirtualFile file : rootManager.getContentRoots()) {
result.add(i, describeRoot(file, i, macroManager));
i++;
}
} else {
PathMacroManager macroManager = PathMacroManager.getInstance(project);
ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
int i = 0;
for (VirtualFile file : rootManager.getContentRoots()) {
result.add(i, describeRoot(file, i, macroManager));
i++;
}
}
return result;
}
use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.
the class TestOnlyInspection method isUnderTestSources.
private static boolean isUnderTestSources(PsiElement e) {
ProjectRootManager rm = ProjectRootManager.getInstance(e.getProject());
VirtualFile f = e.getContainingFile().getVirtualFile();
return f != null && rm.getFileIndex().isInTestSourceContent(f);
}
use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.
the class MoveInnerDialog method getTargetContainer.
@Nullable
private PsiElement getTargetContainer() {
if (myTargetContainer instanceof PsiDirectory) {
final PsiDirectory psiDirectory = (PsiDirectory) myTargetContainer;
PsiPackage oldPackage = getTargetPackage();
String name = oldPackage == null ? "" : oldPackage.getQualifiedName();
final String targetName = myPackageNameField.getText();
if (!Comparing.equal(name, targetName)) {
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
final List<VirtualFile> contentSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject);
final PackageWrapper newPackage = new PackageWrapper(PsiManager.getInstance(myProject), targetName);
final VirtualFile targetSourceRoot;
if (contentSourceRoots.size() > 1) {
PsiPackage targetPackage = JavaPsiFacade.getInstance(myProject).findPackage(targetName);
PsiDirectory initialDir = null;
if (targetPackage != null) {
final PsiDirectory[] directories = targetPackage.getDirectories();
final VirtualFile root = projectRootManager.getFileIndex().getSourceRootForFile(psiDirectory.getVirtualFile());
for (PsiDirectory dir : directories) {
if (Comparing.equal(projectRootManager.getFileIndex().getSourceRootForFile(dir.getVirtualFile()), root)) {
initialDir = dir;
break;
}
}
}
final VirtualFile sourceRoot = MoveClassesOrPackagesUtil.chooseSourceRoot(newPackage, contentSourceRoots, initialDir);
if (sourceRoot == null)
return null;
targetSourceRoot = sourceRoot;
} else {
targetSourceRoot = contentSourceRoots.get(0);
}
PsiDirectory dir = RefactoringUtil.findPackageDirectoryInSourceRoot(newPackage, targetSourceRoot);
if (dir == null) {
dir = ApplicationManager.getApplication().runWriteAction(new NullableComputable<PsiDirectory>() {
public PsiDirectory compute() {
try {
return RefactoringUtil.createPackageDirectoryInSourceRoot(newPackage, targetSourceRoot);
} catch (IncorrectOperationException e) {
return null;
}
}
});
}
return dir;
}
}
return myTargetContainer;
}
Aggregations