use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class ModuleVcsPathPresenter method getPresentableRelativePath.
@Override
public String getPresentableRelativePath(@NotNull final ContentRevision fromRevision, @NotNull final ContentRevision toRevision) {
final FilePath fromPath = fromRevision.getFile();
final FilePath toPath = toRevision.getFile();
// need to use parent path because the old file is already not there
final VirtualFile fromParent = getParentFile(fromPath);
final VirtualFile toParent = getParentFile(toPath);
if (fromParent != null && toParent != null) {
String moduleResult = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
final boolean hideExcludedFiles = Registry.is("ide.hide.excluded.files");
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
Module fromModule = fileIndex.getModuleForFile(fromParent, hideExcludedFiles);
Module toModule = fileIndex.getModuleForFile(toParent, hideExcludedFiles);
if (fromModule == null || toModule == null || fromModule.equals(toModule))
return null;
VirtualFile fromContentRoot = fileIndex.getContentRootForFile(fromParent, hideExcludedFiles);
if (fromContentRoot == null)
return null;
String relativePath = VfsUtilCore.getRelativePath(fromParent, fromContentRoot, File.separatorChar);
assert relativePath != null;
relativePath += File.separatorChar;
if (!fromPath.getName().equals(toPath.getName())) {
relativePath += fromPath.getName();
}
return getPresentableRelativePathFor(fromModule, fromContentRoot, relativePath);
}
});
if (moduleResult != null)
return moduleResult;
}
final RelativePathCalculator calculator = new RelativePathCalculator(toPath.getPath(), fromPath.getPath());
calculator.execute();
final String result = calculator.getResult();
return result != null ? result.replace("/", File.separator) : null;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class JavaExtractSuperBaseDialog method getDirUnderSameSourceRoot.
private PsiDirectory getDirUnderSameSourceRoot(final PsiDirectory[] directories) {
final VirtualFile sourceFile = mySourceClass.getContainingFile().getVirtualFile();
if (sourceFile != null) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(sourceFile);
if (sourceRoot != null) {
for (PsiDirectory dir : directories) {
if (Comparing.equal(fileIndex.getSourceRootForFile(dir.getVirtualFile()), sourceRoot)) {
return dir;
}
}
}
}
return directories[0];
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class MoveClassToModuleFix method registerFixes.
public static void registerFixes(QuickFixActionRegistrar registrar, final PsiJavaCodeReferenceElement reference) {
final PsiElement psiElement = reference.getElement();
@NonNls final String referenceName = reference.getRangeInElement().substring(psiElement.getText());
Project project = psiElement.getProject();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile == null)
return;
PsiDirectory dir = containingFile.getContainingDirectory();
if (dir == null)
return;
VirtualFile classVFile = containingFile.getVirtualFile();
if (classVFile == null)
return;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final Module currentModule = fileIndex.getModuleForFile(classVFile);
if (currentModule == null)
return;
List<VirtualFile> sourceRoots = ModuleRootManager.getInstance(currentModule).getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
if (sourceRoots.isEmpty())
return;
final PsiDirectory sourceDirectory = PsiManager.getInstance(project).findDirectory(sourceRoots.get(0));
if (sourceDirectory == null)
return;
VirtualFile vsourceRoot = fileIndex.getSourceRootForFile(classVFile);
if (vsourceRoot == null)
return;
final PsiDirectory sourceRoot = PsiManager.getInstance(project).findDirectory(vsourceRoot);
if (sourceRoot == null)
return;
registrar.register(new MoveClassToModuleFix(referenceName, currentModule, sourceRoot, psiElement));
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-plugins by JetBrains.
the class DartQuickFix method isAvailable.
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
myQuickFixSet.ensureInitialized();
if (mySuppressActionDelegate != null) {
return mySuppressActionDelegate.isAvailable(project, editor, file);
}
if (mySourceChange == null)
return false;
final List<SourceFileEdit> fileEdits = mySourceChange.getEdits();
if (fileEdits.size() != 1)
return false;
final SourceFileEdit fileEdit = fileEdits.get(0);
final VirtualFile virtualFile = AssistUtils.findVirtualFile(fileEdit);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (fileEdit.getFileStamp() != -1) {
if (virtualFile == null || !fileIndex.isInContent(virtualFile))
return false;
}
return true;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-plugins by JetBrains.
the class NewActionScriptClassAction method isAvailable.
private boolean isAvailable(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (project == null || project.isDisposed() || view == null)
return false;
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (PsiDirectory dir : view.getDirectories()) {
if (projectFileIndex.isInSourceContent(dir.getVirtualFile()) && DirectoryIndex.getInstance(dir.getProject()).getPackageName(dir.getVirtualFile()) != null) {
Module module = ModuleUtilCore.findModuleForPsiElement(dir);
if (module != null && isAvailableIn(module)) {
return true;
}
}
}
return false;
}
Aggregations