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); } } }
@Override protected String getFileName() { return getNode().getName() + ".html"; }
/** * Increments all counters by the values of the given child. When * incrementing the line counter it is assumed that the child refers to the * same source file. * * @param child * child node to add */ public void increment(final ISourceNode child) { instructionCounter = instructionCounter.increment(child .getInstructionCounter()); branchCounter = branchCounter.increment(child.getBranchCounter()); complexityCounter = complexityCounter.increment(child .getComplexityCounter()); methodCounter = methodCounter.increment(child.getMethodCounter()); classCounter = classCounter.increment(child.getClassCounter()); final int firstLine = child.getFirstLine(); if (firstLine != UNKNOWN_LINE) { final int lastLine = child.getLastLine(); ensureCapacity(firstLine, lastLine); for (int i = firstLine; i <= lastLine; i++) { final ILine line = child.getLine(i); incrementLine(line.getInstructionCounter(), line.getBranchCounter(), i); } } }
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); } }
/** * Highlights the given source file. * * @param parent * parent HTML element * @param source * highlighting information * @param contents * contents of the source file * @throws IOException * problems while reading the source file or writing the output */ public void render(final HTMLElement parent, final ISourceNode source, final Reader contents) throws IOException { final HTMLElement pre = parent.pre(Styles.SOURCE + " lang-" + lang + " linenums"); final BufferedReader lineBuffer = new BufferedReader(contents); String line; int nr = 0; while ((line = lineBuffer.readLine()) != null) { nr++; renderCodeLine(pre, line, source.getLine(nr), nr); } }