KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > uka > ipd > coverage > recording > BasicBlockBuilder


1 /*
2  * Created on Aug 16, 2004
3  * @author Matthias Kempka
4  */

5 package de.uka.ipd.coverage.recording;
6
7
8
9 /**
10  *
11  * The BasicBlockBuilder is used to create BasicBlock objects.
12  * Call Method <code>createBlock</code> to indicate you want to start creating
13  * a new Block
14  *
15  * @author Matthias Kempka
16  *
17  */

18 public class BasicBlockBuilder {
19     
20     private BasicBlock block;
21     private RegisteredMethod method;
22     private int startLine;
23     private int endLine;
24     
25     
26     public void createBasicBlock() {
27         this.block = null;
28         this.method = null;
29         this.startLine = Integer.MIN_VALUE;
30         this.endLine = Integer.MIN_VALUE;
31     }
32     
33     
34     public void setEndLine(int endLine) {
35         this.endLine = endLine;
36     }
37
38     public void setRegisteredMethod(RegisteredMethod method) {
39         this.method = method;
40     }
41     public void setStartLine(int startLine) {
42         this.startLine = startLine;
43     }
44     
45     public BasicBlock getBasicBlock() {
46         if (this.method == null) {
47             throw new IllegalArgumentException JavaDoc("You must call setRegisteredMethod() before" //$NON-NLS-1$
48
+ " calling getBlock()"); //$NON-NLS-1$
49
}
50         if (this.startLine == Integer.MIN_VALUE) {
51             throw new IllegalArgumentException JavaDoc("You must call setStartLine() before" //$NON-NLS-1$
52
+ " calling getBlock()"); //$NON-NLS-1$
53
}
54         if (this.endLine == Integer.MIN_VALUE) {
55             throw new IllegalArgumentException JavaDoc("You must call setEndLine() before" //$NON-NLS-1$
56
+ " calling getBlock()"); //$NON-NLS-1$
57
}
58
59         if (this.block == null) {
60             this.block = createBlock();
61         }
62         return this.block;
63     }
64
65     private BasicBlock createBlock() {
66         BasicBlock block = new BasicBlock(method);
67         block.setStartLine(startLine);
68         block.setEndLine(endLine);
69         return block;
70     }
71     
72 }
73
Popular Tags