1/******************************************************************************* 2 * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors 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 *******************************************************************************/ 12package org.jacoco.report.internal.html.page; 13 14import java.io.IOException; 15 16import org.jacoco.core.analysis.IClassCoverage; 17import org.jacoco.core.analysis.IMethodCoverage; 18import org.jacoco.report.internal.ReportOutputFolder; 19import org.jacoco.report.internal.html.IHTMLReportContext; 20import org.jacoco.report.internal.html.ILinkable; 21 22/** 23 * Page showing coverage information for a class as a table of methods. The 24 * methods are linked to the corresponding source file. 25 */ 26public class ClassPage extends TablePage<IClassCoverage> { 27 28 private final ILinkable sourcePage; 29 30 /** 31 * Creates a new visitor in the given context. 32 * 33 * @param classNode 34 * coverage data for this class 35 * @param parent 36 * optional hierarchical parent 37 * @param sourcePage 38 * corresponding source page or <code>null</code> 39 * @param folder 40 * base folder to create this page in 41 * @param context 42 * settings context 43 */ 44 public ClassPage(final IClassCoverage classNode, final ReportPage parent, 45 final ILinkable sourcePage, final ReportOutputFolder folder, 46 final IHTMLReportContext context) { 47 super(classNode, parent, folder, context); 48 this.sourcePage = sourcePage; 49 context.getIndexUpdate().addClass(this, classNode.getId()); 50 } 51 52 @Override 53 protected String getOnload() { 54 return "initialSort(['breadcrumb'])"; 55 } 56 57 @Override 58 public void render() throws IOException { 59 for (final IMethodCoverage m : getNode().getMethods()) { 60 final String label = context.getLanguageNames().getMethodName( 61 getNode().getName(), m.getName(), m.getDesc(), 62 m.getSignature()); 63 addItem(new MethodItem(m, label, sourcePage)); 64 } 65 super.render(); 66 } 67 68 @Override 69 protected String getFileName() { 70 final String vmname = getNode().getName(); 71 final int pos = vmname.lastIndexOf('/'); 72 final String shortname = pos == -1 ? vmname : vmname.substring(pos + 1); 73 return shortname + ".html"; 74 } 75 76 @Override 77 public String getLinkLabel() { 78 return context.getLanguageNames().getClassName(getNode().getName(), 79 getNode().getSignature(), getNode().getSuperName(), 80 getNode().getInterfaceNames()); 81 } 82 83} 84