use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class BaseAnalysisActionDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
myTitledSeparator.setText(myAnalysisNoon);
//include test option
myInspectTestSource.setSelected(myAnalysisOptions.ANALYZE_TEST_SOURCES);
myInspectTestSource.setVisible(ModuleUtil.isSupportedRootType(myProject, JavaSourceRootType.TEST_SOURCE));
//module scope if applicable
myModuleButton.setText(AnalysisScopeBundle.message("scope.option.module.with.mnemonic", myModuleName));
boolean useModuleScope = false;
if (myModuleName != null) {
useModuleScope = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.MODULE;
myModuleButton.setSelected(myRememberScope && useModuleScope);
}
myModuleButton.setVisible(myModuleName != null && ModuleManager.getInstance(myProject).getModules().length > 1);
boolean useUncommitedFiles = false;
final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
final boolean hasVCS = !changeListManager.getAffectedFiles().isEmpty();
if (hasVCS) {
useUncommitedFiles = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.UNCOMMITTED_FILES;
myUncommitedFilesButton.setSelected(myRememberScope && useUncommitedFiles);
}
myUncommitedFilesButton.setVisible(hasVCS);
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
model.addElement(ALL);
final List<? extends ChangeList> changeLists = changeListManager.getChangeListsCopy();
for (ChangeList changeList : changeLists) {
model.addElement(changeList.getName());
}
myChangeLists.setRenderer(new ListCellRendererWrapper<String>() {
@Override
public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
int availableWidth = myPanel.getWidth() - myUncommitedFilesButton.getWidth() - JBUI.scale(10);
if (availableWidth <= 0) {
availableWidth = JBUI.scale(200);
}
if (list.getFontMetrics(list.getFont()).stringWidth(value) < availableWidth) {
setText(value);
} else {
setText(StringUtil.trimLog(value, 50));
}
}
});
myChangeLists.setModel(model);
myChangeLists.setEnabled(myUncommitedFilesButton.isSelected());
myChangeLists.setVisible(hasVCS);
//file/package/directory/module scope
if (myFileName != null) {
myFileButton.setText(myFileName);
myFileButton.setMnemonic(myFileName.charAt(getSelectedScopeMnemonic()));
} else {
myFileButton.setVisible(false);
}
VirtualFile file = PsiUtilBase.getVirtualFile(myContext);
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
boolean searchInLib = file != null && (fileIndex.isInLibraryClasses(file) || fileIndex.isInLibrarySource(file));
String preselect = StringUtil.isEmptyOrSpaces(myAnalysisOptions.CUSTOM_SCOPE_NAME) ? FindSettings.getInstance().getDefaultScopeName() : myAnalysisOptions.CUSTOM_SCOPE_NAME;
if (searchInLib && GlobalSearchScope.projectScope(myProject).getDisplayName().equals(preselect)) {
preselect = GlobalSearchScope.allScope(myProject).getDisplayName();
}
if (GlobalSearchScope.allScope(myProject).getDisplayName().equals(preselect) && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM) {
myAnalysisOptions.CUSTOM_SCOPE_NAME = preselect;
searchInLib = true;
}
//custom scope
myCustomScopeButton.setSelected(myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM);
myScopeCombo.init(myProject, searchInLib, true, preselect);
myScopeCombo.setCurrentSelection(false);
//correct selection
myProjectButton.setSelected(myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.PROJECT || myFileName == null);
myFileButton.setSelected(myFileName != null && (!myRememberScope || myAnalysisOptions.SCOPE_TYPE != AnalysisScope.PROJECT && !useModuleScope && myAnalysisOptions.SCOPE_TYPE != AnalysisScope.CUSTOM && !useUncommitedFiles));
myScopeCombo.setEnabled(myCustomScopeButton.isSelected());
final ActionListener radioButtonPressed = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onScopeRadioButtonPressed();
}
};
final Enumeration<AbstractButton> enumeration = myGroup.getElements();
while (enumeration.hasMoreElements()) {
enumeration.nextElement().addActionListener(radioButtonPressed);
}
//additional panel - inspection profile chooser
JPanel wholePanel = new JPanel(new BorderLayout());
wholePanel.add(myPanel, BorderLayout.NORTH);
final JComponent additionalPanel = getAdditionalActionSettings(myProject);
if (additionalPanel != null) {
wholePanel.add(additionalPanel, BorderLayout.CENTER);
}
new RadioUpDownListener(myProjectButton, myModuleButton, myUncommitedFilesButton, myFileButton, myCustomScopeButton);
return wholePanel;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class BaseAnalysisAction method getInspectionScopeImpl.
@Nullable
private AnalysisScope getInspectionScopeImpl(@NotNull DataContext dataContext) {
//Possible scopes: file, directory, package, project, module.
Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
if (projectContext != null) {
return new AnalysisScope(projectContext);
}
final AnalysisScope analysisScope = AnalysisScopeUtil.KEY.getData(dataContext);
if (analysisScope != null) {
return analysisScope;
}
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext);
if (psiFile != null && psiFile.getManager().isInProject(psiFile)) {
final VirtualFile file = psiFile.getVirtualFile();
if (file != null && file.isValid() && file.getFileType() instanceof ArchiveFileType && acceptNonProjectDirectories()) {
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
if (jarRoot != null) {
PsiDirectory psiDirectory = psiFile.getManager().findDirectory(jarRoot);
if (psiDirectory != null) {
return new AnalysisScope(psiDirectory);
}
}
}
return new AnalysisScope(psiFile);
}
VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (virtualFiles != null && project != null) {
//analyze on selection
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (virtualFiles.length == 1) {
PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFiles[0]);
if (psiDirectory != null && (acceptNonProjectDirectories() || psiDirectory.getManager().isInProject(psiDirectory))) {
return new AnalysisScope(psiDirectory);
}
}
Set<VirtualFile> files = new HashSet<>();
for (VirtualFile vFile : virtualFiles) {
if (fileIndex.isInContent(vFile)) {
files.add(vFile);
}
}
return new AnalysisScope(project, files);
}
Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
if (moduleContext != null) {
return new AnalysisScope(moduleContext);
}
Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
if (modulesArray != null) {
return new AnalysisScope(modulesArray);
}
return project == null ? null : new AnalysisScope(project);
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class ImportPopupHectorComponentProvider method createConfigurable.
@Override
public HectorComponentPanel createConfigurable(@NotNull final PsiFile file) {
final Project project = file.getProject();
final DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(project);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile virtualFile = file.getVirtualFile();
assert virtualFile != null;
final boolean notInLibrary = !fileIndex.isInLibrarySource(virtualFile) && !fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInContent(virtualFile);
return new HectorComponentPanel() {
private JCheckBox myImportPopupCheckBox = new JCheckBox(EditorBundle.message("hector.import.popup.checkbox"));
@Override
public JComponent createComponent() {
DialogUtil.registerMnemonic(myImportPopupCheckBox);
return myImportPopupCheckBox;
}
@Override
public boolean isModified() {
return myImportPopupCheckBox.isSelected() != analyzer.isImportHintsEnabled(file);
}
@Override
public void apply() throws ConfigurationException {
analyzer.setImportHintsEnabled(file, myImportPopupCheckBox.isSelected());
}
@Override
public void reset() {
myImportPopupCheckBox.setSelected(analyzer.isImportHintsEnabled(file));
myImportPopupCheckBox.setEnabled(analyzer.isAutohintsAvailable(file));
myImportPopupCheckBox.setVisible(notInLibrary);
}
@Override
public void disposeUIResources() {
myImportPopupCheckBox = null;
}
};
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class SummaryNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
ArrayList<AbstractTreeNode> children = new ArrayList<>();
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
if (myToDoSettings.isModulesShown()) {
for (Iterator i = myBuilder.getAllFiles(); i.hasNext(); ) {
final PsiFile psiFile = (PsiFile) i.next();
if (psiFile == null) {
// skip invalid PSI files
continue;
}
final VirtualFile virtualFile = psiFile.getVirtualFile();
createModuleTodoNodeForFile(children, projectFileIndex, virtualFile);
}
} else {
if (myToDoSettings.getIsPackagesShown()) {
if (myBuilder instanceof CurrentFileTodosTreeBuilder) {
final Iterator allFiles = myBuilder.getAllFiles();
if (allFiles.hasNext()) {
children.add(new TodoFileNode(myProject, (PsiFile) allFiles.next(), myBuilder, false));
}
} else {
TodoTreeHelper.getInstance(getProject()).addPackagesToChildren(children, null, myBuilder);
}
} else {
for (Iterator i = myBuilder.getAllFiles(); i.hasNext(); ) {
final PsiFile psiFile = (PsiFile) i.next();
if (psiFile == null) {
// skip invalid PSI files
continue;
}
TodoFileNode fileNode = new TodoFileNode(getProject(), psiFile, myBuilder, false);
if (getTreeStructure().accept(psiFile) && !children.contains(fileNode)) {
children.add(fileNode);
}
}
}
}
Collections.sort(children, TodoFileDirAndModuleComparator.INSTANCE);
return children;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class DirectoryAsPackageRenameHandlerBase method doRename.
private void doRename(PsiElement element, final Project project, PsiElement nameSuggestionContext, Editor editor) {
final PsiDirectory psiDirectory = (PsiDirectory) element;
final T aPackage = getPackage(psiDirectory);
final String qualifiedName = aPackage != null ? getQualifiedName(aPackage) : "";
if (aPackage == null || qualifiedName.length() == 0 || /*default package*/
!isIdentifier(psiDirectory.getName(), project)) {
PsiElementRenameHandler.rename(element, project, nameSuggestionContext, editor);
} else {
PsiDirectory[] directories = aPackage.getDirectories();
final VirtualFile[] virtualFiles = occursInPackagePrefixes(aPackage);
if (virtualFiles.length == 0 && directories.length == 1) {
PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor);
} else {
// the directory corresponds to a package that has multiple associated directories
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
boolean inLib = false;
for (PsiDirectory directory : directories) {
inLib |= !projectFileIndex.isInContent(directory.getVirtualFile());
}
final PsiDirectory[] projectDirectories = aPackage.getDirectories(GlobalSearchScope.projectScope(project));
if (inLib) {
final Module module = ModuleUtilCore.findModuleForPsiElement(psiDirectory);
LOG.assertTrue(module != null);
PsiDirectory[] moduleDirs = null;
if (nameSuggestionContext instanceof PsiPackageBase) {
moduleDirs = aPackage.getDirectories(GlobalSearchScope.moduleScope(module));
if (moduleDirs.length <= 1) {
moduleDirs = null;
}
}
final String promptMessage = "Package \'" + aPackage.getName() + "\' contains directories in libraries which cannot be renamed. Do you want to rename " + (moduleDirs == null ? "current directory" : "current module directories");
if (projectDirectories.length > 0) {
int ret = Messages.showYesNoCancelDialog(project, promptMessage + " or all directories in project?", RefactoringBundle.message("warning.title"), RefactoringBundle.message("rename.current.directory"), RefactoringBundle.message("rename.directories"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
if (ret == Messages.CANCEL)
return;
renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, ret == Messages.YES ? (moduleDirs == null ? new PsiDirectory[] { psiDirectory } : moduleDirs) : projectDirectories);
} else {
if (Messages.showOkCancelDialog(project, promptMessage + "?", RefactoringBundle.message("warning.title"), Messages.getWarningIcon()) == Messages.OK) {
renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, psiDirectory);
}
}
} else {
final StringBuffer message = new StringBuffer();
RenameUtil.buildPackagePrefixChangedMessage(virtualFiles, message, qualifiedName);
buildMultipleDirectoriesInPackageMessage(message, getQualifiedName(aPackage), directories);
message.append(RefactoringBundle.message("directories.and.all.references.to.package.will.be.renamed", psiDirectory.getVirtualFile().getPresentableUrl()));
int ret = Messages.showYesNoCancelDialog(project, message.toString(), RefactoringBundle.message("warning.title"), RefactoringBundle.message("rename.package.button.text"), RefactoringBundle.message("rename.directory.button.text"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
if (ret == Messages.YES) {
PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor);
} else if (ret == Messages.NO) {
renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, psiDirectory);
}
}
}
}
}
Aggregations