use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.
the class SingleInspectionProfilePanel method compoundPopup.
private JPopupMenu compoundPopup() {
final DefaultActionGroup group = new DefaultActionGroup();
final SeverityRegistrar severityRegistrar = myProfile.getProfileManager().getOwnSeverityRegistrar();
for (HighlightSeverity severity : LevelChooserAction.getSeverities(severityRegistrar, includeDoNotShow())) {
final HighlightDisplayLevel level = HighlightDisplayLevel.find(severity);
group.add(new AnAction(renderSeverity(severity), renderSeverity(severity), level.getIcon()) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
setNewHighlightingLevel(level);
}
@Override
public boolean isDumbAware() {
return true;
}
});
}
group.add(Separator.getInstance());
ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group);
return menu.getComponent();
}
use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.
the class InspectionProfileImpl method getErrorLevel.
@Override
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey inspectionToolKey, PsiElement element) {
Project project = element == null ? null : element.getProject();
final ToolsImpl tools = getToolsOrNull(inspectionToolKey.toString(), project);
HighlightDisplayLevel level = tools != null ? tools.getLevel(element) : HighlightDisplayLevel.WARNING;
if (!getProfileManager().getOwnSeverityRegistrar().isSeverityValid(level.getSeverity().getName())) {
level = HighlightDisplayLevel.WARNING;
setErrorLevel(inspectionToolKey, level, project);
}
return level;
}
use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.
the class InspectionProfileImpl method convert.
public void convert(@NotNull Element element, @NotNull Project project) {
final Element scopes = element.getChild("scopes");
if (scopes == null) {
return;
}
initInspectionTools(project);
for (Element scopeElement : scopes.getChildren(SCOPE)) {
final String profile = scopeElement.getAttributeValue(PROFILE);
InspectionProfileImpl inspectionProfile = profile == null ? null : getProfileManager().getProfile(profile);
NamedScope scope = inspectionProfile == null ? null : getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME));
if (scope == null) {
continue;
}
for (InspectionToolWrapper toolWrapper : inspectionProfile.getInspectionTools(null)) {
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
try {
InspectionToolWrapper toolWrapperCopy = copyToolSettings(toolWrapper);
HighlightDisplayLevel errorLevel = inspectionProfile.getErrorLevel(key, null, project);
getTools(toolWrapper.getShortName(), project).addTool(scope, toolWrapperCopy, inspectionProfile.isToolEnabled(key), errorLevel);
} catch (Exception e) {
LOG.error(e);
}
}
}
reduceConvertedScopes();
}
use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.
the class InspectionProfileImpl method addTool.
public void addTool(@Nullable Project project, @NotNull InspectionToolWrapper toolWrapper, @NotNull Map<String, List<String>> dependencies) {
final String shortName = toolWrapper.getShortName();
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null) {
final InspectionEP extension = toolWrapper.getExtension();
Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<>(toolWrapper.getDisplayName()) : extension::getDisplayName;
if (toolWrapper instanceof LocalInspectionToolWrapper) {
key = HighlightDisplayKey.register(shortName, computable, toolWrapper.getID(), ((LocalInspectionToolWrapper) toolWrapper).getAlternativeID());
} else {
key = HighlightDisplayKey.register(shortName, computable);
}
}
if (key == null) {
LOG.error(shortName + " ; number of initialized tools: " + myTools.size());
return;
}
HighlightDisplayLevel baseLevel = myBaseProfile != null && myBaseProfile.getToolsOrNull(shortName, project) != null ? myBaseProfile.getErrorLevel(key, project) : HighlightDisplayLevel.DO_NOT_SHOW;
HighlightDisplayLevel defaultLevel = toolWrapper.getDefaultLevel();
HighlightDisplayLevel level = baseLevel.getSeverity().compareTo(defaultLevel.getSeverity()) > 0 ? baseLevel : defaultLevel;
boolean enabled = myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : toolWrapper.isEnabledByDefault();
final ToolsImpl toolsList = new ToolsImpl(toolWrapper, level, !myLockedProfile && enabled, enabled);
final Element element = myUninitializedSettings.remove(shortName);
try {
if (element != null) {
getPathMacroManager().expandPaths(element);
toolsList.readExternal(element, getProfileManager(), dependencies);
} else if (!myUninitializedSettings.containsKey(InspectionElementsMergerBase.getMergedMarkerName(shortName))) {
final InspectionElementsMergerBase merger = getMerger(shortName);
Element merged = merger == null ? null : merger.merge(myUninitializedSettings);
if (merged != null) {
getPathMacroManager().expandPaths(merged);
toolsList.readExternal(merged, getProfileManager(), dependencies);
} else if (isProfileLocked()) {
// https://youtrack.jetbrains.com/issue/IDEA-158936
toolsList.setEnabled(false);
if (toolsList.getNonDefaultTools() == null) {
toolsList.getDefaultState().setEnabled(false);
}
}
}
} catch (InvalidDataException e) {
LOG.error("Can't read settings for " + toolWrapper, e);
}
myTools.put(shortName, toolsList);
}
use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.
the class WebReferencesAnnotatorBase method apply.
@Override
public void apply(@NotNull PsiFile file, MyInfo[] infos, @NotNull AnnotationHolder holder) {
if (infos == null || infos.length == 0) {
return;
}
final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file);
for (MyInfo info : infos) {
if (!info.myResult) {
final PsiElement element = info.myAnchor.retrieve();
if (element != null) {
final int start = element.getTextRange().getStartOffset();
final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset());
final String message = getErrorMessage(info.myUrl);
final Annotation annotation;
if (displayLevel == HighlightDisplayLevel.ERROR) {
annotation = holder.createErrorAnnotation(range, message);
} else if (displayLevel == HighlightDisplayLevel.WARNING) {
annotation = holder.createWarningAnnotation(range, message);
} else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
annotation = holder.createInfoAnnotation(range, message);
} else {
annotation = holder.createWarningAnnotation(range, message);
}
for (IntentionAction action : getQuickFixes()) {
annotation.registerFix(action);
}
}
}
}
}
Aggregations