public void printHighlightedSrcFile(ISourceNode cov, Writer output) { try { StringBuilder buf = new StringBuilder(); List<String> sourceLines; try { sourceLines = readLines(); } catch (IOException e) { e.printStackTrace(); output.write("ERROR: Error while reading the sourcefile!"); return; } output.write("<code style=\"white-space:pre;\">"); for (int i = 1; i <= sourceLines.size(); ++i) { buf.setLength(0); ILine line = cov.getLine(i); ICounter branches = line.getBranchCounter(); int status = line.getStatus(); if (status != ICounter.EMPTY) { printHighlightedLine(buf, i, branches, sourceLines.get(i - 1), status); } else { buf.append(i).append(": ").append(sourceLines.get(i - 1)).append("<br>"); } output.write(buf.toString()); } output.write("</code>"); //logger.log(Level.INFO, "lines: " + buf); } catch (IOException e) { throw new RuntimeException(e); } }
private void printLine(final ILine line, final int nr, final String indent) { if (line.getStatus() != ICounter.EMPTY) { out.printf("%6s %6s %s +- line %s%n", total(line.getInstructionCounter()), total(line.getBranchCounter()), indent, Integer.valueOf(nr)); } }
private static void writeLines(final ISourceNode source, final ReportElement parent) throws IOException { final int last = source.getLastLine(); for (int nr = source.getFirstLine(); nr <= last; nr++) { final ILine line = source.getLine(nr); if (line.getStatus() != ICounter.EMPTY) { parent.line(nr, line); } } }
HTMLElement highlight(final HTMLElement pre, final ILine line, final int lineNr) throws IOException { final String style; switch (line.getStatus()) { case ICounter.NOT_COVERED: style = Styles.NOT_COVERED;