aboutsummaryrefslogtreecommitdiffstats
path: root/org.jacoco.report/src/org/jacoco/report/internal/xml/XMLGroupVisitor.java
blob: 7f2b7d3fbbe0d05f5b28db242be1eaa4bc538218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
 * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Brock Janiczak - initial API and implementation
 *    Marc R. Hoffmann - generalized structure, line info
 *    
 *******************************************************************************/
package org.jacoco.report.internal.xml;

import java.io.IOException;

import org.jacoco.core.analysis.IBundleCoverage;
import org.jacoco.report.ISourceFileLocator;
import org.jacoco.report.internal.AbstractGroupVisitor;

/**
 * A {@link org.jacoco.report.IReportGroupVisitor} that transforms the report
 * structure into XML elements.
 */
public class XMLGroupVisitor extends AbstractGroupVisitor {

	/** XML element of this group */
	protected final ReportElement element;

	/**
	 * New handler for a group with the given name.
	 * 
	 * @param element
	 *            XML-Element representing this coverage node. The start tag
	 *            must not be closed yet to allow adding additional attributes.
	 * @param name
	 *            name of the group
	 * @throws IOException
	 *             in case of problems with the underlying writer
	 */
	public XMLGroupVisitor(final ReportElement element, final String name)
			throws IOException {
		super(name);
		this.element = element;
	}

	@Override
	protected void handleBundle(final IBundleCoverage bundle,
			final ISourceFileLocator locator) throws IOException {
		final ReportElement child = element.group(bundle.getName());
		XMLCoverageWriter.writeBundle(bundle, child);
	}

	@Override
	protected AbstractGroupVisitor handleGroup(final String name)
			throws IOException {
		final ReportElement child = element.group(name);
		return new XMLGroupVisitor(child, name);
	}

	@Override
	protected void handleEnd() throws IOException {
		XMLCoverageWriter.writeCounters(total, element);
	}

}