Search in sources :

Example 21 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class CheckinHandlerUtil method filterOutGeneratedAndExcludedFiles.

public static List<VirtualFile> filterOutGeneratedAndExcludedFiles(@NotNull Collection<VirtualFile> files, @NotNull Project project) {
    ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
    List<VirtualFile> result = new ArrayList<>(files.size());
    for (VirtualFile file : files) {
        if (!fileIndex.isExcluded(file) && !GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, project)) {
            result.add(file);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ArrayList(java.util.ArrayList)

Example 22 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class DestinationFolderComboBox method setData.

public void setData(final Project project, final PsiDirectory initialTargetDirectory, final Pass<String> errorMessageUpdater, final EditorComboBox editorComboBox) {
    myInitialTargetDirectory = initialTargetDirectory;
    mySourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(project);
    new ComboboxSpeedSearch(getComboBox()) {

        @Override
        protected String getElementText(Object element) {
            if (element == NULL_WRAPPER)
                return LEAVE_IN_SAME_SOURCE_ROOT;
            if (element instanceof DirectoryChooser.ItemWrapper) {
                final VirtualFile virtualFile = ((DirectoryChooser.ItemWrapper) element).getDirectory().getVirtualFile();
                final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
                if (module != null) {
                    return module.getName();
                }
            }
            return super.getElementText(element);
        }
    };
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    getComboBox().setRenderer(new ListCellRendererWrapper<DirectoryChooser.ItemWrapper>() {

        @Override
        public void customize(JList list, DirectoryChooser.ItemWrapper itemWrapper, int index, boolean selected, boolean hasFocus) {
            if (itemWrapper != NULL_WRAPPER && itemWrapper != null) {
                setIcon(itemWrapper.getIcon(fileIndex));
                setText(itemWrapper.getRelativeToProjectPath());
            } else {
                setText(LEAVE_IN_SAME_SOURCE_ROOT);
            }
        }
    });
    final VirtualFile initialSourceRoot = initialTargetDirectory != null ? fileIndex.getSourceRootForFile(initialTargetDirectory.getVirtualFile()) : null;
    final VirtualFile[] selection = new VirtualFile[] { initialSourceRoot };
    addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile root = MoveClassesOrPackagesUtil.chooseSourceRoot(new PackageWrapper(PsiManager.getInstance(project), getTargetPackage()), mySourceRoots, initialTargetDirectory);
            if (root == null)
                return;
            final ComboBoxModel model = getComboBox().getModel();
            for (int i = 0; i < model.getSize(); i++) {
                DirectoryChooser.ItemWrapper item = (DirectoryChooser.ItemWrapper) model.getElementAt(i);
                if (item != NULL_WRAPPER && Comparing.equal(fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()), root)) {
                    getComboBox().setSelectedItem(item);
                    getComboBox().repaint();
                    return;
                }
            }
            setComboboxModel(getComboBox(), root, root, fileIndex, mySourceRoots, project, true, errorMessageUpdater);
        }
    });
    editorComboBox.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            JComboBox comboBox = getComboBox();
            DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper) comboBox.getSelectedItem();
            setComboboxModel(comboBox, selectedItem != null && selectedItem != NULL_WRAPPER ? fileIndex.getSourceRootForFile(selectedItem.getDirectory().getVirtualFile()) : initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
        }
    });
    setComboboxModel(getComboBox(), initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
    getComboBox().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Object selectedItem = getComboBox().getSelectedItem();
            updateErrorMessage(errorMessageUpdater, fileIndex, selectedItem);
            if (selectedItem instanceof DirectoryChooser.ItemWrapper && selectedItem != NULL_WRAPPER) {
                PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory();
                if (directory != null) {
                    selection[0] = fileIndex.getSourceRootForFile(directory.getVirtualFile());
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) PackageWrapper(com.intellij.refactoring.PackageWrapper) ActionListener(java.awt.event.ActionListener) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) DirectoryChooser(com.intellij.ide.util.DirectoryChooser)

Example 23 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class PsiUtilEx method isInSourceContent.

public static boolean isInSourceContent(PsiElement e) {
    final VirtualFile file = e.getContainingFile().getVirtualFile();
    if (file == null)
        return false;
    final ProjectFileIndex index = ProjectRootManager.getInstance(e.getProject()).getFileIndex();
    return index.isInContent(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 24 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class SimpleCoverageAnnotator method annotate.

public void annotate(@NotNull final VirtualFile contentRoot, @NotNull final CoverageSuitesBundle suite, @NotNull final CoverageDataManager dataManager, @NotNull final ProjectData data, final Project project, final Annotator annotator) {
    if (!contentRoot.isValid()) {
        return;
    }
    // TODO: check name filter!!!!!
    final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    @SuppressWarnings("unchecked") final Set<String> files = data.getClasses().keySet();
    final Map<String, String> normalizedFiles2Files = ContainerUtil.newHashMap();
    for (final String file : files) {
        normalizedFiles2Files.put(normalizeFilePath(file), file);
    }
    collectFolderCoverage(contentRoot, dataManager, annotator, data, suite.isTrackTestFolders(), index, suite.getCoverageEngine(), ContainerUtil.newHashSet(), Collections.unmodifiableMap(normalizedFiles2Files));
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 25 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class GeneratePluginClassAction method update.

public void update(final AnActionEvent e) {
    super.update(e);
    final Presentation presentation = e.getPresentation();
    if (presentation.isEnabled()) {
        final Project project = e.getProject();
        final Module module = e.getData(LangDataKeys.MODULE);
        if (project != null && module != null && PsiUtil.isPluginModule(module)) {
            final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
            if (view != null) {
                // from com.intellij.ide.actions.CreateClassAction.update()
                ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
                PsiDirectory[] dirs = view.getDirectories();
                for (PsiDirectory dir : dirs) {
                    if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
                        return;
                    }
                }
            }
        }
        presentation.setEnabledAndVisible(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Presentation(com.intellij.openapi.actionSystem.Presentation) Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView)

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