Search in sources :

Example 26 with ProjectFileIndex

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;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) RelativePathCalculator(com.intellij.openapi.vcs.changes.patch.RelativePathCalculator) Module(com.intellij.openapi.module.Module)

Example 27 with ProjectFileIndex

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];
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 28 with ProjectFileIndex

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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module)

Example 29 with ProjectFileIndex

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFileEdit(org.dartlang.analysis.server.protocol.SourceFileEdit) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 30 with ProjectFileIndex

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;
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) Module(com.intellij.openapi.module.Module)

Aggregations

ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)164 VirtualFile (com.intellij.openapi.vfs.VirtualFile)124 Module (com.intellij.openapi.module.Module)54 Project (com.intellij.openapi.project.Project)51 Nullable (org.jetbrains.annotations.Nullable)38 PsiDirectory (com.intellij.psi.PsiDirectory)24 NotNull (org.jetbrains.annotations.NotNull)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 PsiFile (com.intellij.psi.PsiFile)15 ArrayList (java.util.ArrayList)15 IdeView (com.intellij.ide.IdeView)11 OrderEntry (com.intellij.openapi.roots.OrderEntry)10 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)7 THashSet (gnu.trove.THashSet)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 List (java.util.List)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 Presentation (com.intellij.openapi.actionSystem.Presentation)3 CompilerManager (com.intellij.openapi.compiler.CompilerManager)3