1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
*
* This program and the accompanying materials are made available under
* the terms of the Common Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/cpl-v10.html
*
* $Id: MethodItem.java,v 1.1.1.1.2.1 2004/06/20 20:07:22 vlad_r Exp $
*/
package com.vladium.emma.report;
import com.vladium.util.Descriptors;
import com.vladium.util.IntObjectMap;
import com.vladium.util.asserts.$assert;
import com.vladium.emma.data.IMetadataConstants;
import com.vladium.emma.data.MethodDescriptor;
// ----------------------------------------------------------------------------
/**
* @author Vlad Roubtsov, (C) 2003
*/
public
final class MethodItem extends Item
{
// public: ................................................................
public MethodItem (final IItem parent, final int ID, final String name, final String descriptor, final int firstLine)
{
super (parent);
m_ID = ID;
m_name = name;
m_descriptor = descriptor;
m_firstLine = firstLine;
}
public String getName ()
{
if (m_userName == null)
{
m_userName = Descriptors.methodVMNameToJavaName (m_parent.getName (), m_name, m_descriptor, true, true, true);
}
return m_userName;
}
public int getID ()
{
return m_ID;
}
public int getFirstLine ()
{
return m_firstLine;
}
public int getAggregate (final int type)
{
final int [] aggregates = m_aggregates;
int value = aggregates [type];
if (value < 0)
{
final ClassItem parent = ((ClassItem) m_parent);
final MethodDescriptor method = parent.m_cls.getMethods () [m_ID];
final int status = method.getStatus ();
if ((status & IMetadataConstants.METHOD_NO_BLOCK_DATA) != 0)
{
if ($assert.ENABLED) $assert.ASSERT (false, "excluded method in report data model");
for (int i = 0; i < aggregates.length; ++ i) aggregates [i] = 0;
}
else
{
final boolean lineInfo = ((status & IMetadataConstants.METHOD_NO_LINE_NUMBER_TABLE) == 0);
final boolean [] coverage = parent.m_coverage != null ? parent.m_coverage [m_ID] : null;
final int totalBlockCount = method.getBlockCount ();
aggregates [TOTAL_METHOD_COUNT] = 1; // TODO: check that excluded methods are accounted for correctly
aggregates [TOTAL_BLOCK_COUNT] = totalBlockCount;
int totalBlockInstr = 0;
final int [] blockSizes = method.getBlockSizes ();
if (coverage != null)
{
int coverageBlockCount = 0, coverageLineCount = 0;
int coverageBlockInstr = 0, coverageLineInstr = 0;
for (int b = 0; b < totalBlockCount; ++ b)
{
final int instr = blockSizes [b];
totalBlockInstr += instr;
if (coverage [b])
{
++ coverageBlockCount;
coverageBlockInstr += instr;
}
}
if (lineInfo)
{
final IntObjectMap lineMap = method.getLineMap (); // TODO: expensive way to get totalLineCount
final int totalLineCount = lineMap.size ();
aggregates [TOTAL_LINE_COUNT] = totalLineCount;
final int [] lines = lineMap.keys ();
for (int l = 0; l < totalLineCount; ++ l)
{
final int [] blocks = (int []) lineMap.get (lines [l]);
int thisLineCoverageCount = 0; final int thisLineTotalCount = blocks.length;
int thisLineCoverageInstr = 0, thisLineTotalInstr = 0;
for (int bID = 0; bID < thisLineTotalCount; ++ bID)
{
final int b = blocks [bID];
final int instr = blockSizes [b];
thisLineTotalInstr += instr;
if (coverage [b])
{
++ thisLineCoverageCount;
thisLineCoverageInstr += instr;
}
}
coverageLineCount += (PRECISION * thisLineCoverageCount) / thisLineTotalCount;
coverageLineInstr += (PRECISION * thisLineCoverageInstr) / thisLineTotalInstr;
}
aggregates [COVERAGE_LINE_COUNT] = coverageLineCount;
aggregates [COVERAGE_LINE_INSTR] = coverageLineInstr;
}
aggregates [TOTAL_BLOCK_INSTR] = totalBlockInstr;
aggregates [COVERAGE_METHOD_COUNT] = coverageBlockCount > 0 ? 1 : 0;
aggregates [COVERAGE_BLOCK_COUNT] = coverageBlockCount;
aggregates [COVERAGE_BLOCK_INSTR] = coverageBlockInstr;
}
else
{
for (int b = 0; b < totalBlockCount; ++ b)
{
totalBlockInstr += blockSizes [b];
}
aggregates [TOTAL_BLOCK_INSTR] = totalBlockInstr;
aggregates [COVERAGE_METHOD_COUNT] = 0;
aggregates [COVERAGE_BLOCK_COUNT] = 0;
aggregates [COVERAGE_BLOCK_INSTR] = 0;
if (lineInfo)
{
final IntObjectMap lineMap = method.getLineMap (); // TODO: expensive way to get totalLineCount
final int totalLineCount = lineMap.size ();
aggregates [TOTAL_LINE_COUNT] = totalLineCount;
aggregates [COVERAGE_LINE_COUNT] = 0;
aggregates [COVERAGE_LINE_INSTR] = 0;
}
}
}
return aggregates [type];
}
return value;
}
public void accept (final IItemVisitor visitor, final Object ctx)
{
visitor.visit (this, ctx);
}
public final IItemMetadata getMetadata ()
{
return METADATA;
}
public static IItemMetadata getTypeMetadata ()
{
return METADATA;
}
// protected: .............................................................
// package: ...............................................................
// private: ...............................................................
private final int m_ID;
private final String m_name, m_descriptor;
private final int m_firstLine;
private transient String m_userName;
private static final Item.ItemMetadata METADATA; // set in <clinit>
static
{
METADATA = new Item.ItemMetadata (IItemMetadata.TYPE_ID_METHOD, "method",
1 << IItemAttribute.ATTRIBUTE_NAME_ID |
1 << IItemAttribute.ATTRIBUTE_METHOD_COVERAGE_ID |
1 << IItemAttribute.ATTRIBUTE_BLOCK_COVERAGE_ID |
1 << IItemAttribute.ATTRIBUTE_LINE_COVERAGE_ID);
}
} // end of class
// ----------------------------------------------------------------------------
|