Package com.google.caja.reporting

Examples of com.google.caja.reporting.Message


          }
          escaped = !escaped && ch2 == '\\';
        }
        if (!closed) {
          throw new ParseException(
              new Message(
                  MessageType.UNTERMINATED_STRING_TOKEN,
                  p.filePositionForOffsets(start, end)));
        }
        type = JsTokenType.STRING;
        break;
      }
      case '/':
      {
        if (end == limit) {
          type = JsTokenType.PUNCTUATION;
        } else {
          char ch2 = buf[end];
          switch (ch2) {
          case '/':
            while (end < limit && !JsLexer.isJsLineSeparator(buf[end])) {
              ++end;
            }
            type = JsTokenType.COMMENT;
            break;
          case '*':
            {
              boolean star = false;
              boolean closed = false;
              while (++end < limit) {
                ch2 = buf[end];
                if (star && '/' == ch2) {
                  closed = true;
                  ++end;
                  break;
                } else {
                  star = (ch2 == '*') && !tokenBreak(end);
                }
              }
              if (!closed) {
                throw new ParseException(
                    new Message(MessageType.UNTERMINATED_STRING_TOKEN,
                        p.filePositionForOffsets(start, p.getOffset())));
              }
              type = JsTokenType.COMMENT;
            }
            break;
          default:
            {
              if (lastNonCommentToken == null
                  || JsLexer.isRegexp(lastNonCommentToken.text)) {
                boolean closed = false;
                boolean escaped = false;
                boolean inCharSet = false;

                regex_body:
                do {
                  ch2 = buf[end];
                  if (JsLexer.isJsLineSeparator(ch2)) {
                    // will register as unterminated token below
                    break;
                  } else if (!escaped) {
                    switch (ch2) {
                      case '/':
                        if (!inCharSet) {
                          closed = true;
                          ++end;
                          break regex_body;
                        }
                        break;
                      case '[':
                        inCharSet = true;
                        break;
                      case ']':
                        inCharSet = false;
                        break;
                      case '\\':
                        escaped = true;
                        break;
                    }
                  } else {
                    escaped = false;
                  }
                  ++end;
                } while (end < limit);
                if (!closed) {
                  throw new ParseException(
                      new Message(MessageType.UNTERMINATED_STRING_TOKEN,
                          p.filePositionForOffsets(start, end)));
                }
                // Pick up any modifiers at the end, e.g. /foo/g
                // Firefox fails on "/foo/instanceof RegExp" with an
                // invalid identifiers error, so just pick up all letters
View Full Code Here


  /** Throws a ParseException if the queue is not empty. */
  public void expectEmpty() throws ParseException {
    if (!isEmpty()) {
      throw new ParseException(
          new Message(MessageType.UNUSED_TOKENS,
              currentPosition(), MessagePart.Factory.valueOf(peek().text)));
    }
  }
View Full Code Here

    if (null == t) {
      eof = true;
      if (failOnEof) {
        throw new ParseException(
            new Message(MessageType.END_OF_FILE,
                        (null != inputRange ? this.inputRange : this.file)));
      }
      return;
    }
View Full Code Here

      t = peek();
    } catch (ParseException ex) {
      if (prev != null
          && ex.getCajaMessage().getMessageType() == MessageType.END_OF_FILE) {
        throw new ParseException(
            new Message(MessageType.EXPECTED_TOKEN,
                        FilePosition.endOf(prev.t.pos),
                        MessagePart.Factory.valueOf(text),
                        MessagePart.Factory.valueOf("EOF")));
      }
      throw ex;
    }
    if (t.text.equals(text)) {
      advance();
      return;
    }

    throw new ParseException(
        new Message(MessageType.EXPECTED_TOKEN, t.pos,
                    MessagePart.Factory.valueOf(text),
                    MessagePart.Factory.valueOf(t.text)));
  }
View Full Code Here

    if (t.type == tt) {
      advance();
      return t;
    }
    throw new ParseException(
        new Message(MessageType.EXPECTED_TOKEN, t.pos,
                    MessagePart.Factory.valueOf(tt.toString()),
                    MessagePart.Factory.valueOf(t.text)));
  }
View Full Code Here

        "type " + type + " and level " + level);
  }

  protected void assertMessage(
      boolean consume, Function<Message, Integer> scorer, String description) {
    Message closest = null;
    int closestScore = Integer.MIN_VALUE;
    for (Message msg : mq.getMessages()) {
      final int score = scorer.apply(msg);
      if (score == Integer.MAX_VALUE) {
        if (consume) {
          mq.getMessages().remove(msg);
        }
        return;
      }
      if (score > closestScore) {
        closest = msg;
        closestScore = score;
      }
    }
    if (closest == null) {
      fail("No message found like " + description);
    } else {
      fail("Failed to find message.  Closest match was " + closest.format(mc)
           + " with parts " + closest.getMessageParts());
    }
  }
View Full Code Here

        "<ihtml:template formals=\"a b\" name=\"t\"></ihtml:template>",
        ""
        + "<ihtml:template formals='a b' name='t'>"
        + "<ihtml:message>Hello</ihtml:message>"
        + "</ihtml:template>",
        new Message(IhtmlMessageType.MISSING_ATTRIB,
                    elKey("ihtml:message"), attrKey("ihtml:message", "name"),
                    FilePosition.instance(is, 1, 40, 40, 36))
        );
  }
View Full Code Here

        + "<ihtml:template formals=\"a b\" name=\"t\">"
        + "<ihtml:message name=\"x__\">"
        + "Hello"
        + "</ihtml:message>"
        + "</ihtml:template>",
        new Message(IhtmlMessageType.BAD_ATTRIB,
                    FilePosition.instance(is, 1, 55, 55, 10),
                    elKey("ihtml:message"), attrKey("ihtml:message", "name"),
                    MessagePart.Factory.valueOf("x__"))
        );
  }
View Full Code Here

        + "<ihtml:ph name=\"if\"/>"
        + "<ihtml:dynamic expr=\"planet\"/>"
        + "<ihtml:eph/>!"
        + "</ihtml:message>"
        + "</ihtml:template>",
        new Message(
            IhtmlMessageType.BAD_ATTRIB,
            FilePosition.instance(is, 1, 78, 78, 9),
            elKey("ihtml:ph"), attrKey("ihtml:ph", "name"),
            MessagePart.Factory.valueOf("if")),
        new Message(
            IhtmlMessageType.ORPHANED_PLACEHOLDER_END,
            FilePosition.instance(is, 1, 119, 119, 12)));
  }
View Full Code Here

        + "<ihtml:ph/>"
        + "<ihtml:dynamic expr=\"planet\"/>"
        + "<ihtml:eph/>!"
        + "</ihtml:message>"
        + "</ihtml:template>",
        new Message(
            IhtmlMessageType.MISSING_ATTRIB,
            elKey("ihtml:ph"),attrKey("ihtml:ph", "name"),
            FilePosition.instance(is, 1, 68, 68, 11)),
        new Message(
            IhtmlMessageType.ORPHANED_PLACEHOLDER_END,
            FilePosition.instance(is, 1, 109, 109, 12)));
  }
View Full Code Here

TOP

Related Classes of com.google.caja.reporting.Message

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.