Search in sources :

Example 26 with XmlToken

use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.

the class XmlParameterInfoHandler method findXmlTag.

@Nullable
private static XmlTag findXmlTag(PsiFile file, int offset) {
    if (!(file instanceof XmlFile))
        return null;
    PsiElement element = file.findElementAt(offset);
    if (element == null)
        return null;
    element = element.getParent();
    while (element != null) {
        if (element instanceof XmlTag) {
            XmlTag tag = (XmlTag) element;
            final PsiElement[] children = tag.getChildren();
            if (offset <= children[0].getTextRange().getStartOffset())
                return null;
            for (PsiElement child : children) {
                final TextRange range = child.getTextRange();
                if (range.getStartOffset() <= offset && range.getEndOffset() > offset)
                    return tag;
                if (child instanceof XmlToken) {
                    XmlToken token = (XmlToken) child;
                    if (token.getTokenType() == XmlTokenType.XML_TAG_END)
                        return null;
                }
            }
            return null;
        }
        element = element.getParent();
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) XmlToken(com.intellij.psi.xml.XmlToken) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with XmlToken

use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.

the class XmlCDATAContentSelectioner method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
    PsiElement[] children = e.getChildren();
    PsiElement first = null;
    PsiElement last = null;
    for (PsiElement child : children) {
        if (child instanceof XmlToken) {
            XmlToken token = (XmlToken) child;
            if (token.getTokenType() == XmlTokenType.XML_CDATA_START) {
                first = token.getNextSibling();
            }
            if (token.getTokenType() == XmlTokenType.XML_CDATA_END) {
                last = token.getPrevSibling();
                break;
            }
        }
    }
    if (first != null && last != null) {
        result.addAll(expandToWholeLine(editorText, new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset()), false));
    }
    return result;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) CompositePsiElement(com.intellij.psi.impl.source.tree.CompositePsiElement) XmlToken(com.intellij.psi.xml.XmlToken)

Example 28 with XmlToken

use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.

the class XmlWrongClosingTagNameInspection method annotate.

@Override
public void annotate(@NotNull final PsiElement psiElement, @NotNull final AnnotationHolder holder) {
    if (psiElement instanceof XmlToken) {
        final PsiElement parent = psiElement.getParent();
        if (parent instanceof XmlTag) {
            final XmlTag tag = (XmlTag) parent;
            final XmlToken start = XmlTagUtil.getStartTagNameElement(tag);
            XmlToken endTagName = XmlTagUtil.getEndTagNameElement(tag);
            if (start == psiElement) {
                if (endTagName != null && !(tag instanceof HtmlTag) && !tag.getName().equals(endTagName.getText())) {
                    registerProblemStart(holder, tag, start, endTagName);
                } else if (endTagName == null && !(tag instanceof HtmlTag && HtmlUtil.isSingleHtmlTag(tag.getName()))) {
                    final PsiErrorElement errorElement = PsiTreeUtil.getChildOfType(tag, PsiErrorElement.class);
                    endTagName = findEndTagName(errorElement);
                    if (endTagName != null) {
                        registerProblemStart(holder, tag, start, endTagName);
                    }
                }
            } else if (endTagName == psiElement) {
                if (!(tag instanceof HtmlTag) && !tag.getName().equals(endTagName.getText())) {
                    registerProblemEnd(holder, tag, endTagName);
                }
            }
        } else if (parent instanceof PsiErrorElement) {
            if (XmlTokenType.XML_NAME == ((XmlToken) psiElement).getTokenType()) {
                final PsiFile psiFile = psiElement.getContainingFile();
                if (psiFile != null && (HTMLLanguage.INSTANCE == psiFile.getViewProvider().getBaseLanguage() || HTMLLanguage.INSTANCE == parent.getLanguage())) {
                    final String message = XmlErrorMessages.message("xml.parsing.closing.tag.matches.nothing");
                    if (message.equals(((PsiErrorElement) parent).getErrorDescription()) && psiFile.getContext() == null) {
                        final Annotation annotation = holder.createWarningAnnotation(parent, message);
                        annotation.registerFix(new RemoveExtraClosingTagIntentionAction());
                    }
                }
            }
        }
    }
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) HtmlTag(com.intellij.psi.html.HtmlTag) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Annotation(com.intellij.lang.annotation.Annotation) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag)

Example 29 with XmlToken

use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.

the class XMLExternalAnnotator method addMessagesForTag.

private static void addMessagesForTag(XmlTag tag, String message, Validator.ValidationHost.ErrorType type, AnnotationHolder myHolder, IntentionAction... actions) {
    XmlToken childByRole = XmlTagUtil.getStartTagNameElement(tag);
    addMessagesForTreeChild(childByRole, type, message, myHolder, actions);
    childByRole = XmlTagUtil.getEndTagNameElement(tag);
    addMessagesForTreeChild(childByRole, type, message, myHolder, actions);
}
Also used : XmlToken(com.intellij.psi.xml.XmlToken)

Aggregations

XmlToken (com.intellij.psi.xml.XmlToken)29 PsiElement (com.intellij.psi.PsiElement)18 XmlTag (com.intellij.psi.xml.XmlTag)12 TextRange (com.intellij.openapi.util.TextRange)6 IElementType (com.intellij.psi.tree.IElementType)6 Nullable (org.jetbrains.annotations.Nullable)5 NotNull (org.jetbrains.annotations.NotNull)4 ASTNode (com.intellij.lang.ASTNode)3 Document (com.intellij.openapi.editor.Document)3 PsiErrorElement (com.intellij.psi.PsiErrorElement)3 XmlAttribute (com.intellij.psi.xml.XmlAttribute)3 ArrayList (java.util.ArrayList)3 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2 ResourceType (com.android.resources.ResourceType)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 HtmlTag (com.intellij.psi.html.HtmlTag)2