Java Code Examples for com.intellij.psi.xml.XmlTokenType.XML_TAG_END

The following are Jave code examples for showing how to use XML_TAG_END of the com.intellij.psi.xml.XmlTokenType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: intellij-ce-playground   File: HtmlParsing.java   Source Code and License Vote up 6 votes
private void parseHeader(String tagName) {
  boolean freeMakerTag = !tagName.isEmpty() && '#' == tagName.charAt(0);

  do {
    final IElementType tt = token();
    if (freeMakerTag) {
      if (tt == XmlTokenType.XML_EMPTY_ELEMENT_END ||
          tt == XmlTokenType.XML_TAG_END ||
          tt == XmlTokenType.XML_END_TAG_START ||
          tt == XmlTokenType.XML_START_TAG_START) break;
      advance();
    }
    else {
      if (tt == XmlTokenType.XML_NAME) {
        parseAttribute();
      }
      else if (tt == XmlTokenType.XML_CHAR_ENTITY_REF || tt == XmlTokenType.XML_ENTITY_REF_TOKEN) {
        parseReference();
      }
      else {
        break;
      }
    }
  }
  while (!eof());
}
 
Example 2
Project: intellij-ce-playground   File: XmlParser.java   Source Code and License Vote up 6 votes
@Override
public ThreeState fun(ASTNode oldNode,
                      LighterASTNode newNode,
                      FlyweightCapableTreeStructure<LighterASTNode> structure) {
  if (oldNode instanceof XmlTag && newNode.getTokenType() == XmlElementType.XML_TAG) {
    String oldName = ((XmlTag)oldNode).getName();
    Ref<LighterASTNode[]> childrenRef = Ref.create(null);
    int count = structure.getChildren(newNode, childrenRef);
    if (count < 3) return ThreeState.UNSURE;
    LighterASTNode[] children = childrenRef.get();
    if (children[0].getTokenType() != XmlTokenType.XML_START_TAG_START) return ThreeState.UNSURE;
    if (children[1].getTokenType() != XmlTokenType.XML_NAME) return ThreeState.UNSURE;
    if (children[2].getTokenType() != XmlTokenType.XML_TAG_END) return ThreeState.UNSURE;
    LighterASTTokenNode name = (LighterASTTokenNode)children[1];
    CharSequence newName = name.getText();
    if (!Comparing.equal(oldName, newName)) return ThreeState.NO;
  }

  return ThreeState.UNSURE;
}
 
Example 3
Project: intellij-ce-playground   File: TagDeclarationRangeHandler.java   Source Code and License Vote up 6 votes
@Override
@NotNull
public TextRange getDeclarationRange(@NotNull final PsiElement container) {
  XmlTag xmlTag = (XmlTag)container;
  int endOffset = xmlTag.getTextRange().getStartOffset();

  for (PsiElement child = xmlTag.getFirstChild(); child != null; child = child.getNextSibling()) {
    endOffset = child.getTextRange().getEndOffset();
    if (child instanceof XmlToken) {
      XmlToken token = (XmlToken)child;
      IElementType tokenType = token.getTokenType();
      if (tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END || tokenType == XmlTokenType.XML_TAG_END) break;
    }
  }

  return new TextRange(xmlTag.getTextRange().getStartOffset(), endOffset);
}
 
Example 4
Project: intellij-ce-playground   File: XmlTagTreeHighlightingPass.java   Source Code and License Vote up 6 votes
@Nullable
private static TextRange getStartTagRange(ASTNode tagNode) {
  final ASTNode startTagStart = XmlChildRole.START_TAG_START_FINDER.findChild(tagNode);
  if (startTagStart == null) {
    return null;
  }

  ASTNode tagName = startTagStart.getTreeNext();
  if (tagName == null || tagName.getElementType() != XmlTokenType.XML_NAME) {
    return null;
  }

  ASTNode next = tagName.getTreeNext();
  if (next != null && next.getElementType() == XmlTokenType.XML_TAG_END) {
    tagName = next;
  }

  return new TextRange(startTagStart.getStartOffset(), tagName.getTextRange().getEndOffset());
}
 
Example 5
Project: intellij-ce-playground   File: XmlTagTreeHighlightingPass.java   Source Code and License Vote up 6 votes
@Nullable
private static TextRange getEndTagRange(ASTNode tagNode) {
  final ASTNode endTagStart = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(tagNode);
  if (endTagStart == null) {
    return null;
  }

  ASTNode endTagEnd = endTagStart;
  while (endTagEnd != null && endTagEnd.getElementType() != XmlTokenType.XML_TAG_END) {
    endTagEnd = endTagEnd.getTreeNext();
  }

  if (endTagEnd == null) {
    return null;
  }

  return new TextRange(endTagStart.getStartOffset(), endTagEnd.getTextRange().getEndOffset());
}
 
