public void visitCoverage(final IClassCoverage coverage) { final String name = coverage.getName(); final IClassCoverage dup = classes.put(name, coverage); if (dup != null) { if (dup.getId() != coverage.getId()) { throw new IllegalStateException( "Can't add different class with same name: " + name); } } else { final String source = coverage.getSourceFileName(); if (source != null) { final SourceFileCoverageImpl sourceFile = getSourceFile(source, coverage.getPackageName()); sourceFile.increment(coverage); } } }
public void visitCoverage(final IClassCoverage coverage) { final String desc = String.format("class 0x%016x %s", Long.valueOf(coverage.getId()), coverage.getName()); printDetails(desc, coverage); if (verbose) { for (final Iterator<IMethodCoverage> i = coverage.getMethods() .iterator(); i.hasNext();) { printMethod(i.next(), i.hasNext()); } } }
/** * Returns all classes for which execution data does not match. * * @see IClassCoverage#isNoMatch() * @return collection of classes with non-matching execution data */ public Collection<IClassCoverage> getNoMatchClasses() { final Collection<IClassCoverage> result = new ArrayList<IClassCoverage>(); for (final IClassCoverage c : classes.values()) { if (c.isNoMatch()) { result.add(c); } } return result; }
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()); } } }
private List<IClassCoverage> getSameClassCoverage(String className, List<IClassCoverage> classCoverages) { return classCoverages.stream() .filter(iClassCoverage -> className.equals(iClassCoverage.getName())) .collect(Collectors.toList()); }
System.out.printf("Coverage of class %s%n", cc.getName()); printCounter("instructions", cc.getInstructionCounter()); printCounter("branches", cc.getBranchCounter()); printCounter("lines", cc.getLineCounter()); printCounter("methods", cc.getMethodCounter()); printCounter("complexity", cc.getComplexityCounter()); for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) { System.out.printf("Line %s: %s%n", Integer.valueOf(i), getColor(cc.getLine(i).getStatus()));
for (IClassCoverage classCov: classList) { ClassReport classReport = new ClassReport(); classReport.setName(classCov.getName()); classReport.setParent(packageReport); classReport.setSrcFileInfo(classCov, executionFileLoader.getSrcDir() + "/" + packageCov.getName() + "/" + classCov.getSourceFileName()); ArrayList<IMethodCoverage> methodList = new ArrayList<>(classCov.getMethods()); for (IMethodCoverage methodCov: methodList) { MethodReport methodReport = new MethodReport();
@Override public String getLinkLabel() { return context.getLanguageNames().getClassName(getNode().getName(), getNode().getSignature(), getNode().getSuperName(), getNode().getInterfaceNames()); }
/** * Creates a 'class' element. * * @param coverage * class coverage node to write out * @return 'class' element * @throws IOException * in case of problems with the underlying output */ public ReportElement classElement(final IClassCoverage coverage) throws IOException { final ReportElement element = namedElement("class", coverage.getName()); element.attr("sourcefilename", coverage.getSourceFileName()); return element; }
@Override protected void content(HTMLElement body) throws IOException { if (getNode().isNoMatch()) { body.p().text( "A different version of class was executed at runtime."); } if (getNode().getLineCounter().getTotalCount() == 0) { body.p().text( "Class files must be compiled with debug information to show line coverage."); } final String sourceFileName = getNode().getSourceFileName(); if (sourceFileName == null) { body.p().text( "Class files must be compiled with debug information to link with source files."); } else if (sourcePage == null) { final String sourcePath; if (getNode().getPackageName().length() != 0) { sourcePath = getNode().getPackageName() + "/" + sourceFileName; } else { sourcePath = sourceFileName; } body.p().text("Source file \"" + sourcePath + "\" was not found during generation of report."); } super.content(body); }
public static List<Integer> getListOfCountForCounterFunction(IClassCoverage coverage, Function<ICounter, Integer> counterGetter) { return coverage.getMethods() .stream() .filter(iMethodCoverage -> !"<clinit>".equals(iMethodCoverage.getName())) .flatMap(iMethodCoverage -> IntStream.range(iMethodCoverage.getFirstLine(), iMethodCoverage.getLastLine() + 1) .mapToObj(iMethodCoverage::getLine) .map(ILine::getInstructionCounter) .map(counterGetter) ).collect(Collectors.toList()); }
public void visit(IClassFile classfile) throws JavaModelException { final String vmname = classfile.getType().getFullyQualifiedName() .replace('.', '/'); final IClassCoverage coverage = nodes.getClassCoverage(vmname); if (coverage != null) { modelcoverage.putClassFile(classfile, coverage); // Add source file coverage manually in case of binary roots // as we will not see compilation units: final ISourceFileCoverage source = nodes.getSourceFileCoverage( coverage.getPackageName(), coverage.getSourceFileName()); if (source != null) { sources.add(source); } } }
private void renderClasses() throws IOException { for (final IClassCoverage c : getNode().getClasses()) { if (!c.containsCode()) { continue; } final ILinkable sourceFilePage = packageSourcePage .getSourceFilePage(c.getSourceFileName()); final ClassPage page = new ClassPage(c, this, sourceFilePage, folder, context); page.render(); addItem(page); } }
/** * Creates package node instance for a package with the given name. * * @param name * vm name of the package * @param classes * collection of all classes in this package * @param sourceFiles * collection of all source files in this package */ public PackageCoverageImpl(final String name, final Collection<IClassCoverage> classes, final Collection<ISourceFileCoverage> sourceFiles) { super(ElementType.PACKAGE, name); this.classes = classes; this.sourceFiles = sourceFiles; increment(sourceFiles); for (final IClassCoverage c : classes) { // We need to add only classes without a source file reference. // Classes associated with a source file are already included in the // SourceFileCoverage objects. if (c.getSourceFileName() == null) { increment(c); } } }
private static Collection<IPackageCoverage> groupByPackage( final Collection<IClassCoverage> classes, final Collection<ISourceFileCoverage> sourcefiles) { final Map<String, Collection<IClassCoverage>> classesByPackage = new HashMap<String, Collection<IClassCoverage>>(); for (final IClassCoverage c : classes) { addByName(classesByPackage, c.getPackageName(), c); } final Map<String, Collection<ISourceFileCoverage>> sourceFilesByPackage = new HashMap<String, Collection<ISourceFileCoverage>>(); for (final ISourceFileCoverage s : sourcefiles) { addByName(sourceFilesByPackage, s.getPackageName(), s); } final Set<String> packageNames = new HashSet<String>(); packageNames.addAll(classesByPackage.keySet()); packageNames.addAll(sourceFilesByPackage.keySet()); final Collection<IPackageCoverage> result = new ArrayList<IPackageCoverage>(); for (final String name : packageNames) { Collection<IClassCoverage> c = classesByPackage.get(name); if (c == null) { c = Collections.emptyList(); } Collection<ISourceFileCoverage> s = sourceFilesByPackage.get(name); if (s == null) { s = Collections.emptyList(); } result.add(new PackageCoverageImpl(name, c, s)); } return result; }
/** * Creates a new visitor in the given context. * * @param classNode * coverage data for this class * @param parent * optional hierarchical parent * @param sourcePage * corresponding source page or <code>null</code> * @param folder * base folder to create this page in * @param context * settings context */ public ClassPage(final IClassCoverage classNode, final ReportPage parent, final ILinkable sourcePage, final ReportOutputFolder folder, final IHTMLReportContext context) { super(classNode, parent, folder, context); this.sourcePage = sourcePage; context.getIndexUpdate().addClass(this, classNode.getId()); }
private void printNoMatchWarning(final Collection<IClassCoverage> nomatch, final PrintWriter out) { if (!nomatch.isEmpty()) { out.println( "[WARN] Some classes do not match with execution data."); out.println( "[WARN] For report generation the same class files must be used as at runtime."); for (final IClassCoverage c : nomatch) { out.printf( "[WARN] Execution data for class %s does not match.%n", c.getName()); } } }
@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(); }
/** * Writes the class summary information as a row. * * @param groupName * name of the group * @param packageName * vm name of the package * @param node * class coverage data * @throws IOException * in case of problems with the writer */ public void writeRow(final String groupName, final String packageName, final IClassCoverage node) throws IOException { writer.write(groupName); writer.write(languageNames.getPackageName(packageName)); final String className = languageNames.getClassName(node.getName(), node.getSignature(), node.getSuperName(), node.getInterfaceNames()); writer.write(className); for (final CounterEntity entity : COUNTERS) { final ICounter counter = node.getCounter(entity); writer.write(counter.getMissedCount()); writer.write(counter.getCoveredCount()); } writer.nextLine(); }
private static void writeClass(final IClassCoverage c, final ReportElement parent) throws IOException { final ReportElement element = parent.classElement(c); for (final IMethodCoverage m : c.getMethods()) { writeMethod(m, element); } writeCounters(c, element); }