use of org.jacoco.core.analysis.ILine in project jacoco by jacoco.
the class MethodAnalyzerTest method assertLine.
private void assertLine(int nr, int insnMissed, int insnCovered, int branchesMissed, int branchesCovered) {
final ILine line = result.getLine(nr);
assertEquals("Instructions in line " + nr, CounterImpl.getInstance(insnMissed, insnCovered), line.getInstructionCounter());
assertEquals("Branches in line " + nr, CounterImpl.getInstance(branchesMissed, branchesCovered), line.getBranchCounter());
}
use of org.jacoco.core.analysis.ILine in project jacoco by jacoco.
the class SourceNodeImpl method increment.
/**
* 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);
}
}
}
use of org.jacoco.core.analysis.ILine in project jacoco by jacoco.
the class ValidationTestBase method assertLine.
protected void assertLine(final String tag, final int status) {
final int nr = source.getLineNumber(tag);
final ILine line = sourceCoverage.getLine(nr);
final String msg = String.format("Status in line %s: %s", Integer.valueOf(nr), source.getLine(nr));
final int insnStatus = line.getInstructionCounter().getStatus();
assertEquals(msg, STATUS_NAME[status], STATUS_NAME[insnStatus]);
}
use of org.jacoco.core.analysis.ILine in project jacoco by jacoco.
the class XMLCoverageWriter method writeLines.
private static void writeLines(final ISourceNode source, final XMLElement 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) {
final XMLElement element = parent.element("line");
element.attr("nr", nr);
writeCounter(element, "mi", "ci", line.getInstructionCounter());
writeCounter(element, "mb", "cb", line.getBranchCounter());
}
}
}
use of org.jacoco.core.analysis.ILine in project sonar-java by SonarSource.
the class UnitTestAnalyzer method analyzeFile.
private static void analyzeFile(NewCoverage newCoverage, InputFile resource, ISourceFileCoverage coverage) {
for (int lineId = coverage.getFirstLine(); lineId <= coverage.getLastLine(); lineId++) {
final int hits;
ILine line = coverage.getLine(lineId);
switch(line.getInstructionCounter().getStatus()) {
case ICounter.FULLY_COVERED:
case ICounter.PARTLY_COVERED:
hits = 1;
break;
case ICounter.NOT_COVERED:
hits = 0;
break;
case ICounter.EMPTY:
continue;
default:
JaCoCoExtensions.LOG.warn("Unknown status for line {} in {}", lineId, resource);
continue;
}
newCoverage.lineHits(lineId, hits);
ICounter branchCounter = line.getBranchCounter();
int conditions = branchCounter.getTotalCount();
if (conditions > 0) {
int coveredConditions = branchCounter.getCoveredCount();
newCoverage.conditions(lineId, conditions, coveredConditions);
}
}
}