use of org.jetbrains.android.inspections.lint.AndroidLintInspectionBase in project android by JetBrains.
the class LintNotificationPanel method updateExplanation.
private void updateExplanation(@Nullable IssueData selected) {
// We have the capability to show markup text here, e.g.
// myExplanationPane.setContentType(UIUtil.HTML_MIME)
// and then use an HtmlBuilder to populate it with for
// example issue.getExplanation(HTML). However, the builtin
// HTML formatter ends up using a bunch of weird fonts etc
// so the dialog just ends up looking tacky.
String headerFontColor = HtmlBuilderHelper.getHeaderFontColor();
HtmlBuilder builder = new HtmlBuilder();
builder.openHtmlBody();
if (selected != null) {
builder.addHeading("Message: ", headerFontColor);
builder.add(selected.message).newline();
// Look for quick fixes
AndroidLintInspectionBase inspection = selected.inspection;
AndroidLintQuickFix[] quickFixes = inspection.getQuickFixes(selected.startElement, selected.endElement, selected.message);
IntentionAction[] intentions = inspection.getIntentions(selected.startElement, selected.endElement);
builder.addHeading("Suggested Fixes:", headerFontColor).newline();
builder.beginList();
for (final AndroidLintQuickFix fix : quickFixes) {
builder.listItem();
builder.addLink(fix.getName(), myLinkManager.createRunnableLink(() -> {
myPopup.cancel();
// TODO: Pull in editor context?
WriteCommandAction.runWriteCommandAction(selected.startElement.getProject(), () -> {
fix.apply(selected.startElement, selected.endElement, AndroidQuickfixContexts.BatchContext.getInstance());
});
}));
}
for (final IntentionAction fix : intentions) {
builder.listItem();
builder.addLink(fix.getText(), myLinkManager.createRunnableLink(() -> {
NlModel model = myScreenView.getModel();
Editor editor = PsiEditorUtil.Service.getInstance().findEditorByPsiElement(selected.startElement);
if (editor != null) {
editor.getCaretModel().getCurrentCaret().moveToOffset(selected.startElement.getTextOffset());
myPopup.cancel();
WriteCommandAction.runWriteCommandAction(model.getProject(), () -> {
fix.invoke(model.getProject(), editor, model.getFile());
});
}
}));
}
final SuppressLintIntentionAction suppress = new SuppressLintIntentionAction(selected.issue, selected.startElement);
builder.listItem();
builder.addLink(suppress.getText(), myLinkManager.createRunnableLink(() -> {
myPopup.cancel();
WriteCommandAction.runWriteCommandAction(selected.startElement.getProject(), () -> {
suppress.invoke(selected.startElement.getProject(), null, myScreenView.getModel().getFile());
});
}));
builder.endList();
Issue issue = selected.issue;
builder.addHeading("Priority: ", headerFontColor);
builder.addHtml(String.format("%1$d / 10", issue.getPriority()));
builder.newline();
builder.addHeading("Category: ", headerFontColor);
builder.add(issue.getCategory().getFullName());
builder.newline();
builder.addHeading("Severity: ", headerFontColor);
builder.beginSpan();
// Use converted level instead of *default* severity such that we match any user configured overrides
HighlightDisplayLevel level = selected.level;
builder.add(StringUtil.capitalize(level.getName().toLowerCase(Locale.US)));
builder.endSpan();
builder.newline();
builder.addHeading("Explanation: ", headerFontColor);
String description = issue.getBriefDescription(HTML);
builder.addHtml(description);
if (!description.isEmpty() && Character.isLetter(description.charAt(description.length() - 1))) {
builder.addHtml(".");
}
builder.newline();
String explanationHtml = issue.getExplanation(HTML);
builder.addHtml(explanationHtml);
List<String> moreInfo = issue.getMoreInfo();
builder.newline();
int count = moreInfo.size();
if (count > 1) {
builder.addHeading("More Info: ", headerFontColor);
builder.beginList();
}
for (String uri : moreInfo) {
if (count > 1) {
builder.listItem();
}
builder.addLink(uri, uri);
}
if (count > 1) {
builder.endList();
}
builder.newline();
}
builder.closeHtmlBody();
try {
myExplanationPane.read(new StringReader(builder.getHtml()), null);
HtmlBuilderHelper.fixFontStyles(myExplanationPane);
myExplanationPane.setCaretPosition(0);
} catch (IOException ignore) {
// can't happen for internal string reading
}
}
Aggregations