use of com.intellij.analysis.BaseAnalysisActionDialog in project intellij-community by JetBrains.
the class SliceForwardHandler method askForParams.
@Override
public SliceAnalysisParams askForParams(PsiElement element, boolean dataFlowToThis, SliceManager.StoredSettingsBean storedSettingsBean, String dialogTitle) {
AnalysisScope analysisScope = new AnalysisScope(element.getContainingFile());
Module module = ModuleUtilCore.findModuleForPsiElement(element);
String name = module == null ? null : module.getName();
Project myProject = element.getProject();
final SliceForwardForm form = new SliceForwardForm();
form.init(storedSettingsBean.showDereferences);
AnalysisUIOptions analysisUIOptions = new AnalysisUIOptions();
analysisUIOptions.save(storedSettingsBean.analysisUIOptions);
BaseAnalysisActionDialog dialog = new BaseAnalysisActionDialog(dialogTitle, "Analyze scope", myProject, analysisScope, name, true, analysisUIOptions, element) {
@Override
protected JComponent getAdditionalActionSettings(Project project) {
return form.getComponent();
}
};
if (!dialog.showAndGet()) {
return null;
}
storedSettingsBean.analysisUIOptions.save(analysisUIOptions);
storedSettingsBean.showDereferences = form.isToShowDerefs();
AnalysisScope scope = dialog.getScope(analysisUIOptions, analysisScope, myProject, module);
SliceAnalysisParams params = new SliceAnalysisParams();
params.scope = scope;
params.dataFlowToThis = dataFlowToThis;
params.showInstanceDereferences = form.isToShowDerefs();
return params;
}
use of com.intellij.analysis.BaseAnalysisActionDialog in project intellij-community by JetBrains.
the class SliceHandler method askForParams.
public SliceAnalysisParams askForParams(PsiElement element, boolean dataFlowToThis, SliceManager.StoredSettingsBean storedSettingsBean, String dialogTitle) {
AnalysisScope analysisScope = new AnalysisScope(element.getContainingFile());
Module module = ModuleUtilCore.findModuleForPsiElement(element);
String name = module == null ? null : module.getName();
Project myProject = element.getProject();
AnalysisUIOptions analysisUIOptions = new AnalysisUIOptions();
analysisUIOptions.save(storedSettingsBean.analysisUIOptions);
BaseAnalysisActionDialog dialog = new BaseAnalysisActionDialog(dialogTitle, "Analyze scope", myProject, analysisScope, name, true, analysisUIOptions, element);
if (!dialog.showAndGet()) {
return null;
}
AnalysisScope scope = dialog.getScope(analysisUIOptions, analysisScope, myProject, module);
storedSettingsBean.analysisUIOptions.save(analysisUIOptions);
SliceAnalysisParams params = new SliceAnalysisParams();
params.scope = scope;
params.dataFlowToThis = dataFlowToThis;
return params;
}
use of com.intellij.analysis.BaseAnalysisActionDialog in project intellij-community by JetBrains.
the class RunInspectionAction method runInspection.
public static void runInspection(@NotNull final Project project, @NotNull String shortName, @Nullable VirtualFile virtualFile, PsiElement psiElement, PsiFile psiFile) {
final PsiElement element = psiFile == null ? psiElement : psiFile;
final InspectionProfile currentProfile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
final InspectionToolWrapper toolWrapper = element != null ? currentProfile.getInspectionTool(shortName, element) : currentProfile.getInspectionTool(shortName, project);
LOGGER.assertTrue(toolWrapper != null, "Missed inspection: " + shortName);
final InspectionManagerEx managerEx = (InspectionManagerEx) InspectionManager.getInstance(project);
final Module module = virtualFile != null ? ModuleUtilCore.findModuleForFile(virtualFile, project) : null;
AnalysisScope analysisScope = null;
if (psiFile != null) {
analysisScope = new AnalysisScope(psiFile);
} else {
if (virtualFile != null && virtualFile.isDirectory()) {
final PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile);
if (psiDirectory != null) {
analysisScope = new AnalysisScope(psiDirectory);
}
}
if (analysisScope == null && virtualFile != null) {
analysisScope = new AnalysisScope(project, Arrays.asList(virtualFile));
}
if (analysisScope == null) {
analysisScope = new AnalysisScope(project);
}
}
final AnalysisUIOptions options = AnalysisUIOptions.getInstance(project);
final FileFilterPanel fileFilterPanel = new FileFilterPanel();
fileFilterPanel.init(options);
final AnalysisScope initialAnalysisScope = analysisScope;
final BaseAnalysisActionDialog dialog = new BaseAnalysisActionDialog("Run '" + toolWrapper.getDisplayName() + "'", AnalysisScopeBundle.message("analysis.scope.title", InspectionsBundle.message("inspection.action.noun")), project, analysisScope, module != null ? module.getName() : null, true, options, psiElement) {
private InspectionToolWrapper myUpdatedSettingsToolWrapper;
@Nullable
@Override
protected JComponent getAdditionalActionSettings(Project project) {
final JPanel fileFilter = fileFilterPanel.getPanel();
if (toolWrapper.getTool().createOptionsPanel() != null) {
JPanel additionPanel = new JPanel();
additionPanel.setLayout(new BoxLayout(additionPanel, BoxLayout.Y_AXIS));
additionPanel.add(fileFilter);
//new InheritOptionsForToolPanel(toolWrapper.getShortName(), project);
myUpdatedSettingsToolWrapper = copyToolWithSettings(toolWrapper);
additionPanel.add(new TitledSeparator(IdeBundle.message("goto.inspection.action.choose.inherit.settings.from")));
JComponent optionsPanel = myUpdatedSettingsToolWrapper.getTool().createOptionsPanel();
LOGGER.assertTrue(optionsPanel != null);
if (UIUtil.hasScrollPane(optionsPanel)) {
additionPanel.add(optionsPanel);
} else {
additionPanel.add(ScrollPaneFactory.createScrollPane(optionsPanel, SideBorder.NONE));
}
return additionPanel;
} else {
return fileFilter;
}
}
@NotNull
@Override
public AnalysisScope getScope(@NotNull AnalysisUIOptions uiOptions, @NotNull AnalysisScope defaultScope, @NotNull Project project, Module module) {
final AnalysisScope scope = super.getScope(uiOptions, defaultScope, project, module);
final GlobalSearchScope filterScope = fileFilterPanel.getSearchScope();
if (filterScope == null) {
return scope;
}
scope.setFilter(filterScope);
return scope;
}
private AnalysisScope getScope() {
return getScope(options, initialAnalysisScope, project, module);
}
private InspectionToolWrapper getToolWrapper() {
return myUpdatedSettingsToolWrapper == null ? toolWrapper : myUpdatedSettingsToolWrapper;
}
@NotNull
@Override
protected Action[] createActions() {
final List<Action> actions = new ArrayList<>();
final boolean hasFixAll = toolWrapper.getTool() instanceof CleanupLocalInspectionTool;
actions.add(new AbstractAction(hasFixAll ? AnalysisScopeBundle.message("action.analyze.verb") : CommonBundle.getOkButtonText()) {
{
putValue(DEFAULT_ACTION, Boolean.TRUE);
}
@Override
public void actionPerformed(ActionEvent e) {
RunInspectionIntention.rerunInspection(getToolWrapper(), managerEx, getScope(), null);
close(DialogWrapper.OK_EXIT_CODE);
}
});
if (hasFixAll) {
actions.add(new AbstractAction("Fix All") {
@Override
public void actionPerformed(ActionEvent e) {
InspectionToolWrapper wrapper = getToolWrapper();
InspectionProfileImpl cleanupToolProfile = RunInspectionIntention.createProfile(wrapper, managerEx, null);
managerEx.createNewGlobalContext(false).codeCleanup(getScope(), cleanupToolProfile, "Cleanup by " + wrapper.getDisplayName(), null, false);
close(DialogWrapper.OK_EXIT_CODE);
}
});
}
actions.add(getCancelAction());
if (SystemInfo.isMac) {
Collections.reverse(actions);
}
return actions.toArray(new Action[actions.size()]);
}
};
dialog.showAndGet();
}
use of com.intellij.analysis.BaseAnalysisActionDialog in project intellij-community by JetBrains.
the class MethodDuplicatesHandler method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) {
final int offset = editor.getCaretModel().getOffset();
final PsiElement element = file.findElementAt(offset);
final PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class);
final String cannotRefactorMessage = getCannotRefactorMessage(member);
if (cannotRefactorMessage != null) {
String message = RefactoringBundle.getCannotRefactorMessage(cannotRefactorMessage);
showErrorMessage(message, project, editor);
return;
}
final AnalysisScope scope = new AnalysisScope(file);
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(RefactoringBundle.message("replace.method.duplicates.scope.chooser.title", REFACTORING_NAME), RefactoringBundle.message("replace.method.duplicates.scope.chooser.message"), project, scope, module != null ? module.getName() : null, false, AnalysisUIOptions.getInstance(project), element);
if (dlg.showAndGet()) {
AnalysisScope selectedScope = dlg.getScope(AnalysisUIOptions.getInstance(project), scope, project, module);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Locate duplicates", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
invokeOnScope(project, member, selectedScope);
}
});
}
}
use of com.intellij.analysis.BaseAnalysisActionDialog in project intellij-community by JetBrains.
the class CleanupOnScopeIntention method getScope.
@Nullable
@Override
protected AnalysisScope getScope(final Project project, final PsiFile file) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
AnalysisScope analysisScope = new AnalysisScope(file);
final VirtualFile virtualFile = file.getVirtualFile();
if (file.isPhysical() || virtualFile == null || !virtualFile.isInLocalFileSystem()) {
analysisScope = new AnalysisScope(project);
}
final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(AnalysisScopeBundle.message("specify.analysis.scope", InspectionsBundle.message("inspection.action.title")), AnalysisScopeBundle.message("analysis.scope.title", InspectionsBundle.message("inspection.action.noun")), project, analysisScope, module != null ? module.getName() : null, true, AnalysisUIOptions.getInstance(project), file);
if (!dlg.showAndGet()) {
return null;
}
final AnalysisUIOptions uiOptions = AnalysisUIOptions.getInstance(project);
return dlg.getScope(uiOptions, analysisScope, project, module);
}
Aggregations