GroupColumn.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.ICoverageNode;
18import org.jacoco.core.analysis.ICoverageNode.ElementType;
19import org.jacoco.report.IReportVisitor;
20import org.jacoco.report.ISourceFileLocator;
21
22/**
23 * Column containing the aggregated group name. Consecutive groups will be
24 * merged into a single group
25 *
26 * @author Brock Janiczak
27 * @version $Revision: $
28 */
29public class GroupColumn implements IReportVisitor, ICsvColumn {
30 private String groupName;
31 private final CsvReportFile reportFile;
32
33 /**
34 * Creates a new Group Column for the report
35 *
36 * @param reportFile
37 * CSV Report context
38 * @param node
39 * {@link ElementType#GROUP} coverage node
40 */
41 public GroupColumn(final CsvReportFile reportFile, final ICoverageNode node) {
42 this.reportFile = reportFile;
43 groupName = node.getName();
44 }
45
46 public IReportVisitor visitChild(final ICoverageNode node)
47 throws IOException {
48 if (node.getElementType() == ElementType.GROUP) {
49 groupName += "/" + node.getName();
50 return this;
51 }
52
53 return new BundleColumn(reportFile, this, node);
54 }
55
56 public void visitEnd(final ISourceFileLocator sourceFileLocator)
57 throws IOException {
58
59 }
60
61 public void writeContents(final DelimitedWriter writer) throws IOException {
62 writer.write(groupName);
63 }
64}