001: /*
002: * @(#)MeasureMark.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.compiler;
028:
029: import net.sourceforge.groboutils.codecoverage.v2.logger.ICoverageLoggerConst;
030:
031: import org.apache.bcel.generic.INVOKESTATIC;
032: import org.apache.bcel.generic.InstructionList;
033: import org.apache.bcel.generic.LDC;
034: import org.apache.bcel.generic.SIPUSH;
035:
036: /**
037: * Exactly one mark for a specific measure on an instruction. This class is
038: * tightly coupled with the ParseCoverageLogger class, in that the signatures
039: * must match between the two.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @version $Date: 2004/04/15 05:48:25 $
043: * @since December 17, 2002
044: */
045: class MeasureMark {
046: private static final Class COVERAGE_SIGNATURE[] = ICoverageLoggerConst.COVERAGE_SIGNATURE;
047:
048: /**
049: * constant pool index for the name of the class's signature.
050: */
051: private final int classSigPoolIndex;
052:
053: /**
054: * constant pool index for the method-ref for invoking the logger.
055: */
056: private final int staticMethodPoolIndex;
057:
058: /**
059: * Reference to the owning method's index
060: */
061: private final short methodIndex;
062:
063: private final short measureIndex;
064: private final short markIndex;
065:
066: /*
067: Java language code for logger:
068:
069: net.sourceforge.groboutils.codecoverage.v2.logger.CoverageLogger.
070: cover( classSig, methodIndex, channel, markIndex );
071:
072: Java bytecode calls for the logger:
073: (this is why we use shorts, not ints!!!!)
074:
075: LDC [class sig constant pool index]
076: SIPUSH [methodIndex]
077: SIPUSH [channel]
078: SIPUSH [markIndex]
079: INVOKESTATIC ["net.sourceforge.groboutils.codecoverage.v2.logger.
080: CoverageLogger.cover (Ljava.lang.String;SSS)V
081: */
082:
083: /**
084: * @throws IllegalStateException if the class file has already been
085: * modified (identified by a class name field).
086: */
087: MeasureMark(int classSigPoolIndex, int staticMethodPoolIndex,
088: short methodIndex, short measureIndex, short markIndex) {
089: this .classSigPoolIndex = classSigPoolIndex;
090: this .staticMethodPoolIndex = staticMethodPoolIndex;
091: this .methodIndex = methodIndex;
092: this .measureIndex = measureIndex;
093: this .markIndex = markIndex;
094: }
095:
096: public void addToInstructionList(InstructionList list) {
097: list.append(new LDC(this .classSigPoolIndex));
098: list.append(new SIPUSH(this .methodIndex));
099: list.append(new SIPUSH(this .measureIndex));
100: list.append(new SIPUSH(this .markIndex));
101: list.append(new INVOKESTATIC(this.staticMethodPoolIndex));
102: }
103: }
|