Package com.google.dart.engine.html.scanner

Examples of com.google.dart.engine.html.scanner.Token


  }

  @Override
  public Void visitXmlAttributeNode(XmlAttributeNode node) {
    String name = node.getName();
    Token value = node.getValueToken();
    if (name.length() == 0) {
      writer.print("__");
    } else {
      writer.print(name);
    }
    writer.print("=");
    if (value == null) {
      writer.print("__");
    } else {
      writer.print(value.getLexeme());
    }
    return null;
  }
View Full Code Here


    if (tagNodes.size() != 0 || !tag.getLexeme().equals(SCRIPT)) {
      return false;
    }
    for (XmlAttributeNode attribute : attributes) {
      if (attribute.getName().equals(TYPE)) {
        Token valueToken = attribute.getValueToken();
        if (valueToken != null) {
          String value = valueToken.getLexeme();
          if (value.equals(APPLICATION_DART_IN_DOUBLE_QUOTES)
              || value.equals(APPLICATION_DART_IN_SINGLE_QUOTES)) {
            return true;
          }
        }
View Full Code Here

   *
   * @param type the type of token to be inserted (not {@code null})
   * @return the synthetic token that was inserted (not {@code null})
   */
  private Token insertSyntheticToken(TokenType type) {
    Token token = new Token(type, currentToken.getOffset(), "");
    currentToken.getPrevious().setNext(token);
    token.setNext(currentToken);
    return token;
  }
View Full Code Here

   * @return the attribute (not {@code null})
   */
  private XmlAttributeNode parseAttribute() {

    // Assume the current token is a tag
    Token name = currentToken;
    currentToken = currentToken.getNext();

    // Equals sign
    Token equals;
    if (currentToken.getType() == TokenType.EQ) {
      equals = currentToken;
      currentToken = currentToken.getNext();
    } else {
      reportUnexpectedToken();
      equals = insertSyntheticToken(EQ);
    }

    // String value
    Token value;
    if (currentToken.getType() == TokenType.STRING) {
      value = currentToken;
      currentToken = currentToken.getNext();
    } else {
      reportUnexpectedToken();
View Full Code Here

   * @return the tag node or {@code null} if none found
   */
  private XmlTagNode parseTagNode() {

    // Assume that the current node is a tag node start TokenType#LT
    Token nodeStart = currentToken;
    currentToken = currentToken.getNext();

    // Get the tag or create a synthetic tag and report an error
    Token tag;
    if (currentToken.getType() == TokenType.TAG) {
      tag = currentToken;
      currentToken = currentToken.getNext();
    } else {
      reportUnexpectedToken();
      tag = insertSyntheticToken(TAG);
    }

    // Parse the attributes
    List<XmlAttributeNode> attributes = parseAttributes();

    // Token ending attribute list
    Token attributeEnd;
    if (currentToken.getType() == GT || currentToken.getType() == SLASH_GT) {
      attributeEnd = currentToken;
      currentToken = currentToken.getNext();
    } else {
      reportUnexpectedToken();
      attributeEnd = insertSyntheticToken(SLASH_GT);
    }

    // If the node has no children, then return the node
    if (attributeEnd.getType() == SLASH_GT || isSelfClosing(tag)) {
      return createTagNode(
          nodeStart,
          tag,
          attributes,
          attributeEnd,
          XmlTagNode.NO_TAG_NODES,
          currentToken,
          null,
          attributeEnd);
    }

    // Parse the child tag nodes
    List<XmlTagNode> tagNodes = parseChildTagNodes();

    // Token ending child tag nodes
    Token contentEnd;
    if (currentToken.getType() == LT_SLASH) {
      contentEnd = currentToken;
      currentToken = currentToken.getNext();
    } else {
      // TODO (danrubel): handle self closing HTML elements by inserting synthetic tokens
      // but not reporting an error
      reportUnexpectedToken();
      contentEnd = insertSyntheticToken(LT_SLASH);
    }

    // Closing tag
    Token closingTag;
    if (currentToken.getType() == TAG) {
      closingTag = currentToken;
      currentToken = currentToken.getNext();
    } else {
      reportUnexpectedToken();
      closingTag = insertSyntheticToken(TAG);
    }

    // Token ending node
    Token nodeEnd;
    if (currentToken.getType() == GT) {
      nodeEnd = currentToken;
      currentToken = currentToken.getNext();
    } else {
      reportUnexpectedToken();
View Full Code Here

   * Return the number of characters in the node's source range.
   *
   * @return the number of characters in the node's source range
   */
  public int getLength() {
    Token beginToken = getBeginToken();
    Token endToken = getEndToken();
    if (beginToken == null || endToken == null) {
      return -1;
    }
    return endToken.getOffset() + endToken.getLength() - beginToken.getOffset();
  }
View Full Code Here

   *
   * @return the offset from the beginning of the file to the first character in the node's source
   *         range
   */
  public int getOffset() {
    Token beginToken = getBeginToken();
    if (beginToken == null) {
      return -1;
    }
    return getBeginToken().getOffset();
  }
View Full Code Here

    final XmlAttributeNode[] result = {null};
    try {
      htmlUnit.accept(new RecursiveXmlVisitor<Void>() {
        @Override
        public Void visitXmlAttributeNode(XmlAttributeNode node) {
          Token nameToken = node.getNameToken();
          if (nameToken.getOffset() <= offset && offset <= nameToken.getEnd()) {
            result[0] = node;
            throw new FoundAttributeNodeError();
          }
          return super.visitXmlAttributeNode(node);
        }
View Full Code Here

    // do we have an enclosing tag at all?
    if (node == null) {
      return null;
    }
    // is "offset" in the open tag?
    Token openTag = node.getTagToken();
    if (openTag.getOffset() <= offset && offset <= openTag.getEnd()) {
      return node;
    }
    // is "offset" in the open tag?
    Token closeTag = node.getClosingTag();
    if (closeTag != null && closeTag.getOffset() <= offset && offset <= closeTag.getEnd()) {
      return node;
    }
    // not on a tag name
    return null;
  }
View Full Code Here

  @Override
  public Void visitXmlAttributeNode(XmlAttributeNode node) {
    Element element = node.getElement();
    if (element != null) {
      Token nameToken = node.getNameToken();
      Location location = createLocationForToken(nameToken);
      store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, location);
    }
    return super.visitXmlAttributeNode(node);
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.html.scanner.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.