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;
}
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());
}
}
}
});
}
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);
}
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));
}
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);
}
}
Aggregations