1 /*******************************************************************************
2  * Copyright (c) 2009, 2019 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  *******************************************************************************/
12 package org.jacoco.core.analysis;
13 
14 /**
15  * Interface for hierarchical coverage data nodes with different coverage
16  * counters.
17  */
18 public interface ICoverageNode {
19 
20 	/**
21 	 * Type of a Java element represented by a {@link ICoverageNode} instance.
22 	 */
23 	enum ElementType {
24 
25 		/** Method */
26 		METHOD,
27 
28 		/** Class */
29 		CLASS,
30 
31 		/** Source File */
32 		SOURCEFILE,
33 
34 		/** Java Package */
35 		PACKAGE,
36 
37 		/** Bundle of Packages */
38 		BUNDLE,
39 
40 		/** Logical Group of Bundles */
41 		GROUP,
42 
43 	}
44 
45 	/**
46 	 * Different counter types supported by JaCoCo.
47 	 */
48 	enum CounterEntity {
49 
50 		/** Counter for instructions */
51 		INSTRUCTION,
52 
53 		/** Counter for branches */
54 		BRANCH,
55 
56 		/** Counter for source lines */
57 		LINE,
58 
59 		/** Counter for cyclomatic complexity */
60 		COMPLEXITY,
61 
62 		/** Counter for methods */
63 		METHOD,
64 
65 		/** Counter for classes */
66 		CLASS
67 	}
68 
69 	/**
70 	 * Returns the type of element represented by this node.
71 	 *
72 	 * @return type of this node
73 	 */
getElementType()74 	ElementType getElementType();
75 
76 	/**
77 	 * Returns the name of this node.
78 	 *
79 	 * @return name of this node
80 	 */
getName()81 	String getName();
82 
83 	/**
84 	 * Returns the counter for byte code instructions.
85 	 *
86 	 * @return counter for instructions
87 	 */
getInstructionCounter()88 	ICounter getInstructionCounter();
89 
90 	/**
91 	 * Returns the counter for branches.
92 	 *
93 	 * @return counter for branches
94 	 */
getBranchCounter()95 	ICounter getBranchCounter();
96 
97 	/**
98 	 * Returns the counter for lines.
99 	 *
100 	 * @return counter for lines
101 	 */
getLineCounter()102 	ICounter getLineCounter();
103 
104 	/**
105 	 * Returns the counter for cyclomatic complexity.
106 	 *
107 	 * @return counter for complexity
108 	 */
getComplexityCounter()109 	ICounter getComplexityCounter();
110 
111 	/**
112 	 * Returns the counter for methods.
113 	 *
114 	 * @return counter for methods
115 	 */
getMethodCounter()116 	ICounter getMethodCounter();
117 
118 	/**
119 	 * Returns the counter for classes.
120 	 *
121 	 * @return counter for classes
122 	 */
getClassCounter()123 	ICounter getClassCounter();
124 
125 	/**
126 	 * Generic access to the the counters.
127 	 *
128 	 * @param entity
129 	 *            entity we're we want to have the counter for
130 	 * @return counter for the given entity
131 	 */
getCounter(CounterEntity entity)132 	ICounter getCounter(CounterEntity entity);
133 
134 	/**
135 	 * Checks whether this node contains code relevant for code coverage.
136 	 *
137 	 * @return <code>true</code> if this node contains code relevant for code coverage
138 	 */
containsCode()139 	boolean containsCode();
140 
141 	/**
142 	 * Creates a plain copy of this node. While {@link ICoverageNode}
143 	 * implementations may contain heavy data structures, the copy returned by
144 	 * this method is reduced to the counters only. This helps to save memory
145 	 * while processing huge structures.
146 	 *
147 	 * @return copy with counters only
148 	 */
getPlainCopy()149 	ICoverageNode getPlainCopy();
150 
151 }
152