Example 6
Project: intellij-ce-playground   File: XmlTagUtil.java   Source Code and License Vote up 6 votes
private static TextRange getTag(XmlToken tagName, IElementType tagStart) {
  if (tagName != null) {
    PsiElement s = tagName.getPrevSibling();

    while (s != null && s.getNode().getElementType() != tagStart) {
      s = s.getPrevSibling();
    }

    PsiElement f = tagName.getNextSibling();

    while (f != null &&
           !(f.getNode().getElementType() == XmlTokenType.XML_TAG_END ||
             f.getNode().getElementType() == XmlTokenType.XML_EMPTY_ELEMENT_END)) {
      f = f.getNextSibling();
    }
    if (s != null && f != null) {
      return new TextRange(s.getTextRange().getStartOffset(), f.getTextRange().getEndOffset());
    }
  }
  return null;
}
 
Example 7
Project: intellij-ce-playground   File: EnterBetweenXmlTagsHandler.java   Source Code and License Vote up 6 votes
private static boolean isAtTheEndOfEmptyTag(Project project, Editor editor, PsiFile file, HighlighterIterator iterator) {
  if (iterator.getTokenType() != XmlTokenType.XML_TAG_END) {
    return false;
  }

  PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
  final PsiElement element = file.findElementAt(iterator.getStart());

  if (element == null) {
    return false;
  }

  final PsiElement parent = element.getParent();
  return parent instanceof XmlTag &&
         parent.getTextRange().getEndOffset() == iterator.getEnd();
}
 
Example 8
Project: intellij-ce-playground   File: XmlBraceMatcher.java   Source Code and License Vote up 6 votes
private static boolean findEndTagStart(HighlighterIterator iterator) {
  IElementType tokenType = iterator.getTokenType();
  int balance = 0;
  int count = 0;
  while(balance >= 0){
    iterator.retreat();
    count++;
    if (iterator.atEnd()) break;
    tokenType = iterator.getTokenType();
    if (tokenType == XmlTokenType.XML_TAG_END || tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END){
      balance++;
    }
    else if (tokenType == XmlTokenType.XML_END_TAG_START || tokenType == XmlTokenType.XML_START_TAG_START){
      balance--;
    }
  }
  while(count-- > 0) iterator.advance();
  return tokenType == XmlTokenType.XML_END_TAG_START;
}
 
Example 9
Project: intellij-ce-playground   File: HtmlParsing.java   Source Code and License Vote up 5 votes
private void parseAttributeValue() {
  final PsiBuilder.Marker attValue = mark();
  if (token() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER) {
    while (true) {
      final IElementType tt = token();
      if (tt == null || tt == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER || tt == XmlTokenType.XML_END_TAG_START || tt == XmlTokenType
        .XML_EMPTY_ELEMENT_END ||
          tt == XmlTokenType.XML_START_TAG_START) {
        break;
      }

      if (tt == XmlTokenType.XML_BAD_CHARACTER) {
        final PsiBuilder.Marker error = mark();
        advance();
        error.error(XmlErrorMessages.message("unescaped.ampersand.or.nonterminated.character.entity.reference"));
      }
      else if (tt == XmlTokenType.XML_ENTITY_REF_TOKEN) {
        parseReference();
      }
      else {
        advance();
      }
    }

    if (token() == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
      advance();
    }
    else {
      error(XmlErrorMessages.message("xml.parsing.unclosed.attribute.value"));
    }
  }
  else {
    if (token() != XmlTokenType.XML_TAG_END && token() != XmlTokenType.XML_EMPTY_ELEMENT_END) {
      advance(); // Single token att value
    }
  }

  attValue.done(XmlElementType.XML_ATTRIBUTE_VALUE);
}
 
Example 10
Project: intellij-ce-playground   File: XmlParameterInfoHandler.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 11
Project: intellij-ce-playground   File: DtdSelectioner.java   Source Code and License Vote up 5 votes
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor 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_TAG_END) {
        last = token;
        break;
      }
      if (token.getTokenType() == XmlTokenType.XML_ELEMENT_DECL_START ||
          token.getTokenType() == XmlTokenType.XML_ATTLIST_DECL_START
         ) {
        first = token;
      }
    }
  }

  List<TextRange> result = new ArrayList<TextRange>(1);
  if (first != null && last != null) {
    final int offset = last.getTextRange().getEndOffset() + 1;
      result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText,
                                      new TextRange(first.getTextRange().getStartOffset(), offset < editorText.length() ? offset:editorText.length()),
                                      false));
  }

  return result;
}
 
