KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quilt > cover > stmt > CounterVertex


1 /* CounterVertex.java */
2 package org.quilt.cover.stmt;
3
4 import org.apache.bcel.generic.*;
5 import org.quilt.cl.*;
6 import org.quilt.graph.*;
7
8 /**
9  * <p>A CodeVertex which carries counter instrumentation and a label.
10  * The counter has an index. Whenever the flow of execution passes
11  * through this vertex, the counter code adds 1 to the hit count table,
12  * to <code>q$$q[n]</code>, where <code>n</code> is the counter index.</p>
13  *
14  * <p>Counter indexes are unique and assigned consecutively. They are
15  * not the same as vertex indexes. In the current revision of the
16  * software, counter vertices are also labeled with the counter index.</p>
17  *
18  * @author <a HREF="mailto:jddixon@users.sourceforge.net">Jim Dixon</a>
19  */

20 public class CounterVertex extends CodeVertex {
21    
22     /**
23      * Create a code vertex with default bytecode offset, line number,
24      * empty instruction list, and no label.
25      *
26      * @param g Graph which the vertex belongs to.
27      */

28     public CounterVertex (ControlFlowGraph g) {
29         super(g);
30     }
31     /**
32      * Create a counter vertex, specifying a label
33      *
34      * @param g Graph which the vertex belongs to.
35      * @param l The String label applied to the vertex.
36      */

37     public CounterVertex (ControlFlowGraph g, String JavaDoc lbl) {
38         this(g);
39         label_ = lbl;
40     }
41
42     // OTHER METHODS ////////////////////////////////////////////////
43
/**
44      * @return Graph index and Vertex index in a neatly formatted String,
45      * including the label if there is one, *not* newline-terminated.
46      */

47     public String JavaDoc toString () {
48         StringBuffer JavaDoc sb = new StringBuffer JavaDoc().append("Counter ")
49                                 .append(getGraph().getIndex())
50                                 .append(":").append(getIndex());
51         if (label_ != null) {
52             sb.append(" {").append(label_).append("}");
53         }
54         return sb.toString();
55     }
56     /**
57      * @param b If true, add label (if any) and instruction list.
58      * @return A neatly formatted String ending with a newline.
59      */

60     public String JavaDoc toString (boolean b) {
61         
62         StringBuffer JavaDoc sb = new StringBuffer JavaDoc().append(toString());
63         if (b) {
64             sb.append("\n ilist: ");
65             InstructionHandle ih = ilist.getStart();
66             while ( ih != null) {
67                 sb.append(ih.getInstruction());
68             }
69         }
70         return sb.toString();
71     }
72 }
73
Popular Tags