Search in sources :

Example 1 with InspectionProfileImpl

use of com.intellij.codeInspection.ex.InspectionProfileImpl in project intellij-community by JetBrains.

the class PyCompatibilityInspectionAdvertiser method enableCompatibilityInspection.

private static void enableCompatibilityInspection(@NotNull Project project) {
    final InspectionProfileImpl profile = InspectionProfileManager.getInstance(project).getCurrentProfile();
    final InspectionToolWrapper tool = profile.getInspectionTool(getCompatibilityInspectionShortName(), project);
    if (tool != null) {
        profile.setToolEnabled(tool.getShortName(), true);
        EditInspectionToolsSettingsAction.editToolSettings(project, profile, getCompatibilityInspectionShortName());
    }
}
Also used : InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 2 with InspectionProfileImpl

use of com.intellij.codeInspection.ex.InspectionProfileImpl in project intellij-community by JetBrains.

the class SpellCheckingEditorCustomization method customize.

@Override
public void customize(@NotNull EditorEx editor) {
    boolean apply = isEnabled();
    if (!READY) {
        return;
    }
    Project project = editor.getProject();
    if (project == null) {
        return;
    }
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
        return;
    }
    Function<InspectionProfileImpl, InspectionProfileWrapper> strategy = file.getUserData(InspectionProfileWrapper.CUSTOMIZATION_KEY);
    if (strategy == null) {
        file.putUserData(InspectionProfileWrapper.CUSTOMIZATION_KEY, strategy = new MyInspectionProfileStrategy());
    }
    if (!(strategy instanceof MyInspectionProfileStrategy)) {
        return;
    }
    ((MyInspectionProfileStrategy) strategy).setUseSpellCheck(apply);
    if (apply) {
        editor.putUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY, false);
    }
    // Update representation.
    DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(project);
    if (analyzer != null) {
        analyzer.restart(file);
    }
}
Also used : Project(com.intellij.openapi.project.Project) InspectionProfileWrapper(com.intellij.codeInspection.ex.InspectionProfileWrapper) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) PsiFile(com.intellij.psi.PsiFile)

Example 3 with InspectionProfileImpl

use of com.intellij.codeInspection.ex.InspectionProfileImpl in project intellij-community by JetBrains.

the class EditSettingsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final InspectionResultsView view = getView(e);
    InspectionProfileImpl inspectionProfile = view.getCurrentProfile();
    if (view.isSingleInspectionRun()) {
        InspectionToolWrapper tool = ObjectUtils.notNull(inspectionProfile.getInspectionTool(ObjectUtils.notNull(inspectionProfile.getSingleTool()), view.getProject()));
        JComponent panel = tool.getTool().createOptionsPanel();
        if (panel != null) {
            final DialogBuilder builder = new DialogBuilder().title(InspectionsBundle.message("inspection.tool.window.inspection.dialog.title", tool.getDisplayName())).centerPanel(panel);
            builder.removeAllActions();
            builder.addOkAction();
            if (view.isRerunAvailable()) {
                builder.addActionDescriptor(new DialogBuilder.DialogActionDescriptor(InspectionsBundle.message("inspection.action.rerun"), 'R') {

                    @Override
                    protected Action createAction(DialogWrapper dialogWrapper) {
                        return new AbstractAction() {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                view.rerun();
                                dialogWrapper.close(DialogWrapper.OK_EXIT_CODE);
                            }
                        };
                    }
                });
            }
            builder.show();
        } else {
            Messages.showInfoMessage(view.getProject(), InspectionsBundle.message("inspection.tool.window.dialog.no.options", tool.getDisplayName()), InspectionsBundle.message("inspection.tool.window.dialog.title"));
        }
    } else {
        final InspectionToolWrapper toolWrapper = view.getTree().getSelectedToolWrapper(false);
        if (toolWrapper != null) {
            //do not search for dead code entry point tool
            final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
            if (key != null) {
                if (new EditInspectionToolsSettingsAction(key).editToolSettings(view.getProject(), inspectionProfile)) {
                    view.updateCurrentProfile();
                }
                return;
            }
        }
        final String[] path = view.getTree().getSelectedGroupPath();
        if (EditInspectionToolsSettingsAction.editSettings(view.getProject(), inspectionProfile, (c) -> {
            if (path != null) {
                c.selectInspectionGroup(path);
            }
        })) {
            view.updateCurrentProfile();
        }
    }
}
Also used : InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) EditInspectionToolsSettingsAction(com.intellij.codeInspection.ex.EditInspectionToolsSettingsAction) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) EditInspectionToolsSettingsAction(com.intellij.codeInspection.ex.EditInspectionToolsSettingsAction) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 4 with InspectionProfileImpl

