KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > compiler > MeasureMark


1 /*
2  * @(#)MeasureMark.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.compiler;
28
29 import net.sourceforge.groboutils.codecoverage.v2.logger.ICoverageLoggerConst;
30
31 import org.apache.bcel.generic.INVOKESTATIC;
32 import org.apache.bcel.generic.InstructionList;
33 import org.apache.bcel.generic.LDC;
34 import org.apache.bcel.generic.SIPUSH;
35
36 /**
37  * Exactly one mark for a specific measure on an instruction. This class is
38  * tightly coupled with the ParseCoverageLogger class, in that the signatures
39  * must match between the two.
40  *
41  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
42  * @version $Date: 2004/04/15 05:48:25 $
43  * @since December 17, 2002
44  */

45 class MeasureMark
46 {
47     private static final Class JavaDoc COVERAGE_SIGNATURE[] =
48         ICoverageLoggerConst.COVERAGE_SIGNATURE;
49     
50     
51     /**
52      * constant pool index for the name of the class's signature.
53      */

54     private final int classSigPoolIndex;
55     
56     /**
57      * constant pool index for the method-ref for invoking the logger.
58      */

59     private final int staticMethodPoolIndex;
60     
61     /**
62      * Reference to the owning method's index
63      */

64     private final short methodIndex;
65     
66     
67     private final short measureIndex;
68     private final short markIndex;
69     
70     /*
71     Java language code for logger:
72     
73         net.sourceforge.groboutils.codecoverage.v2.logger.CoverageLogger.
74             cover( classSig, methodIndex, channel, markIndex );
75     
76     Java bytecode calls for the logger:
77     (this is why we use shorts, not ints!!!!)
78       
79         LDC [class sig constant pool index]
80         SIPUSH [methodIndex]
81         SIPUSH [channel]
82         SIPUSH [markIndex]
83         INVOKESTATIC ["net.sourceforge.groboutils.codecoverage.v2.logger.
84             CoverageLogger.cover (Ljava.lang.String;SSS)V
85     */

86     
87     /**
88      * @throws IllegalStateException if the class file has already been
89      * modified (identified by a class name field).
90      */

91     MeasureMark( int classSigPoolIndex, int staticMethodPoolIndex,
92             short methodIndex, short measureIndex, short markIndex )
93     {
94         this.classSigPoolIndex = classSigPoolIndex;
95         this.staticMethodPoolIndex = staticMethodPoolIndex;
96         this.methodIndex = methodIndex;
97         this.measureIndex = measureIndex;
98         this.markIndex = markIndex;
99     }
100     
101     
102     public void addToInstructionList( InstructionList list )
103     {
104         list.append( new LDC( this.classSigPoolIndex ) );
105         list.append( new SIPUSH( this.methodIndex ) );
106         list.append( new SIPUSH( this.measureIndex ) );
107         list.append( new SIPUSH( this.markIndex ) );
108         list.append( new INVOKESTATIC( this.staticMethodPoolIndex ) );
109     }
110 }
111
112
Popular Tags