PackageColumn.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.ClassCoverage;
18import org.jacoco.core.analysis.ICoverageNode;
19import org.jacoco.core.analysis.ICoverageNode.ElementType;
20import org.jacoco.report.ILanguageNames;
21import org.jacoco.report.IReportVisitor;
22import org.jacoco.report.ISourceFileLocator;
23
24/**
25 * Column containing the package name
26 *
27 * @author Brock Janiczak
28 * @version $Revision: $
29 */
30public class PackageColumn implements IReportVisitor, ICsvColumn {
31
32 private final ICsvColumn parent;
33 private final CsvReportFile reportFile;
34 private final String packageName;
35
36 /**
37 * Creates a new Package Column for the report
38 *
39 * @param reportFile
40 * CSV Report context
41 * @param parent
42 * parent element
43 * @param node
44 * {@link ElementType#PACKAGE} coverage node
45 */
46 public PackageColumn(final CsvReportFile reportFile,
47 final ICsvColumn parent, final ICoverageNode node) {
48 this.reportFile = reportFile;
49 this.parent = parent;
50 this.packageName = node.getName();
51 }
52
53 public IReportVisitor visitChild(final ICoverageNode node)
54 throws IOException {
55 if (node.getElementType() == ElementType.SOURCEFILE) {
56 return CsvReportFile.NULL_VISITOR;
57 }
58 return new ClassColumn(reportFile, this, (ClassCoverage) node);
59 }
60
61 public void visitEnd(final ISourceFileLocator sourceFileLocator)
62 throws IOException {
63 }
64
65 public void writeContents(final DelimitedWriter writer) throws IOException {
66 final ILanguageNames languageNames = reportFile.getLanguageNames();
67 final String value = languageNames.getPackageName(packageName);
68
69 parent.writeContents(writer);
70 writer.write(value);
71 }
72
73}