Search in sources :

Example 6 with IMethodCoverage

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);
            }
        }
    };
}
Also used : IMethodCoverage(org.jacoco.core.analysis.IMethodCoverage)

Example 7 with IMethodCoverage

use of org.jacoco.core.analysis.IMethodCoverage in project jacoco by jacoco.

the class CyclomaticComplexityTest method analyze.

private ICounter analyze() throws IOException {
    final CoverageBuilder builder = new CoverageBuilder();
    final ExecutionDataStore store = new ExecutionDataStore();
    data.collect(store, new SessionInfoStore(), false);
    final Analyzer analyzer = new Analyzer(store, builder);
    analyzer.analyzeClass(bytes, "TestTarget");
    final Collection<IClassCoverage> classes = builder.getClasses();
    assertEquals(1, classes.size(), 0.0);
    final IClassCoverage classCoverage = classes.iterator().next();
    for (final IMethodCoverage m : classCoverage.getMethods()) {
        if (m.getName().equals("test")) {
            return m.getComplexityCounter();
        }
    }
    throw new AssertionError("No test() method.");
}
Also used : IMethodCoverage(org.jacoco.core.analysis.IMethodCoverage) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Aggregations

IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)7 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)3 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Analyzer (org.jacoco.core.analysis.Analyzer)1 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 ICounter (org.jacoco.core.analysis.ICounter)1 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)1 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)1 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)1 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)1 IReportVisitor (org.jacoco.report.IReportVisitor)1 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)1