use of com.intellij.codeInspection.ex.InspectionProfileImpl in project intellij-community by JetBrains.

the class InspectionProfileSchemesModel method apply.

void apply(InspectionProfileModifiableModel selected, Consumer<InspectionProfileImpl> applyRootProfileAction) {
    for (InspectionProfileImpl profile : myDeletedProfiles) {
        profile.getProfileManager().deleteProfile(profile);
    }
    myDeletedProfiles.clear();
    SingleInspectionProfilePanel selectedPanel = getProfilePanel(selected);
    for (SingleInspectionProfilePanel panel : getProfilePanels()) {
        panel.apply();
        if (panel == selectedPanel) {
            applyRootProfileAction.consume(panel.getProfile());
        }
    }
}
Also used : InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) SingleInspectionProfilePanel(com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel)

Example 5 with InspectionProfileImpl

use of com.intellij.codeInspection.ex.InspectionProfileImpl in project intellij-community by JetBrains.

the class InspectionProfileSchemesPanel method createSchemeActions.

@Override
protected AbstractSchemeActions<InspectionProfileModifiableModel> createSchemeActions() {
    return new DescriptionAwareSchemeActions<InspectionProfileModifiableModel>(this) {

        @Nullable
        @Override
        public String getDescription(@NotNull InspectionProfileModifiableModel scheme) {
            SingleInspectionProfilePanel inspectionProfile = ((InspectionProfileSchemesModel) getModel()).getProfilePanel(scheme);
            return inspectionProfile.getProfile().getDescription();
        }

        @Override
        protected void setDescription(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newDescription) {
            InspectionProfileModifiableModel inspectionProfile = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(scheme).getProfile();
            if (!Comparing.strEqual(newDescription, inspectionProfile.getDescription())) {
                inspectionProfile.setDescription(newDescription);
                inspectionProfile.setModified(true);
            }
        }

        @Override
        protected void importScheme(@NotNull String importerName) {
            final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

                @Override
                public boolean isFileSelectable(VirtualFile file) {
                    return file.getFileType().equals(StdFileTypes.XML);
                }
            };
            descriptor.setDescription("Choose profile file");
            FileChooser.chooseFile(descriptor, myProject, null, file -> {
                if (file != null) {
                    final InspectionProfileImpl profile;
                    try {
                        profile = InspectionToolsConfigurable.importInspectionProfile(JDOMUtil.load(file.getInputStream()), myAppProfileManager, myProject);
                        final SingleInspectionProfilePanel existed = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(profile);
                        if (existed != null) {
                            if (Messages.showOkCancelDialog(myProject, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", Messages.getInformationIcon()) != Messages.OK) {
                                return;
                            }
                            getModel().removeScheme(existed.getProfile());
                        }
                        InspectionProfileModifiableModel model = new InspectionProfileModifiableModel(profile);
                        model.setModified(true);
                        addProfile(model);
                        selectScheme(model);
                    } catch (JDOMException | InvalidDataException | IOException e) {
                        LOG.error(e);
                    }
                }
            });
        }

        @Override
        protected void resetScheme(@NotNull InspectionProfileModifiableModel scheme) {
            final SingleInspectionProfilePanel panel = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(scheme);
            panel.performProfileReset();
        }

        @Override
        protected void duplicateScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newName) {
            final InspectionProfileModifiableModel newProfile = copyToNewProfile(scheme, myProject, newName, false);
            addProfile(newProfile);
            myConfigurable.selectProfile(newProfile);
            selectScheme(newProfile);
        }

        @Override
        protected void exportScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String exporterName) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            descriptor.setDescription("Choose directory to store profile file");
            FileChooser.chooseFile(descriptor, myProject, null, dir -> {
                try {
                    LOG.assertTrue(true);
                    Element element = scheme.writeScheme(false);
                    Path file = Paths.get(dir.getPath(), sanitizeFileName(scheme.getName()) + ".xml");
                    if (Files.isRegularFile(file.toAbsolutePath()) && Messages.showOkCancelDialog(myProject, "File \'" + file + "\' already exist. Do you want to overwrite it?", "Warning", Messages.getQuestionIcon()) != Messages.OK) {
                        return;
                    }
                    JdomKt.write(element, file);
                } catch (IOException e1) {
                    LOG.error(e1);
                }
            });
        }

        @Override
        protected void onSchemeChanged(@Nullable InspectionProfileModifiableModel scheme) {
            super.onSchemeChanged(scheme);
            if (scheme != null) {
                myConfigurable.selectProfile(scheme);
            }
        }

        @Override
        protected void renameScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newName) {
            scheme.setName(newName);
        }

        @Override
        protected void copyToProject(@NotNull InspectionProfileModifiableModel scheme) {
            copyToAnotherLevel(scheme, true);
        }

        @Override
        protected void copyToIDE(@NotNull InspectionProfileModifiableModel scheme) {
            copyToAnotherLevel(scheme, false);
        }

        @Override
        protected Class<InspectionProfileModifiableModel> getSchemeType() {
            return InspectionProfileModifiableModel.class;
        }

        private void copyToAnotherLevel(InspectionProfileModifiableModel profile, boolean copyToProject) {
            String name = SchemeNameGenerator.getUniqueName(profile.getName(), schemeName -> ((InspectionProfileSchemesModel) getModel()).hasName(schemeName, copyToProject));
            final InspectionProfileModifiableModel newProfile = copyToNewProfile(profile, myProject, name, true);
            addProfile(newProfile);
            selectScheme(newProfile);
            getSchemesPanel().startEdit();
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Path(java.nio.file.Path) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) DescriptionAwareSchemeActions(com.intellij.application.options.schemes.DescriptionAwareSchemeActions) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull) SingleInspectionProfilePanel(com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel) InspectionProfileModifiableModel(com.intellij.codeInspection.ex.InspectionProfileModifiableModel) InvalidDataException(com.intellij.openapi.util.InvalidDataException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)24 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)7 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)5 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)5 Project (com.intellij.openapi.project.Project)5 NotNull (org.jetbrains.annotations.NotNull)5 SingleInspectionProfilePanel (com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel)3 ActionEvent (java.awt.event.ActionEvent)3 InspectionProfile (com.intellij.codeInspection.InspectionProfile)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 InspectionManagerEx (com.intellij.codeInspection.ex.InspectionManagerEx)2 InspectionProfileModifiableModel (com.intellij.codeInspection.ex.InspectionProfileModifiableModel)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 PsiFile (com.intellij.psi.PsiFile)2 Element (org.jdom.Element)2 AnalysisScope (com.intellij.analysis.AnalysisScope)1 AnalysisUIOptions (com.intellij.analysis.AnalysisUIOptions)1 BaseAnalysisActionDialog (com.intellij.analysis.BaseAnalysisActionDialog)1 DescriptionAwareSchemeActions (com.intellij.application.options.schemes.DescriptionAwareSchemeActions)1 SchemesCombo (com.intellij.application.options.schemes.SchemesCombo)1