Search in sources :

Example 1 with BaseAnalysisActionDialog

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;
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) Project(com.intellij.openapi.project.Project) AnalysisUIOptions(com.intellij.analysis.AnalysisUIOptions) Module(com.intellij.openapi.module.Module) BaseAnalysisActionDialog(com.intellij.analysis.BaseAnalysisActionDialog)

Example 2 with BaseAnalysisActionDialog

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;
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) Project(com.intellij.openapi.project.Project) AnalysisUIOptions(com.intellij.analysis.AnalysisUIOptions) Module(com.intellij.openapi.module.Module) BaseAnalysisActionDialog(com.intellij.analysis.BaseAnalysisActionDialog)

Example 3 with BaseAnalysisActionDialog

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();
}
Also used : InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) BaseAnalysisActionDialog(com.intellij.analysis.BaseAnalysisActionDialog) AnalysisScope(com.intellij.analysis.AnalysisScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AnalysisUIOptions(com.intellij.analysis.AnalysisUIOptions) InspectionProfile(com.intellij.codeInspection.InspectionProfile) InspectionManagerEx(com.intellij.codeInspection.ex.InspectionManagerEx) Project(com.intellij.openapi.project.Project) CleanupLocalInspectionTool(com.intellij.codeInspection.CleanupLocalInspectionTool) TitledSeparator(com.intellij.ui.TitledSeparator) Module(com.intellij.openapi.module.Module) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 4 with BaseAnalysisActionDialog

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);
            }
        });
    }
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Module(com.intellij.openapi.module.Module) BaseAnalysisActionDialog(com.intellij.analysis.BaseAnalysisActionDialog)

Example 5 with BaseAnalysisActionDialog

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);
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnalysisUIOptions(com.intellij.analysis.AnalysisUIOptions) Module(com.intellij.openapi.module.Module) BaseAnalysisActionDialog(com.intellij.analysis.BaseAnalysisActionDialog) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BaseAnalysisActionDialog (com.intellij.analysis.BaseAnalysisActionDialog)6 AnalysisScope (com.intellij.analysis.AnalysisScope)5 AnalysisUIOptions (com.intellij.analysis.AnalysisUIOptions)5 Module (com.intellij.openapi.module.Module)5 Project (com.intellij.openapi.project.Project)3 CleanupLocalInspectionTool (com.intellij.codeInspection.CleanupLocalInspectionTool)1 InspectionProfile (com.intellij.codeInspection.InspectionProfile)1 InspectionManagerEx (com.intellij.codeInspection.ex.InspectionManagerEx)1 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 TitledSeparator (com.intellij.ui.TitledSeparator)1 ActionEvent (java.awt.event.ActionEvent)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1