use of com.intellij.codeInsight.daemon.impl.analysis.ErrorQuickFixProvider in project intellij-community by JetBrains.
the class DefaultHighlightVisitor method createErrorElementInfo.
private static HighlightInfo createErrorElementInfo(@NotNull PsiErrorElement element) {
TextRange range = element.getTextRange();
String errorDescription = element.getErrorDescription();
if (!range.isEmpty()) {
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range);
if (errorDescription != null) {
builder.descriptionAndTooltip(errorDescription);
}
final HighlightInfo info = builder.create();
if (info != null) {
for (ErrorQuickFixProvider provider : Extensions.getExtensions(ErrorQuickFixProvider.EP_NAME)) {
provider.registerErrorQuickFix(element, info);
}
}
return info;
}
int offset = range.getStartOffset();
PsiFile containingFile = element.getContainingFile();
int fileLength = containingFile.getTextLength();
FileViewProvider viewProvider = containingFile.getViewProvider();
PsiElement elementAtOffset = viewProvider.findElementAt(offset, LanguageUtil.getRootLanguage(element));
String text = elementAtOffset == null ? null : elementAtOffset.getText();
HighlightInfo info;
if (offset < fileLength && text != null && !StringUtil.startsWithChar(text, '\n') && !StringUtil.startsWithChar(text, '\r')) {
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(offset, offset + 1);
if (errorDescription != null) {
builder.descriptionAndTooltip(errorDescription);
}
info = builder.create();
} else {
int start;
int end;
if (offset > 0) {
start = offset;
end = offset;
} else {
start = offset;
end = offset < fileLength ? offset + 1 : offset;
}
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element, start, end);
if (errorDescription != null) {
builder.descriptionAndTooltip(errorDescription);
}
builder.endOfLine();
info = builder.create();
}
return info;
}
Aggregations