Package com.google.caja.reporting

Examples of com.google.caja.reporting.SnippetProducer


  static MessageLevel reportErrors(
      Map<InputSource, CharSequence> inputs,
      MessageContext mc, MessageQueue mq, Appendable out)
      throws IOException {
    MessageLevel max = MessageLevel.values()[0];
    SnippetProducer sp = new SnippetProducer(inputs, mc);
    // HACK: do not commit
    Map<MessageTypeInt, Integer> counts = Maps.newHashMap();
    for (Message msg : sortMessages(mq.getMessages())) {
      counts.put(
          msg.getMessageType(),
          Integer.valueOf(counts.containsKey(msg.getMessageType())
                          ? counts.get(msg.getMessageType()) + 1
                          : 1));
      MessageLevel level = msg.getMessageLevel();
      if (level.compareTo(max) > 0) { max = level; }
      String snippet = sp.getSnippet(msg);
      out.append(
          level.name() + " : " + msg.format(mc)
          + ("".equals(snippet) ? "" : "\n" + snippet) + "\n");
    }
View Full Code Here


    // From the ignore attribute to the <transform> element.
    Set<?> toIgnore = (Set<?>) options.get("toIgnore");
    if (toIgnore == null) { toIgnore = Collections.emptySet(); }

    // Log messages
    SnippetProducer snippetProducer = new SnippetProducer(originalSources, mc);
    for (Message msg : mq.getMessages()) {
      if (passed && MessageLevel.LOG.compareTo(msg.getMessageLevel()) >= 0) {
        continue;
      }
      String snippet = snippetProducer.getSnippet(msg);
      if (!"".equals(snippet)) { snippet = "\n" + snippet; }
      if (!passed || !toIgnore.contains(msg.getMessageType().name())) {
        logger.println(
            msg.getMessageLevel() + " : " + msg.format(mc) + snippet);
      }
View Full Code Here

      CharSequence orig, MessageQueue mq, boolean visible) {
    MessageContext mc = new MessageContext();
    Map<InputSource, CharSequence> originalSrc = Maps.newHashMap();
    originalSrc.put(is, orig);
    mc.addInputSource(is);
    SnippetProducer sp = new SnippetProducer(originalSrc, mc);

    Element errElement = doc.createElement("ul");
    // Style defined in gadgets.css
    errElement.setAttribute("class", "gadgets-messages");
    if (!visible) {
      errElement.setAttribute("style", "display: none");
    }
    for (Message msg : mq.getMessages()) {
      // Ignore LINT messages
      if (MessageLevel.LINT.compareTo(msg.getMessageLevel()) <= 0) {
        String snippet = sp.getSnippet(msg);
        String messageText = msg.getMessageLevel().name() + ' ' +
          html(msg.format(mc)) + ':' + snippet;
        Element li = doc.createElement("li");
        li.appendChild(doc.createTextNode(messageText));
        errElement.appendChild(li);
View Full Code Here

  private StyleSheet parseString(String fuzzString) throws Exception {
    return css(fromString(fuzzString));
  }

  private String renderSnippets(Map<InputSource, String> srcs) {
    SnippetProducer sr = new SnippetProducer(srcs, mc, 80);
    List<Message> messages = new ArrayList<Message>(mq.getMessages());
    Collections.sort(messages, new Comparator<Message>() {
      public int compare(Message a, Message b) {
        FilePosition fpa = firstFilePosition(a.getMessageParts());
        FilePosition fpb = firstFilePosition(b.getMessageParts());
        int delta = fpa.startCharInFile() - fpb.startCharInFile();
        if (delta == 0) {
          delta = fpa.endCharInFile() - fpb.endCharInFile();
        }
        return delta;
      }
      private FilePosition firstFilePosition(List<MessagePart> parts) {
        if (parts.isEmpty()) { return FilePosition.UNKNOWN; }
        MessagePart p0 = parts.get(0);
        return p0 instanceof FilePosition
            ? (FilePosition) p0
            : FilePosition.UNKNOWN;
      }
    });
    List<String> snippets = new ArrayList<String>();
    for (Message msg : messages) {
      snippets.add(msg.getMessageLevel() + " : " + msg.format(mc));
      snippets.add(sr.getSnippet(msg));
    }
    return Join.join("\n", snippets);
  }
View Full Code Here

    // From the ignore attribute to the <transform> element.
    Set<?> toIgnore = (Set<?>) options.get("toIgnore");
    if (toIgnore == null) { toIgnore = Collections.emptySet(); }

    // Log messages
    SnippetProducer snippetProducer = new SnippetProducer(originalSources, mc);
    for (Message msg : mq.getMessages()) {
      if (passed && MessageLevel.LOG.compareTo(msg.getMessageLevel()) >= 0) {
        continue;
      }
      String snippet = snippetProducer.getSnippet(msg);
      if (!"".equals(snippet)) { snippet = "\n" + snippet; }
      if (!passed || !toIgnore.contains(msg.getMessageType().name())) {
        logger.println(
            msg.getMessageLevel() + " : " + msg.format(mc) + snippet);
      }
View Full Code Here

  static MessageLevel reportErrors(
      Map<InputSource, CharSequence> inputs,
      MessageContext mc, MessageQueue mq, Appendable out)
      throws IOException {
    MessageLevel max = MessageLevel.values()[0];
    SnippetProducer sp = new SnippetProducer(inputs, mc);
    // HACK: do not commit
    Map<MessageTypeInt, Integer> counts = Maps.newHashMap();
    for (Message msg : sortMessages(mq.getMessages())) {
      counts.put(
          msg.getMessageType(),
          Integer.valueOf(counts.containsKey(msg.getMessageType())
                          ? counts.get(msg.getMessageType()) + 1
                          : 1));
      MessageLevel level = msg.getMessageLevel();
      if (level.compareTo(max) > 0) { max = level; }
      String snippet = sp.getSnippet(msg);
      out.append(
          level.name() + " : " + msg.format(mc)
          + (snippet != null ? "\n" + snippet : "") + "\n");
    }
View Full Code Here

  private String[] formatMessages(
      Map<InputSource, ? extends CharSequence> inputMap,
      MessageContext mc, MessageQueue mq) {
    List<Message> messages = mq.getMessages();
    SnippetProducer sp = new HtmlSnippetProducer(inputMap, mc);
    List<String> result = Lists.newArrayList();

    for (Message msg : messages) {
      String snippet = sp.getSnippet(msg);
      StringBuilder messageText = new StringBuilder();
      messageText.append(msg.getMessageLevel().name())
                 .append(" ")
                 .append(msg.format(mc));
      messageText.append(":").append(snippet);
View Full Code Here

TOP

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

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.