MethodNode.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 * Brock Janiczak -initial API and implementation
10 *
11 * $Id: $
12 *******************************************************************************/
13package org.jacoco.report.xml;
14
15import java.io.IOException;
16
17import org.jacoco.core.analysis.ICoverageNode;
18import org.jacoco.core.analysis.MethodCoverage;
19import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
20import org.jacoco.report.IReportVisitor;
21
22/**
23 * Wrapper for an {@link XMLElement} that contains method coverage data
24 *
25 * @author Brock Janiczak
26 * @version $Revision: $
27 */
28public class MethodNode extends NodeWithCoverage {
29 private static final CounterEntity[] METHOD_COUNTERS = {
30 CounterEntity.BLOCK, CounterEntity.LINE, CounterEntity.INSTRUCTION, };
31
32 /**
33 * Creates a new Method coverage element for the supplied package and class
34 * coverage node
35 *
36 * @param parent
37 * Parent element that will own this class element
38 * @param methodNode
39 * Method coverage node
40 * @throws IOException
41 * IO Error creating the element
42 */
43 public MethodNode(final ClassNode parent, final ICoverageNode methodNode)
44 throws IOException {
45 super(parent, "method", methodNode);
46 final MethodCoverage methodCoverageNode = (MethodCoverage) methodNode;
47 this.attr("desc", methodCoverageNode.getDesc());
48 final String signature = methodCoverageNode.getSignature();
49 if (signature != null) {
50 this.attr("signature", signature);
51 }
52 }
53
54 public IReportVisitor visitChild(final ICoverageNode node)
55 throws IOException {
56 throw new IllegalStateException("Methods must not have child nodes.");
57 }
58
59 @Override
60 protected CounterEntity[] getCounterEntities() {
61 return METHOD_COUNTERS;
62 }
63
64}