Search in sources :

Example 6 with XmlComment

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

the class HtmlConditionalCommentInjector method parseConditionalCommentBoundaries.

/**
   * Tries to parse given element as <a href="http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx">conditional comment</a>.
   * 
   * @param host  target element to parse
   * @return      {@code null} if given element is not a conditional comment;
   *              pair like {@code (conditional comment start element; conditional comment end element)} otherwise
   */
@Nullable
private static Pair<ASTNode, ASTNode> parseConditionalCommentBoundaries(@NotNull PsiElement host) {
    if (!(host instanceof XmlComment)) {
        return null;
    }
    final ASTNode comment = host.getNode();
    if (comment == null) {
        return null;
    }
    final ASTNode conditionalStart = comment.findChildByType(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_START_END));
    if (conditionalStart == null) {
        return null;
    }
    final ASTNode conditionalEnd = comment.findChildByType(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_END_START));
    if (conditionalEnd == null) {
        return null;
    }
    final ASTNode endOfEnd = comment.findChildByType(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_END));
    return endOfEnd == null ? null : Pair.create(conditionalStart, conditionalEnd);
}
Also used : XmlComment(com.intellij.psi.xml.XmlComment) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

XmlComment (com.intellij.psi.xml.XmlComment)6 PsiElement (com.intellij.psi.PsiElement)4 XmlProlog (com.intellij.psi.xml.XmlProlog)2 XmlTag (com.intellij.psi.xml.XmlTag)2 Nullable (org.jetbrains.annotations.Nullable)2 ASTNode (com.intellij.lang.ASTNode)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 XmlText (com.intellij.psi.xml.XmlText)1 NotNull (org.jetbrains.annotations.NotNull)1