ClassCoverage.java
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 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.analysis;
13
14import java.util.Collection;
15
16/**
17 * Coverage data of a single class.
18 *
19 * @author Marc R. Hoffmann
20 * @version 0.4.1.20101007204400
21 */
22public class ClassCoverage extends CoverageNodeImpl {
23
24 private final long id;
25 private final String signature;
26 private final String superName;
27 private final String[] interfaces;
28 private final Collection<MethodCoverage> methods;
29 private final String sourceFileName;
30
31 /**
32 * Creates a class coverage data object with the given parameters.
33 *
34 * @param name
35 * vm name of the class
36 * @param id
37 * class identifier
38 * @param signature
39 * vm signature of the class
40 * @param superName
41 * vm name of the superclass of this class
42 * @param interfaces
43 * vm names of interfaces of this class
44 * @param sourceFileName
45 * optional name of the corresponding source file
46 * @param methods
47 * contained methods
48 */
49 public ClassCoverage(final String name, final long id,
50 final String signature, final String superName,
51 final String[] interfaces, final String sourceFileName,
52 final Collection<MethodCoverage> methods) {
53 super(ElementType.CLASS, name, true);
54 this.id = id;
55 this.signature = signature;
56 this.superName = superName;
57 this.interfaces = interfaces;
58 this.sourceFileName = sourceFileName;
59 this.methods = methods;
60 increment(methods);
61 // As class is considered as covered when at least one method is
62 // covered:
63 final boolean covered = methodCounter.getCoveredCount() > 0;
64 this.classCounter = CounterImpl.getInstance(covered);
65 }
66
67 /**
68 * Returns the identifier for this class which is the CRC64 signature of the
69 * class definition.
70 *
71 * @return class identifier
72 */
73 public long getId() {
74 return id;
75 }
76
77 /**
78 * Returns the VM signature of the class.
79 *
80 * @return VM signature of the class (may be <code>null</code>)
81 */
82 public String getSignature() {
83 return signature;
84 }
85
86 /**
87 * Returns the VM name of the superclass.
88 *
89 * @return VM name of the super class (may be <code>null</code>, i.e.
90 * <code>java/lang/Object</code>)
91 */
92 public String getSuperName() {
93 return superName;
94 }
95
96 /**
97 * Returns the VM names of implemented/extended interfaces
98 *
99 * @return VM names of implemented/extended interfaces
100 */
101 public String[] getInterfaceNames() {
102 return interfaces;
103 }
104
105 /**
106 * Returns the VM name of the package this class belongs to.
107 *
108 * @return VM name of the package
109 */
110 public String getPackageName() {
111 final int pos = getName().lastIndexOf('/');
112 return pos == -1 ? "" : getName().substring(0, pos);
113 }
114
115 /**
116 * Returns the optional name of the corresponding source file.
117 *
118 * @return name of the corresponding source file
119 */
120 public String getSourceFileName() {
121 return sourceFileName;
122 }
123
124 /**
125 * Returns the methods included in this class.
126 *
127 * @return methods of this class
128 */
129 public Collection<MethodCoverage> getMethods() {
130 return methods;
131 }
132
133}