GroupPage.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 * Marc R. Hoffmann - initial API and implementation
10 *
11 * $Id: $
12 *******************************************************************************/
13package org.jacoco.report.html;
14
15import java.io.IOException;
16import java.util.ArrayList;
17import java.util.List;
18
19import org.jacoco.core.analysis.ICoverageNode;
20import org.jacoco.report.IReportVisitor;
21import org.jacoco.report.ISourceFileLocator;
22import org.jacoco.report.ReportOutputFolder;
23
24/**
25 * Page showing coverage information for a node that groups other nodes. The
26 * page shows a table of linked nodes.
27 *
28 * @author Marc R. Hoffmann
29 * @version $Revision: $
30 */
31public class GroupPage extends ReportPage {
32
33 private final List<ReportPage> children = new ArrayList<ReportPage>();
34
35 /**
36 * Creates a new visitor in the given context.
37 *
38 * @param node
39 * @param parent
40 * @param outputFolder
41 * @param context
42 */
43 public GroupPage(final ICoverageNode node, final ReportPage parent,
44 final ReportOutputFolder outputFolder,
45 final IHTMLReportContext context) {
46 super(node, parent, outputFolder, context);
47 }
48
49 public IReportVisitor visitChild(final ICoverageNode node) {
50 ReportPage child;
51 switch (node.getElementType()) {
52 case PACKAGE:
53 child = new PackagePage(node, this, outputFolder, context);
54 break;
55 default:
56 child = new GroupPage(node, this, outputFolder, context);
57 break;
58 }
59 children.add(child);
60 return child;
61 }
62
63 @Override
64 public void visitEnd(final ISourceFileLocator sourceFileLocator)
65 throws IOException {
66 super.visitEnd(sourceFileLocator);
67 // free memory, otherwise we will keep the complete tree:
68 children.clear();
69 }
70
71 @Override
72 protected void content(final HTMLElement body,
73 final ISourceFileLocator sourceFileLocator) throws IOException {
74 context.getTable(getNode().getElementType()).render(body, children,
75 getNode(), context.getResources(), outputFolder);
76 }
77
78 @Override
79 protected String getFileName() {
80 return "index.html";
81 }
82
83 @Override
84 protected ReportOutputFolder getFolder(final ReportOutputFolder base) {
85 return base.subFolder(getLabel());
86 }
87
88}