use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class MavenDomUtil method findContainingMavenizedModule.
@Nullable
public static Module findContainingMavenizedModule(@NotNull PsiFile psiFile) {
VirtualFile file = psiFile.getVirtualFile();
if (file == null)
return null;
Project project = psiFile.getProject();
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
if (!manager.isMavenizedProject())
return null;
ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
Module module = index.getModuleForFile(file);
if (module == null || !manager.isMavenizedModule(module))
return null;
return module;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class AddImportHelper method getImportPriority.
@NotNull
public static ImportPriority getImportPriority(@NotNull PsiElement importLocation, @NotNull PsiFileSystemItem toImport) {
final VirtualFile vFile = toImport.getVirtualFile();
if (vFile == null) {
return UNRESOLVED_SYMBOL_PRIORITY;
}
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(toImport.getProject());
final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
if (fileIndex.isInContent(vFile) && !fileIndex.isInLibraryClasses(vFile)) {
return ImportPriority.PROJECT;
}
final Module module = ModuleUtilCore.findModuleForPsiElement(importLocation);
final Sdk pythonSdk = module != null ? PythonSdkType.findPythonSdk(module) : projectRootManager.getProjectSdk();
return PythonSdkType.isStdLib(vFile, pythonSdk) ? ImportPriority.BUILTIN : ImportPriority.THIRD_PARTY;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class ImportCandidateHolder method getRelevance.
int getRelevance() {
final Project project = myImportable.getProject();
final PsiFile psiFile = myImportable.getContainingFile();
final VirtualFile vFile = psiFile == null ? null : psiFile.getVirtualFile();
if (vFile == null)
return 0;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
// files under project source are most relevant
final Module module = fileIndex.getModuleForFile(vFile);
if (module != null)
return 3;
// then come files directly under Lib
if (vFile.getParent().getName().equals("Lib"))
return 2;
// tests we don't want
if (vFile.getParent().getName().equals("test"))
return 0;
return 1;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class CreateClassToBindFix method run.
public void run() {
final Project project = myEditor.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(myEditor.getFile());
if (sourceRoot == null) {
Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.class.not.in.source.root"), CommonBundle.getErrorTitle());
return;
}
ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, () -> {
// 1. Create all necessary packages
final int indexOfLastDot = myClassName.lastIndexOf('.');
final String packageName = myClassName.substring(0, indexOfLastDot != -1 ? indexOfLastDot : 0);
final PsiDirectory psiDirectory;
if (packageName.length() > 0) {
final PackageWrapper packageWrapper = new PackageWrapper(PsiManager.getInstance(project), packageName);
try {
psiDirectory = RefactoringUtil.createPackageDirectoryInSourceRoot(packageWrapper, sourceRoot);
LOG.assertTrue(psiDirectory != null);
} catch (final IncorrectOperationException e) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.package", packageName, e.getMessage()), CommonBundle.getErrorTitle()));
return;
}
} else {
psiDirectory = PsiManager.getInstance(project).findDirectory(sourceRoot);
LOG.assertTrue(psiDirectory != null);
}
// 2. Create class in the package
try {
final String name = myClassName.substring(indexOfLastDot != -1 ? indexOfLastDot + 1 : 0);
final PsiClass aClass = JavaDirectoryService.getInstance().createClass(psiDirectory, name);
createBoundFields(aClass);
} catch (final IncorrectOperationException e) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.class", packageName, e.getMessage()), CommonBundle.getErrorTitle()));
}
}, getName(), null));
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class AbstractFolderNode method containsImpl.
@Override
protected boolean containsImpl(@NotNull final VirtualFile file) {
final PsiElement psiElement = extractPsiFromValue();
if (psiElement == null || !psiElement.isValid()) {
return false;
}
final VirtualFile valueFile = ((PsiDirectory) psiElement).getVirtualFile();
if (!VfsUtil.isAncestor(valueFile, file, false)) {
return false;
}
final Project project = psiElement.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final Module module = fileIndex.getModuleForFile(valueFile);
if (module == null) {
return fileIndex.getModuleForFile(file) == null;
}
return ModuleRootManager.getInstance(module).getFileIndex().isInContent(file);
}
Aggregations