use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class SingleInspectionProfilePanel method updateOptionsAndDescriptionPanel.
private void updateOptionsAndDescriptionPanel(final TreePath... paths) {
if (myProfile == null || paths == null || paths.length == 0) {
return;
}
final TreePath path = paths[0];
if (path == null)
return;
final List<InspectionConfigTreeNode> nodes = InspectionsAggregationUtil.getInspectionsNodes(paths);
if (!nodes.isEmpty()) {
final InspectionConfigTreeNode singleNode = paths.length == 1 && ((InspectionConfigTreeNode) paths[0].getLastPathComponent()).getDefaultDescriptor() != null ? ContainerUtil.getFirstItem(nodes) : null;
if (singleNode != null) {
final Descriptor descriptor = singleNode.getDefaultDescriptor();
LOG.assertTrue(descriptor != null);
if (descriptor.loadDescription() != null) {
// need this in order to correctly load plugin-supplied descriptions
final Descriptor defaultDescriptor = singleNode.getDefaultDescriptor();
final String description = defaultDescriptor.loadDescription();
try {
if (!readHTML(myBrowser, SearchUtil.markup(toHTML(myBrowser, description, false), myProfileFilter.getFilter()))) {
readHTML(myBrowser, toHTML(myBrowser, "<b>" + UNDER_CONSTRUCTION + "</b>", false));
}
} catch (Throwable t) {
LOG.error("Failed to load description for: " + defaultDescriptor.getToolWrapper().getTool().getClass() + "; description: " + description, t);
}
} else {
readHTML(myBrowser, toHTML(myBrowser, "Can't find inspection description.", false));
}
} else {
readHTML(myBrowser, toHTML(myBrowser, "Multiple inspections are selected. You can edit them as a single inspection.", false));
}
myOptionsPanel.removeAll();
final Project project = myProjectProfileManager.getProject();
final JPanel severityPanel = new JPanel(new GridBagLayout());
final JPanel configPanelAnchor = new JPanel(new GridLayout());
final Set<String> scopesNames = new THashSet<>();
for (final InspectionConfigTreeNode node : nodes) {
final List<ScopeToolState> nonDefaultTools = myProfile.getNonDefaultTools(node.getDefaultDescriptor().getKey().toString(), project);
for (final ScopeToolState tool : nonDefaultTools) {
scopesNames.add(tool.getScopeName());
}
}
final double severityPanelWeightY;
if (scopesNames.isEmpty()) {
final LevelChooserAction severityLevelChooser = new LevelChooserAction(myProfile.getProfileManager().getOwnSeverityRegistrar(), includeDoNotShow(nodes)) {
@Override
protected void onChosen(final HighlightSeverity severity) {
final HighlightDisplayLevel level = HighlightDisplayLevel.find(severity);
for (final InspectionConfigTreeNode node : nodes) {
final HighlightDisplayKey key = node.getDefaultDescriptor().getKey();
final NamedScope scope = node.getDefaultDescriptor().getScope();
final boolean toUpdate = myProfile.getErrorLevel(key, scope, project) != level;
myProfile.setErrorLevel(key, level, null, project);
if (toUpdate)
node.dropCache();
}
myTreeTable.updateUI();
}
};
final HighlightSeverity severity = ScopesAndSeveritiesTable.getSeverity(ContainerUtil.map(nodes, node -> node.getDefaultDescriptor().getState()));
severityLevelChooser.setChosen(severity);
final ScopesChooser scopesChooser = new ScopesChooser(ContainerUtil.map(nodes, node -> node.getDefaultDescriptor()), myProfile, project, null) {
@Override
protected void onScopesOrderChanged() {
myTreeTable.updateUI();
updateOptionsAndDescriptionPanel();
}
@Override
protected void onScopeAdded() {
myTreeTable.updateUI();
updateOptionsAndDescriptionPanel();
}
};
severityPanel.add(new JLabel(InspectionsBundle.message("inspection.severity")), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, JBUI.insets(10, 0), 0, 0));
final JComponent severityLevelChooserComponent = severityLevelChooser.createCustomComponent(severityLevelChooser.getTemplatePresentation());
severityPanel.add(severityLevelChooserComponent, new GridBagConstraints(1, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(10, 0), 0, 0));
final JComponent scopesChooserComponent = scopesChooser.createCustomComponent(scopesChooser.getTemplatePresentation());
severityPanel.add(scopesChooserComponent, new GridBagConstraints(2, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(10, 0), 0, 0));
final JLabel label = new JLabel("", SwingConstants.RIGHT);
severityPanel.add(label, new GridBagConstraints(3, 0, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, JBUI.insets(2, 0), 0, 0));
severityPanelWeightY = 0.0;
if (singleNode != null) {
setConfigPanel(configPanelAnchor, myProfile.getToolDefaultState(singleNode.getDefaultDescriptor().getKey().toString(), project));
}
} else {
if (singleNode != null) {
for (final Descriptor descriptor : singleNode.getDescriptors().getNonDefaultDescriptors()) {
descriptor.loadConfig();
}
}
final JTable scopesAndScopesAndSeveritiesTable = new ScopesAndSeveritiesTable(new ScopesAndSeveritiesTable.TableSettings(nodes, myProfile, project) {
@Override
protected void onScopeChosen(@NotNull final ScopeToolState state) {
setConfigPanel(configPanelAnchor, state);
configPanelAnchor.revalidate();
configPanelAnchor.repaint();
}
@Override
protected void onSettingsChanged() {
update(false);
}
@Override
protected void onScopeAdded() {
update(true);
}
@Override
protected void onScopesOrderChanged() {
update(true);
}
@Override
protected void onScopeRemoved(final int scopesCount) {
update(scopesCount == 1);
}
private void update(final boolean updateOptionsAndDescriptionPanel) {
Queue<InspectionConfigTreeNode> q = new Queue<>(nodes.size());
for (InspectionConfigTreeNode node : nodes) {
q.addLast(node);
}
while (!q.isEmpty()) {
final InspectionConfigTreeNode inspectionConfigTreeNode = q.pullFirst();
inspectionConfigTreeNode.dropCache();
final TreeNode parent = inspectionConfigTreeNode.getParent();
if (parent != null && parent.getParent() != null) {
q.addLast((InspectionConfigTreeNode) parent);
}
}
myTreeTable.updateUI();
if (updateOptionsAndDescriptionPanel) {
updateOptionsAndDescriptionPanel();
}
}
});
final ToolbarDecorator wrappedTable = ToolbarDecorator.createDecorator(scopesAndScopesAndSeveritiesTable).disableUpDownActions().setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
final int selectedRow = scopesAndScopesAndSeveritiesTable.getSelectedRow();
final int rowCount = scopesAndScopesAndSeveritiesTable.getRowCount();
return rowCount - 1 != selectedRow;
}
});
final JPanel panel = wrappedTable.createPanel();
panel.setMinimumSize(new Dimension(getMinimumSize().width, 3 * scopesAndScopesAndSeveritiesTable.getRowHeight()));
severityPanel.add(new JBLabel("Severity by Scope"), new GridBagConstraints(0, 0, 1, 1, 1.0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(5, 0, 2, 10), 0, 0));
severityPanel.add(panel, new GridBagConstraints(0, 1, 1, 1, 0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(0, 0, 0, 0), 0, 0));
severityPanelWeightY = 0.3;
}
myOptionsPanel.add(severityPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, severityPanelWeightY, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(0, 2, 0, 0), 0, 0));
if (configPanelAnchor.getComponentCount() != 0) {
configPanelAnchor.setBorder(IdeBorderFactory.createTitledBorder("Options", false, new JBInsets(7, 0, 0, 0)));
}
GuiUtils.enableChildren(myOptionsPanel, isThoughOneNodeEnabled(nodes));
if (configPanelAnchor.getComponentCount() != 0 || scopesNames.isEmpty()) {
myOptionsPanel.add(configPanelAnchor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(0, 2, 0, 0), 0, 0));
}
myOptionsPanel.revalidate();
} else {
initOptionsAndDescriptionPanel();
}
myOptionsPanel.repaint();
}
use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class SingleInspectionProfilePanel method copyUsedSeveritiesIfUndefined.
private static void copyUsedSeveritiesIfUndefined(InspectionProfileImpl selectedProfile, BaseInspectionProfileManager profileManager) {
final SeverityRegistrar registrar = profileManager.getSeverityRegistrar();
final Set<HighlightSeverity> severities = selectedProfile.getUsedSeverities();
for (Iterator<HighlightSeverity> iterator = severities.iterator(); iterator.hasNext(); ) {
HighlightSeverity severity = iterator.next();
if (registrar.isSeverityValid(severity.getName())) {
iterator.remove();
}
}
if (!severities.isEmpty()) {
final SeverityRegistrar oppositeRegister = selectedProfile.getProfileManager().getSeverityRegistrar();
for (HighlightSeverity severity : severities) {
final TextAttributesKey attributesKey = TextAttributesKey.find(severity.getName());
final TextAttributes textAttributes = oppositeRegister.getTextAttributesBySeverity(severity);
if (textAttributes == null) {
continue;
}
HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl(severity, attributesKey);
registrar.registerSeverity(new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes.clone(), info), textAttributes.getErrorStripeColor());
}
}
}
use of com.intellij.lang.annotation.HighlightSeverity 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.lang.annotation.HighlightSeverity in project scss-lint-plugin by idok.
the class ScssLintAnnotationResult method apply.
@Override
public void apply(@NotNull PsiFile file, ScssLintAnnotationResult annotationResult, @NotNull AnnotationHolder holder) {
if (annotationResult == null) {
return;
}
InspectionProjectProfileManager inspectionProjectProfileManager = InspectionProjectProfileManager.getInstance(file.getProject());
SeverityRegistrar severityRegistrar = inspectionProjectProfileManager.getSeverityRegistrar();
HighlightDisplayKey inspectionKey = getHighlightDisplayKeyByClass();
EditorColorsScheme colorsScheme = annotationResult.input.colorsScheme;
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null) {
return;
}
if (annotationResult.fileLevel != null) {
Annotation annotation = holder.createWarningAnnotation(file, annotationResult.fileLevel);
annotation.registerFix(new EditSettingsAction(new ScssLintSettingsPage(file.getProject())));
annotation.setFileLevelAnnotation(true);
return;
}
// TODO consider adding a fix to edit configuration file
if (annotationResult.result == null || annotationResult.result.lint == null || annotationResult.result.lint.isEmpty()) {
return;
}
// String relativeFile = FileUtils.makeRelative(file.getProject(), file.getVirtualFile());
List<Lint.Issue> issues = annotationResult.result.lint.values().iterator().next();
if (issues == null) {
return;
}
ScssLintProjectComponent component = annotationResult.input.project.getComponent(ScssLintProjectComponent.class);
int tabSize = 4;
for (Lint.Issue issue : issues) {
HighlightSeverity severity = getHighlightSeverity(issue, component.treatAsWarnings);
TextAttributes forcedTextAttributes = AnnotatorUtils.getTextAttributes(colorsScheme, severityRegistrar, severity);
Annotation annotation = createAnnotation(holder, file, document, issue, "SCSS Lint: ", tabSize, severity, forcedTextAttributes, inspectionKey, false);
if (annotation != null) {
int offset = StringUtil.lineColToOffset(document.getText(), issue.line - 1, issue.column);
PsiElement lit = PsiUtil.getElementAtOffset(file, offset);
BaseActionFix actionFix = Fixes.getFixForRule(issue.linter, lit);
if (actionFix != null) {
annotation.registerFix(actionFix, null, inspectionKey);
}
// annotation.registerFix(new SuppressActionFix(issue.rule, lit), null, inspectionKey);
}
}
}
use of com.intellij.lang.annotation.HighlightSeverity in project android 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);
}
Aggregations