com.google.caja.reporting.SnippetProducer

Here are the examples of the java api class com.google.caja.reporting.SnippetProducer taken from open source projects.

1. ErrorReporter#reportErrors()

Project: caja
Source File: ErrorReporter.java
View license
/** Dumps error messages to the output stream. */
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");
    }
    List<Map.Entry<MessageTypeInt, Integer>> countsInOrder = Lists.newArrayList(counts.entrySet());
    Collections.sort(countsInOrder, new Comparator<Map.Entry<MessageTypeInt, Integer>>() {

        public int compare(Map.Entry<MessageTypeInt, Integer> a, Map.Entry<MessageTypeInt, Integer> b) {
            int delta = a.getValue() - b.getValue();
            if (delta != 0) {
                return delta;
            }
            return a.getKey().name().compareTo(b.getKey().name());
        }
    });
    for (Map.Entry<MessageTypeInt, Integer> e : countsInOrder) {
        out.append(String.format("%3d %s\n", e.getValue(), e.getKey().name()));
    }
    return max;
}