Search in sources :

Example 21 with HighlightInfoType

use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.

the class GrInspectionUtil method createAnnotationForRef.

public static HighlightInfo createAnnotationForRef(@NotNull GrReferenceElement ref, @NotNull HighlightDisplayLevel displayLevel, @NotNull String message) {
    PsiElement refNameElement = ref.getReferenceNameElement();
    assert refNameElement != null;
    if (displayLevel == HighlightDisplayLevel.ERROR) {
        return HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(refNameElement).descriptionAndTooltip(message).create();
    }
    if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
        boolean isTestMode = ApplicationManager.getApplication().isUnitTestMode();
        HighlightInfoType infotype = isTestMode ? HighlightInfoType.WARNING : HighlightInfoType.INFORMATION;
        HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(infotype).range(refNameElement);
        builder.descriptionAndTooltip(message);
        return builder.needsUpdateOnTyping(false).textAttributes(GroovySyntaxHighlighter.UNRESOLVED_ACCESS).create();
    }
    HighlightInfoType highlightInfoType = HighlightInfo.convertSeverity(displayLevel.getSeverity());
    return HighlightInfo.newHighlightInfo(highlightInfoType).range(refNameElement).descriptionAndTooltip(message).create();
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) PsiElement(com.intellij.psi.PsiElement)

Example 22 with HighlightInfoType

use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.

the class XmlHighlightVisitor method addMessageWithFixes.

@Override
public void addMessageWithFixes(final PsiElement context, final String message, @NotNull final ErrorType type, @NotNull final IntentionAction... fixes) {
    if (message != null && !message.isEmpty()) {
        final PsiFile containingFile = context.getContainingFile();
        final HighlightInfoType defaultInfoType = type == ErrorType.ERROR ? HighlightInfoType.ERROR : type == ErrorType.WARNING ? HighlightInfoType.WARNING : HighlightInfoType.WEAK_WARNING;
        if (context instanceof XmlTag && XmlExtension.getExtension(containingFile).shouldBeHighlightedAsTag((XmlTag) context)) {
            addElementsForTagWithManyQuickFixes((XmlTag) context, message, defaultInfoType, fixes);
        } else {
            final PsiElement contextOfFile = InjectedLanguageManager.getInstance(containingFile.getProject()).getInjectionHost(containingFile);
            final HighlightInfo highlightInfo;
            if (contextOfFile != null) {
                TextRange range = InjectedLanguageManager.getInstance(context.getProject()).injectedToHost(context, context.getTextRange());
                highlightInfo = HighlightInfo.newHighlightInfo(defaultInfoType).range(range).descriptionAndTooltip(message).create();
            } else {
                highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(context).descriptionAndTooltip(message).create();
            }
            for (final IntentionAction quickFixAction : fixes) {
                if (quickFixAction == null)
                    continue;
                QuickFixAction.registerQuickFixAction(highlightInfo, quickFixAction);
            }
            addToResults(highlightInfo);
        }
    }
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType)

Aggregations

HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)22 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)14 TextRange (com.intellij.openapi.util.TextRange)8 Nullable (org.jetbrains.annotations.Nullable)6 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)5 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)4 SeveritiesProvider (com.intellij.codeInsight.daemon.impl.SeveritiesProvider)3 NotNull (org.jetbrains.annotations.NotNull)3 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)2 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)2 QuickFixActionRegistrarImpl (com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl)1 SeverityEditorDialog (com.intellij.codeInspection.ex.SeverityEditorDialog)1 ASTNode (com.intellij.lang.ASTNode)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Module (com.intellij.openapi.module.Module)1 AttributesDescriptor (com.intellij.openapi.options.colors.AttributesDescriptor)1