ClassColumn.java
1/*******************************************************************************
2 * Copyright (c) 2009 Mountainminds GmbH & Co. KG and others
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Brock Janiczak - initial API and implementation
10 *
11 * $Id: $
12 *******************************************************************************/
13package org.jacoco.report.csv;
14
15import java.io.IOException;
16
17import org.jacoco.core.analysis.ICounter;
18import org.jacoco.core.analysis.ICoverageNode;
19import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
20import org.jacoco.core.analysis.ICoverageNode.ElementType;
21import org.jacoco.report.ILanguageNames;
22import org.jacoco.report.IReportVisitor;
23import org.jacoco.report.ISourceFileLocator;
24
25/**
26 * Columns containing the following values for the class:
27 * <ol>
28 * <li>Class Name</li>
29 * <li>Methods Covered</li>
30 * <li>Methods Not Covered</li>
31 * <li>Blocks Covered</li>
32 * <li>Blocks Not Covered</li>
33 * <li>Lines Covered</li>
34 * <li>Lines Not Covered</li>
35 * <li>Instructions Covered</li>
36 * <li>Instructions Not Covered</li>
37 * </ol>
38 *
39 * @author Brock Janiczak
40 * @version $Revision: $
41 */
42public class ClassColumn implements IReportVisitor, ICsvColumn {
43
44 private final ICsvColumn parent;
45 private final ICoverageNode node;
46 private final CsvReportFile reportFile;
47
48 /**
49 * Creates a new Class Column for the report
50 *
51 * @param reportFile
52 * CSV Report context
53 * @param parent
54 * parent element
55 * @param node
56 * {@link ElementType#CLASS} coverage node
57 */
58 public ClassColumn(final CsvReportFile reportFile, final ICsvColumn parent,
59 final ICoverageNode node) {
60 this.reportFile = reportFile;
61 this.parent = parent;
62 this.node = node;
63 }
64
65 public IReportVisitor visitChild(final ICoverageNode node)
66 throws IOException {
67 return CsvReportFile.NULL_VISITOR;
68 }
69
70 public void visitEnd(final ISourceFileLocator sourceFileLocator)
71 throws IOException {
72 final DelimitedWriter writer = reportFile.getWriter();
73
74 parent.writeContents(writer);
75 this.writeContents(writer);
76
77 }
78
79 public void writeContents(final DelimitedWriter writer) throws IOException {
80 final ILanguageNames languageNames = reportFile.getLanguageNames();
81 final String className = languageNames.getClassName(node.getName());
82 writer.write(className);
83
84 for (final CounterEntity entity : CsvReportFile.COUNTERS) {
85
86 final ICounter counter = node.getCounter(entity);
87 writer.write(counter.getCoveredCount());
88 writer.write(counter.getNotCoveredCount());
89 }
90
91 writer.nextLine();
92 }
93
94}