Search in sources :

Example 1 with IdeValidationHost

use of com.intellij.codeInsight.daemon.IdeValidationHost in project intellij-plugins by JetBrains.

the class MxmlLanguageTagsUtil method addErrorMessage.

private static void addErrorMessage(final XmlElement element, final String message, final Validator.ValidationHost host, @NotNull IntentionAction... intentionActions) {
    PsiElement target = element;
    PsiElement secondaryTarget = null;
    if (element instanceof XmlAttributeValue) {
        final ASTNode node = element.getNode();
        final ASTNode value = node == null ? null : XmlChildRole.ATTRIBUTE_VALUE_VALUE_FINDER.findChild(node);
        if (value instanceof PsiElement) {
            target = (PsiElement) value;
        }
    } else if (element instanceof XmlAttributeImpl) {
        target = ((XmlAttributeImpl) element).getNameElement();
    } else if (element instanceof XmlTag) {
        target = XmlTagUtil.getStartTagNameElement((XmlTag) element);
        secondaryTarget = XmlTagUtil.getEndTagNameElement((XmlTag) element);
    }
    if (host instanceof IdeValidationHost) {
        if (target != null) {
            ((IdeValidationHost) host).addMessageWithFixes(target, message, Validator.ValidationHost.ErrorType.ERROR, intentionActions);
        }
        if (secondaryTarget != null) {
            ((IdeValidationHost) host).addMessageWithFixes(secondaryTarget, message, Validator.ValidationHost.ErrorType.ERROR, intentionActions);
        }
    } else {
        if (target != null) {
            host.addMessage(target, message, Validator.ValidationHost.ErrorType.ERROR);
        }
        if (secondaryTarget != null) {
            host.addMessage(secondaryTarget, message, Validator.ValidationHost.ErrorType.ERROR);
        }
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) XmlAttributeImpl(com.intellij.psi.impl.source.xml.XmlAttributeImpl) IdeValidationHost(com.intellij.codeInsight.daemon.IdeValidationHost) PsiElement(com.intellij.psi.PsiElement)

Aggregations

IdeValidationHost (com.intellij.codeInsight.daemon.IdeValidationHost)1 ASTNode (com.intellij.lang.ASTNode)1 PsiElement (com.intellij.psi.PsiElement)1 XmlAttributeImpl (com.intellij.psi.impl.source.xml.XmlAttributeImpl)1