PackageCoverageImpl.java revision d05ad7d4bc65e91b6c6efb45687f7a850d07f02a
1/******************************************************************************* 2 * Copyright (c) 2009, 2011 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.core.internal.analysis; 13 14import java.util.Collection; 15 16import org.jacoco.core.analysis.CoverageNodeImpl; 17import org.jacoco.core.analysis.IClassCoverage; 18import org.jacoco.core.analysis.IPackageCoverage; 19import org.jacoco.core.analysis.ISourceFileCoverage; 20 21/** 22 * Implementation of {@link IPackageCoverage}. 23 * 24 * @author Marc R. Hoffmann 25 * @version $qualified.bundle.version$ 26 */ 27public class PackageCoverageImpl extends CoverageNodeImpl implements 28 IPackageCoverage { 29 30 private final Collection<IClassCoverage> classes; 31 32 private final Collection<ISourceFileCoverage> sourceFiles; 33 34 /** 35 * Creates package node instance for a package with the given name. 36 * 37 * @param name 38 * vm name of the package 39 * @param classes 40 * collection of all classes in this package 41 * @param sourceFiles 42 * collection of all source files in this package 43 */ 44 public PackageCoverageImpl(final String name, 45 final Collection<IClassCoverage> classes, 46 final Collection<ISourceFileCoverage> sourceFiles) { 47 super(ElementType.PACKAGE, name); 48 this.classes = classes; 49 this.sourceFiles = sourceFiles; 50 increment(sourceFiles); 51 for (final IClassCoverage c : classes) { 52 // We need to add only classes without a source file reference. 53 // Classes associated with a source file are already included in the 54 // SourceFileCoverage objects. 55 if (c.getSourceFileName() == null) { 56 increment(c); 57 } 58 } 59 } 60 61 // === IPackageCoverage implementation === 62 63 public Collection<IClassCoverage> getClasses() { 64 return classes; 65 } 66 67 public Collection<ISourceFileCoverage> getSourceFiles() { 68 return sourceFiles; 69 } 70 71} 72