blob: 63da569c81fd1df31a14af34de6b820fafe9136f (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*******************************************************************************
* 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:
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
package org.jacoco.report.internal;
import java.io.IOException;
import org.jacoco.core.analysis.CoverageNodeImpl;
import org.jacoco.core.analysis.IBundleCoverage;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.report.IReportGroupVisitor;
import org.jacoco.report.ISourceFileLocator;
/**
* Internal base visitor to calculate group counter summaries for hierarchical
* reports.
*/
public abstract class AbstractGroupVisitor implements IReportGroupVisitor {
/** coverage node for this group to total counters */
protected final CoverageNodeImpl total;
private AbstractGroupVisitor lastChild;
/**
* Creates a new group with the given name.
*
* @param name
* name for the coverage node created internally
*/
protected AbstractGroupVisitor(final String name) {
total = new CoverageNodeImpl(ElementType.GROUP, name);
}
public final void visitBundle(final IBundleCoverage bundle,
final ISourceFileLocator locator) throws IOException {
finalizeLastChild();
total.increment(bundle);
handleBundle(bundle, locator);
}
/**
* Called to handle the given bundle in a specific way.
*
* @param bundle
* analyzed bundle
* @param locator
* source locator
* @throws IOException
* if the report can't be written
*/
protected abstract void handleBundle(IBundleCoverage bundle,
ISourceFileLocator locator) throws IOException;
public final IReportGroupVisitor visitGroup(final String name)
throws IOException {
finalizeLastChild();
lastChild = handleGroup(name);
return lastChild;
}
/**
* Called to handle a group with the given name in a specific way.
*
* @param name
* name of the group
* @return created child group
* @throws IOException
* if the report can't be written
*/
protected abstract AbstractGroupVisitor handleGroup(final String name)
throws IOException;
/**
* Must be called at the end of every group.
*
* @throws IOException
* if the report can't be written
*/
public final void visitEnd() throws IOException {
finalizeLastChild();
handleEnd();
}
/**
* Called to handle the end of this group in a specific way.
*
* @throws IOException
* if the report can't be written
*/
protected abstract void handleEnd() throws IOException;
private void finalizeLastChild() throws IOException {
if (lastChild != null) {
lastChild.visitEnd();
total.increment(lastChild.total);
lastChild = null;
}
}
}
|