Search in sources :

Example 1 with ErrorQuickFixProvider

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;
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) TextRange(com.intellij.openapi.util.TextRange) PsiFile(com.intellij.psi.PsiFile) ErrorQuickFixProvider(com.intellij.codeInsight.daemon.impl.analysis.ErrorQuickFixProvider) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ErrorQuickFixProvider (com.intellij.codeInsight.daemon.impl.analysis.ErrorQuickFixProvider)1 TextRange (com.intellij.openapi.util.TextRange)1 FileViewProvider (com.intellij.psi.FileViewProvider)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1