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);
}
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);
}
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;
}
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);
}
}
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();
}
}
}
Aggregations