use of org.jacoco.core.analysis.IMethodCoverage in project jacoco by jacoco.
the class BundleChecker method check.
private void check(final IClassCoverage classCoverage) {
final String name = names.getQualifiedClassName(classCoverage.getName());
checkRules(classCoverage, classRules, "class", name);
if (traverseMethods) {
for (final IMethodCoverage m : classCoverage.getMethods()) {
check(m, classCoverage.getName());
}
}
}
use of org.jacoco.core.analysis.IMethodCoverage in project jacoco by jacoco.
the class ClassPage method render.
@Override
public void render() throws IOException {
for (final IMethodCoverage m : getNode().getMethods()) {
final String label = context.getLanguageNames().getMethodName(getNode().getName(), m.getName(), m.getDesc(), m.getSignature());
addItem(new MethodItem(m, label, sourcePage));
}
super.render();
}
use of org.jacoco.core.analysis.IMethodCoverage in project jacoco by jacoco.
the class XMLCoverageWriter method writeClass.
private static void writeClass(final IClassCoverage c, final XMLElement parent) throws IOException {
final XMLElement element = createChild(parent, "class", c.getName());
for (final IMethodCoverage m : c.getMethods()) {
writeMethod(m, element);
}
writeCounters(c, element);
}
use of org.jacoco.core.analysis.IMethodCoverage in project bazel by bazelbuild.
the class JacocoLCOVFormatter method createVisitor.
public IReportVisitor createVisitor(final File output, final Map<String, BranchCoverageDetail> branchCoverageDetail) {
return new IReportVisitor() {
private Map<String, Map<String, IClassCoverage>> sourceToClassCoverage = new TreeMap<>();
private Map<String, ISourceFileCoverage> sourceToFileCoverage = new TreeMap<>();
@Override
public void visitInfo(List<SessionInfo> sessionInfos, Collection<ExecutionData> executionData) throws IOException {
}
@Override
public void visitEnd() throws IOException {
try (FileWriter fileWriter = new FileWriter(output, true);
PrintWriter printWriter = new PrintWriter(fileWriter)) {
for (String sourceFile : sourceToClassCoverage.keySet()) {
processSourceFile(printWriter, sourceFile);
}
}
}
@Override
public void visitBundle(IBundleCoverage bundle, ISourceFileLocator locator) throws IOException {
// information and process everything at the end.
for (IPackageCoverage pkgCoverage : bundle.getPackages()) {
for (IClassCoverage clsCoverage : pkgCoverage.getClasses()) {
String fileName = clsCoverage.getPackageName() + "/" + clsCoverage.getSourceFileName();
if (!sourceToClassCoverage.containsKey(fileName)) {
sourceToClassCoverage.put(fileName, new TreeMap<String, IClassCoverage>());
}
sourceToClassCoverage.get(fileName).put(clsCoverage.getName(), clsCoverage);
}
for (ISourceFileCoverage srcCoverage : pkgCoverage.getSourceFiles()) {
sourceToFileCoverage.put(srcCoverage.getPackageName() + "/" + srcCoverage.getName(), srcCoverage);
}
}
}
@Override
public IReportGroupVisitor visitGroup(String name) throws IOException {
return null;
}
private void processSourceFile(PrintWriter writer, String sourceFile) {
writer.printf("SF:%s\n", sourceFile);
ISourceFileCoverage srcCoverage = sourceToFileCoverage.get(sourceFile);
if (srcCoverage != null) {
// List methods, including methods from nested classes, in FN/FNDA pairs
for (IClassCoverage clsCoverage : sourceToClassCoverage.get(sourceFile).values()) {
for (IMethodCoverage mthCoverage : clsCoverage.getMethods()) {
String name = constructFunctionName(mthCoverage, clsCoverage.getName());
writer.printf("FN:%d,%s\n", mthCoverage.getFirstLine(), name);
writer.printf("FNDA:%d,%s\n", mthCoverage.getMethodCounter().getCoveredCount(), name);
}
}
for (IClassCoverage clsCoverage : sourceToClassCoverage.get(sourceFile).values()) {
BranchCoverageDetail detail = branchCoverageDetail.get(clsCoverage.getName());
if (detail != null) {
for (int line : detail.linesWithBranches()) {
int numBranches = detail.getBranches(line);
boolean executed = detail.getExecutedBit(line);
if (executed) {
for (int branchIdx = 0; branchIdx < numBranches; branchIdx++) {
if (detail.getTakenBit(line, branchIdx)) {
// executed, taken
writer.printf("BA:%d,%d\n", line, 2);
} else {
// executed, not taken
writer.printf("BA:%d,%d\n", line, 1);
}
}
} else {
for (int branchIdx = 0; branchIdx < numBranches; branchIdx++) {
// not executed
writer.printf("BA:%d,%d\n", line, 0);
}
}
}
}
}
// List of DA entries matching source lines
int firstLine = srcCoverage.getFirstLine();
int lastLine = srcCoverage.getLastLine();
for (int line = firstLine; line <= lastLine; line++) {
ICounter instructionCounter = srcCoverage.getLine(line).getInstructionCounter();
if (instructionCounter.getTotalCount() != 0) {
writer.printf("DA:%d,%d\n", line, instructionCounter.getCoveredCount());
}
}
}
writer.println("end_of_record");
}
private String constructFunctionName(IMethodCoverage mthCoverage, String clsName) {
// lcov_merger doesn't seem to care about these entries.
return clsName + "::" + mthCoverage.getName() + " " + mthCoverage.getDesc();
}
};
}
use of org.jacoco.core.analysis.IMethodCoverage in project jacoco by jacoco.
the class ClassAnalyzer method visitMethod.
@Override
public MethodProbesVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
InstrSupport.assertNotInstrumented(name, coverage.getName());
return new MethodAnalyzer(coverage.getName(), coverage.getSuperName(), stringPool.get(name), stringPool.get(desc), stringPool.get(signature), probes, Filters.ALL) {
@Override
public void visitEnd() {
super.visitEnd();
final IMethodCoverage methodCoverage = getCoverage();
if (methodCoverage.getInstructionCounter().getTotalCount() > 0) {
// Only consider methods that actually contain code
coverage.addMethod(methodCoverage);
}
}
};
}
Aggregations