Search in sources :

Example 1 with HighlightDisplayKey

use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.

the class Pep8ExternalAnnotator method collectInformation.

@Nullable
@Override
public State collectInformation(@NotNull PsiFile file) {
    VirtualFile vFile = file.getVirtualFile();
    if (vFile == null || vFile.getFileType() != PythonFileType.INSTANCE) {
        return null;
    }
    Sdk sdk = PythonSdkType.findLocalCPython(ModuleUtilCore.findModuleForPsiElement(file));
    if (sdk == null) {
        if (!myReportedMissingInterpreter) {
            myReportedMissingInterpreter = true;
            reportMissingInterpreter();
        }
        return null;
    }
    final String homePath = sdk.getHomePath();
    if (homePath == null) {
        if (!myReportedMissingInterpreter) {
            myReportedMissingInterpreter = true;
            LOG.info("Could not find home path for interpreter " + homePath);
        }
        return null;
    }
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(file.getProject()).getCurrentProfile();
    final HighlightDisplayKey key = HighlightDisplayKey.find(PyPep8Inspection.INSPECTION_SHORT_NAME);
    if (!profile.isToolEnabled(key, file)) {
        return null;
    }
    if (file instanceof PyFileImpl && !((PyFileImpl) file).isAcceptedFor(PyPep8Inspection.class)) {
        return null;
    }
    final PyPep8Inspection inspection = (PyPep8Inspection) profile.getUnwrappedTool(PyPep8Inspection.KEY.toString(), file);
    final CodeStyleSettings commonSettings = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings();
    final PyCodeStyleSettings customSettings = commonSettings.getCustomSettings(PyCodeStyleSettings.class);
    final List<String> ignoredErrors = Lists.newArrayList(inspection.ignoredErrors);
    if (!customSettings.SPACE_AFTER_NUMBER_SIGN) {
        // Block comment should start with a space
        ignoredErrors.add("E262");
        // Inline comment should start with a space
        ignoredErrors.add("E265");
    }
    if (!customSettings.SPACE_BEFORE_NUMBER_SIGN) {
        // At least two spaces before inline comment
        ignoredErrors.add("E261");
    }
    final int margin = commonSettings.getRightMargin(file.getLanguage());
    return new State(homePath, file.getText(), profile.getErrorLevel(key, file), ignoredErrors, margin, customSettings.HANG_CLOSING_BRACKETS);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) InspectionProfile(com.intellij.codeInspection.InspectionProfile) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) Sdk(com.intellij.openapi.projectRoots.Sdk) PyFileImpl(com.jetbrains.python.psi.impl.PyFileImpl) PyPep8Inspection(com.jetbrains.python.inspections.PyPep8Inspection) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with HighlightDisplayKey

use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.

the class BaseFormInspection method isActive.

@Override
public boolean isActive(PsiElement psiRoot) {
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(psiRoot.getProject()).getCurrentProfile();
    HighlightDisplayKey key = HighlightDisplayKey.find(myInspectionKey);
    return key != null && profile.isToolEnabled(key, psiRoot);
}
Also used : HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey)

Example 3 with HighlightDisplayKey

use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project kotlin by JetBrains.

the class AndroidLintExternalAnnotator method getIssuesFromInspections.

@NotNull
static List<Issue> getIssuesFromInspections(@NotNull Project project, @Nullable PsiElement context) {
    final List<Issue> result = new ArrayList<Issue>();
    final IssueRegistry fullRegistry = new IntellijLintIssueRegistry();
    for (Issue issue : fullRegistry.getIssues()) {
        final String inspectionShortName = AndroidLintInspectionBase.getInspectionShortNameByIssue(project, issue);
        if (inspectionShortName == null) {
            continue;
        }
        final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionShortName);
        if (key == null) {
            continue;
        }
        final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
        final boolean enabled = context != null ? profile.isToolEnabled(key, context) : profile.isToolEnabled(key);
        if (!enabled) {
            continue;
        } else if (!issue.isEnabledByDefault()) {
            // If an issue is marked as not enabled by default, lint won't run it, even if it's in the set
            // of issues provided by an issue registry. Since in the IDE we're enforcing the enabled-state via
            // inspection profiles, mark the issue as enabled to allow users to turn on a lint check directly
            // via the inspections UI.
            issue.setEnabledByDefault(true);
        }
        result.add(issue);
    }
    return result;
}
Also used : Issue(com.android.tools.klint.detector.api.Issue) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) ArrayList(java.util.ArrayList) IssueRegistry(com.android.tools.klint.client.api.IssueRegistry) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with HighlightDisplayKey

use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.

the class LocalInspectionsPass method registerQuickFixes.

private static void registerQuickFixes(@NotNull LocalInspectionToolWrapper tool, @NotNull ProblemDescriptor descriptor, @NotNull HighlightInfo highlightInfo, @NotNull Set<Pair<TextRange, String>> emptyActionRegistered) {
    final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
    boolean needEmptyAction = true;
    final QuickFix[] fixes = descriptor.getFixes();
    if (fixes != null && fixes.length > 0) {
        for (int k = 0; k < fixes.length; k++) {
            if (fixes[k] != null) {
                // prevent null fixes from var args
                QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixWrapper.wrap(descriptor, k), key);
                needEmptyAction = false;
            }
        }
    }
    HintAction hintAction = descriptor instanceof ProblemDescriptorImpl ? ((ProblemDescriptorImpl) descriptor).getHintAction() : null;
    if (hintAction != null) {
        QuickFixAction.registerQuickFixAction(highlightInfo, hintAction, key);
        needEmptyAction = false;
    }
    if (((ProblemDescriptorBase) descriptor).getEnforcedTextAttributes() != null) {
        needEmptyAction = false;
    }
    if (needEmptyAction && emptyActionRegistered.add(Pair.create(highlightInfo.getFixTextRange(), tool.getShortName()))) {
        IntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName());
        QuickFixAction.registerQuickFixAction(highlightInfo, emptyIntentionAction, key);
    }
}
Also used : HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) EmptyIntentionAction(com.intellij.codeInsight.intention.EmptyIntentionAction) EmptyIntentionAction(com.intellij.codeInsight.intention.EmptyIntentionAction)

Example 5 with HighlightDisplayKey

use of com.intellij.codeInsight.daemon.HighlightDisplayKey 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)

Aggregations

HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)42 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)15 NotNull (org.jetbrains.annotations.NotNull)12 Project (com.intellij.openapi.project.Project)10 PsiElement (com.intellij.psi.PsiElement)10 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)7 Nullable (org.jetbrains.annotations.Nullable)7 InspectionProfile (com.intellij.codeInspection.InspectionProfile)6 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)5 Annotation (com.intellij.lang.annotation.Annotation)4 ArrayList (java.util.ArrayList)4 Issue (com.android.tools.lint.detector.api.Issue)3 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)3 PsiFile (com.intellij.psi.PsiFile)3 NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)3 Element (org.jdom.Element)3 Issue (com.android.tools.klint.detector.api.Issue)2 SeverityRegistrar (com.intellij.codeInsight.daemon.impl.SeverityRegistrar)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 QuickFix (com.intellij.codeInspection.QuickFix)2