use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class LevelChooserAction method createPopupActionGroup.
@NotNull
@Override
public DefaultActionGroup createPopupActionGroup(final JComponent anchor) {
final DefaultActionGroup group = new DefaultActionGroup();
for (final HighlightSeverity severity : getSeverities(mySeverityRegistrar, myIncludeDoNotShow)) {
final HighlightSeverityAction action = new HighlightSeverityAction(severity);
if (myChosen == null) {
setChosen(action.getSeverity());
}
group.add(action);
}
group.addSeparator();
group.add(new DumbAwareAction("Edit severities...") {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final SeverityEditorDialog dlg = new SeverityEditorDialog(anchor, myChosen, mySeverityRegistrar, true);
if (dlg.showAndGet()) {
final HighlightInfoType type = dlg.getSelectedType();
if (type != null) {
final HighlightSeverity severity = type.getSeverity(null);
setChosen(severity);
onChosen(severity);
}
}
}
});
return group;
}
use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class InspectionFilterAction method tune.
private void tune(InspectionProfileImpl profile, Project project) {
addAction(new ResetFilterAction());
addSeparator();
if (ApplicationNamesInfo.getInstance().getProductName().contains("IDEA")) {
// minor IDEs don't have "New in XXX" in inspection descriptions
addAction(new ShowNewInspectionsAction());
}
addSeparator();
addAction(new ShowEnabledOrDisabledInspectionsAction(true));
addAction(new ShowEnabledOrDisabledInspectionsAction(false));
addAction(new ShowOnlyModifiedInspectionsAction());
addSeparator();
for (final HighlightSeverity severity : LevelChooserAction.getSeverities(mySeverityRegistrar)) {
add(new ShowWithSpecifiedSeverityInspectionsAction(severity));
}
addSeparator();
final Set<String> languageIds = new THashSet<>();
for (ScopeToolState state : profile.getDefaultStates(project)) {
languageIds.add(state.getTool().getLanguage());
}
final List<Language> languages = new SmartList<>();
for (String id : languageIds) {
if (id != null) {
final Language language = Language.findLanguageByID(id);
if (language != null) {
languages.add(language);
}
}
}
if (!languages.isEmpty()) {
final DefaultActionGroup languageActionGroupParent = new DefaultActionGroup("Filter by Language", languages.size() >= MIN_LANGUAGE_COUNT_TO_WRAP);
add(languageActionGroupParent);
Collections.sort(languages, Comparator.comparing(Language::getDisplayName));
for (Language language : languages) {
languageActionGroupParent.add(new LanguageFilterAction(language));
}
languageActionGroupParent.add(new LanguageFilterAction(null));
addSeparator();
}
add(new ShowAvailableOnlyOnAnalyzeInspectionsAction());
add(new ShowOnlyCleanupInspectionsAction());
}
use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class InspectionToolsConfigurable method importInspectionProfile.
public static InspectionProfileImpl importInspectionProfile(@NotNull Element rootElement, @NotNull BaseInspectionProfileManager profileManager, @NotNull Project project) {
InspectionProfileImpl profile = new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), profileManager);
if (Comparing.strEqual(rootElement.getName(), "component")) {
//import right from .idea/inspectProfiles/xxx.xml
rootElement = rootElement.getChildren().get(0);
}
final Set<String> levels = new HashSet<>();
for (Element inspectElement : rootElement.getChildren("inspection_tool")) {
addLevelIfNotNull(levels, inspectElement);
for (Element s : inspectElement.getChildren("scope")) {
addLevelIfNotNull(levels, s);
}
}
for (Iterator<String> iterator = levels.iterator(); iterator.hasNext(); ) {
String level = iterator.next();
if (profileManager.getOwnSeverityRegistrar().getSeverity(level) != null) {
iterator.remove();
}
}
if (!levels.isEmpty()) {
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (Messages.showYesNoDialog(project, "Undefined severities detected: " + StringUtil.join(levels, ", ") + ". Do you want to create them?", "Warning", Messages.getWarningIcon()) == Messages.YES) {
for (String level : levels) {
final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES.getDefaultAttributes();
HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl(new HighlightSeverity(level, 50), TextAttributesKey.createTextAttributesKey(level));
profileManager.getOwnSeverityRegistrar().registerSeverity(new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes.clone(), info), textAttributes.getErrorStripeColor());
}
}
} else {
throw new AssertionError("All of levels must exist in unit-test mode, but actual not exist levels = " + levels);
}
}
profile.readExternal(rootElement);
profile.setProjectLevel(false);
profile.initInspectionTools(project);
return profile;
}
use of com.intellij.lang.annotation.HighlightSeverity in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method createAnnotation.
@SuppressWarnings("deprecation")
@NotNull
private Annotation createAnnotation(@NotNull AnnotationHolder holder, @NotNull String message, @NotNull TextRange range, @NotNull HighlightDisplayLevel displayLevel, @NotNull Issue issue) {
// Convert from inspection severity to annotation severity
HighlightSeverity severity;
if (displayLevel == HighlightDisplayLevel.ERROR) {
severity = HighlightSeverity.ERROR;
} else if (displayLevel == HighlightDisplayLevel.WARNING) {
severity = HighlightSeverity.WARNING;
} else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
severity = HighlightSeverity.WEAK_WARNING;
} else if (displayLevel == HighlightDisplayLevel.INFO) {
severity = HighlightSeverity.INFO;
} else {
severity = HighlightSeverity.WARNING;
}
String link = " <a " + "href=\"#lint/" + issue.getId() + "\"" + (UIUtil.isUnderDarcula() ? " color=\"7AB4C9\" " : "") + ">" + DaemonBundle.message("inspection.extended.description") + "</a> " + getShowMoreShortCut();
String tooltip = XmlStringUtil.wrapInHtml(RAW.convertTo(message, HTML) + link);
return holder.createAnnotation(severity, range, message, tooltip);
}
use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class DomElementsHighlightingUtil method createAnnotation.
@Nullable
public static Annotation createAnnotation(final DomElementProblemDescriptor problemDescriptor) {
return createProblemDescriptors(problemDescriptor, s -> {
String text = problemDescriptor.getDescriptionTemplate();
if (StringUtil.isEmpty(text))
text = null;
final HighlightSeverity severity = problemDescriptor.getHighlightSeverity();
TextRange range = s.first;
if (text == null)
range = TextRange.from(range.getStartOffset(), 0);
range = range.shiftRight(s.second.getTextRange().getStartOffset());
final Annotation annotation = createAnnotation(severity, range, text);
if (problemDescriptor instanceof DomElementResolveProblemDescriptor) {
annotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
}
for (LocalQuickFix fix : problemDescriptor.getFixes()) {
if (fix instanceof IntentionAction)
annotation.registerFix((IntentionAction) fix);
}
return annotation;
});
}
Aggregations