Example 12
Project: intellij-ce-playground   File: XmlTokenSelectioner.java   Source Code and License Vote up 5 votes
static boolean shouldSelectToken(final XmlToken token) {
  return token.getTokenType() != XmlTokenType.XML_DATA_CHARACTERS &&
        token.getTokenType() != XmlTokenType.XML_START_TAG_START &&
        token.getTokenType() != XmlTokenType.XML_END_TAG_START &&
        token.getTokenType() != XmlTokenType.XML_EMPTY_ELEMENT_END &&
        token.getTokenType() != XmlTokenType.XML_TAG_END;
}
 
Example 13
Project: intellij-ce-playground   File: XmlBraceMatcher.java   Source Code and License Vote up 5 votes
@Override
public boolean isRBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
  final IElementType tokenType = iterator.getTokenType();
  PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(tokenType.getLanguage());
  if (matcher != null) {
    BracePair[] pairs = matcher.getPairs();
    for (BracePair pair : pairs) {
      if (pair.getRightBraceType() == tokenType) return true;
    }
  }

  if (tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END ||
      tokenType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER ||
      tokenType == XmlTokenType.XML_CDATA_END)
  {
    return true;
  }
  else if (tokenType == XmlTokenType.XML_TAG_END) {
    final boolean result = findEndTagStart(iterator);

    if (isFileTypeWithSingleHtmlTags(fileType)) {
      final String tagName = getTagName(fileText, iterator);

      if (tagName != null && HtmlUtil.isSingleHtmlTag(tagName)) {
        return !result;
      }
    }

    return result;
  }
  else {
    return false;
  }
}
 
Example 14
Project: intellij-ce-playground   File: XmlWhiteSpaceFormattingStrategy.java   Source Code and License Vote up 5 votes
protected boolean isInsideTagBody(@NotNull ASTNode place) {
  final ASTNode treeParent = place.getTreeParent();
  if(treeParent.getElementType() != XmlElementType.XML_TAG
     && treeParent.getElementType() != XmlElementType.HTML_TAG) return false;
  while(place != null){
    if(place.getElementType() == XmlTokenType.XML_TAG_END) return true;
    place = place.getTreePrev();
  }
  return false;
}
 
Example 15
Project: intellij-ce-playground   File: AbstractSyntheticBlock.java   Source Code and License Vote up 4 votes
protected static boolean isXmlTagName(final IElementType type1, final IElementType type2) {
  if (type1 == XmlTokenType.XML_NAME && type2 == XmlTokenType.XML_TAG_END) return true;
  if (type1 == XmlTokenType.XML_NAME && type2 == XmlTokenType.XML_EMPTY_ELEMENT_END) return true;
  if (type1 == XmlElementType.XML_ATTRIBUTE && type2 == XmlTokenType.XML_EMPTY_ELEMENT_END) return true;
  return type1 == XmlElementType.XML_ATTRIBUTE && type2 == XmlTokenType.XML_TAG_END;
}
 
Example 16
Project: intellij-ce-playground   File: HtmlParsing.java   Source Code and License Vote up 4 votes
public void parseDocument() {
  final PsiBuilder.Marker document = mark();

  while (token() == XmlTokenType.XML_COMMENT_START) {
    parseComment();
  }

  parseProlog();

  PsiBuilder.Marker error = null;
  while (!eof()) {
    final IElementType tt = token();
    if (tt == XmlTokenType.XML_START_TAG_START) {
      error = flushError(error);
      parseTag();
      myTagMarkersStack.clear();
      myTagNamesStack.clear();
    }
    else if (tt == XmlTokenType.XML_COMMENT_START) {
      error = flushError(error);
      parseComment();
    }
    else if (tt == XmlTokenType.XML_PI_START) {
      error = flushError(error);
      parseProcessingInstruction();
    }
    else if (tt == XmlTokenType.XML_CHAR_ENTITY_REF || tt == XmlTokenType.XML_ENTITY_REF_TOKEN) {
      parseReference();
    }
    else if (tt == XmlTokenType.XML_REAL_WHITE_SPACE || tt == XmlTokenType.XML_DATA_CHARACTERS) {
      error = flushError(error);
      advance();
    } else if (tt == XmlTokenType.XML_END_TAG_START) {
      final PsiBuilder.Marker tagEndError = myBuilder.mark();

      advance();
      if (token() == XmlTokenType.XML_NAME) {
        advance();
        if (token() == XmlTokenType.XML_TAG_END) {
          advance();
        }
      }

      tagEndError.error(XmlErrorMessages.message("xml.parsing.closing.tag.matches.nothing"));
    }
    else {
      if (error == null) error = mark();
      advance();
    }
  }

  if (error != null) {
    error.error(XmlErrorMessages.message("top.level.element.is.not.completed"));
  }

  document.done(XmlElementType.HTML_DOCUMENT);
}
 
Example 17
Project: intellij-ce-playground   File: XmlTagTreeHighlightingPass.java   Source Code and License Vote up 4 votes
private static boolean isTagStartOrEnd(@Nullable PsiElement element) {
  if (element == null) return false;
  final IElementType type = element.getNode().getElementType();
  if (type == XmlTokenType.XML_NAME) return isTagStartOrEnd(element.getNextSibling()) || isTagStartOrEnd(element.getPrevSibling());
  return type == XmlTokenType.XML_START_TAG_START || type == XmlTokenType.XML_END_TAG_START || type == XmlTokenType.XML_TAG_END;
}
 
Example 18
Project: intellij-ce-playground   File: AbstractSyntheticBlock.java   Source Code and License Vote up 4 votes
private boolean isEndOfTag() {
  return myEndTreeNode.getElementType() == XmlTokenType.XML_TAG_END;
}
 
Example 19
Project: intellij-ce-playground   File: XmlBraceMatcher.java   Source Code and License Vote up 4 votes
protected boolean isXmlStructuralBrace(HighlighterIterator iterator, CharSequence text, FileType fileType, IElementType tokenType) {
  return tokenType == XmlTokenType.XML_START_TAG_START ||
         tokenType == XmlTokenType.XML_TAG_END ||
         tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END ||
         tokenType == XmlTokenType.XML_TAG_END && isFileTypeWithSingleHtmlTags(fileType) && isEndOfSingleHtmlTag(text, iterator);
}
 
Example 20
Project: intellij-ce-playground   File: XmlTagBlock.java   Source Code and License Vote up 4 votes
@Override
protected List<Block> buildChildren() {
  ASTNode child = myNode.getFirstChildNode();
  final Wrap attrWrap = Wrap.createWrap(getWrapType(myXmlFormattingPolicy.getAttributesWrap()), false);
  final Wrap textWrap = Wrap.createWrap(getWrapType(myXmlFormattingPolicy.getTextWrap(getTag())), true);
  final Wrap tagBeginWrap = createTagBeginWrapping(getTag());
  final Alignment attrAlignment = Alignment.createAlignment();
  final Alignment textAlignment = Alignment.createAlignment();
  final ArrayList<Block> result = new ArrayList<Block>(3);
  ArrayList<Block> localResult = new ArrayList<Block>(1);

  boolean insideTag = true;

  while (child != null) {
    if (!containsWhiteSpacesOnly(child) && child.getTextLength() > 0){

      Wrap wrap = chooseWrap(child, tagBeginWrap, attrWrap, textWrap);
      Alignment alignment = chooseAlignment(child, attrAlignment, textAlignment);

      if (child.getElementType() == XmlTokenType.XML_TAG_END) {
        child = processChild(localResult,child, wrap, alignment, Indent.getNoneIndent());
        result.add(createTagDescriptionNode(localResult));
        localResult = new ArrayList<Block>(1);
        insideTag = true;
      }
      else if (child.getElementType() == XmlTokenType.XML_START_TAG_START) {
        insideTag = false;
        if (!localResult.isEmpty()) {
          result.add(createTagContentNode(localResult));
        }
        localResult = new ArrayList<Block>(1);
        child = processChild(localResult,child, wrap, alignment, null);
      }
      else if (child.getElementType() == XmlTokenType.XML_END_TAG_START) {
        insideTag = false;
        if (!localResult.isEmpty()) {
          result.add(createTagContentNode(localResult));
          localResult = new ArrayList<Block>(1);
        }
        child = processChild(localResult,child, wrap, alignment, null);
      } else if (child.getElementType() == XmlTokenType.XML_EMPTY_ELEMENT_END) {
        child = processChild(localResult,child, wrap, alignment, Indent.getNoneIndent());
        result.add(createTagDescriptionNode(localResult));
        localResult = new ArrayList<Block>(1);
      }
      else if (isJspxJavaContainingNode(child)) {
        createJspTextNode(localResult, child, getChildIndent());
      }
      /*
      else if (child.getElementType() == ElementType.XML_TEXT) {
        child  = createXmlTextBlocks(localResult, child, wrap, alignment);
      }
      */
      else {
        final Indent indent;

        if (isJspResult(localResult)) {
          //indent = FormatterEx.getInstance().getNoneIndent();
          indent = getChildrenIndent();
        } else if (!insideTag) {
          indent = null;
        }
        else {
          indent = getChildrenIndent();
        }

        child = processChild(localResult,child, wrap, alignment, indent);
      }
    }
    if (child != null) {
      child = child.getTreeNext();
    }
  }

  if (!localResult.isEmpty()) {
    result.add(createTagContentNode(localResult));
  }

  return result;

}