KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on 23.11.2004
3  *
4  * written by Matthias Kempka
5  */

6 package de.uka.ipd.coverage.recording;
7
8 import java.io.Serializable JavaDoc;
9
10 /**
11  * Created on 23.11.2004
12  * @author Matthias Kempka
13  */

14
15 public class RuntimeBasicBlockWrapper
16         implements IBasicBlock, Cloneable JavaDoc, Serializable JavaDoc {
17     
18     private IBasicBlock basicblock;
19     private boolean entered;
20     private boolean exited;
21     
22     
23     /**
24      * @param basicblock
25      */

26     public RuntimeBasicBlockWrapper(IBasicBlock basicblock) {
27         this.basicblock = basicblock;
28     }
29     
30     public void triggerEntered() {
31         this.entered = true;
32     }
33     
34     public void triggerExited() {
35         assert isEntered() : "call triggerEntered before calling triggerExited!"; //$NON-NLS-1$
36
this.exited = true;
37     }
38     
39     public boolean isEntered() {
40         return entered;
41     }
42     public boolean isExited() {
43         return exited;
44     }
45     
46     public int getStartLine() {
47         return this.basicblock.getStartLine();
48     }
49     
50     public int getEndLine() {
51         return this.basicblock.getEndLine();
52     }
53
54     public RegisteredMethod getRegisteredMethod() {
55         return this.basicblock.getRegisteredMethod();
56     }
57
58     public CoverageState covers(IBasicBlock obj) {
59         CoverageState result = this.basicblock.covers(obj);
60         if (obj instanceof RuntimeBasicBlockWrapper
61                 && result == CoverageState.FULL_COVERAGE) {
62             /*
63              * wrapper this result
64              * ----------------------------------------------------
65              * entered | exited | entered | exited |
66              * ----------------------------------------------------
67              * 0 | 0 | 0 | 0 | FULL
68              * 0 | 0 | - | - | NO
69              * 1 | 0 | - | 0 | FULL
70              * 1 | 0 | 1 | 1 | PARTIAL
71              * 1 | 1 | - | - | FULL
72              */

73             RuntimeBasicBlockWrapper wrapper = (RuntimeBasicBlockWrapper) obj;
74             if (wrapper.entered) {
75                 if (wrapper.exited) {
76                     return CoverageState.FULL_COVERAGE;
77                 } else if (this.exited) {
78                     return CoverageState.PARTIAL_COVERAGE;
79                 }
80                 return CoverageState.FULL_COVERAGE;
81             } else {
82                 if (this.entered) {
83                     return CoverageState.FULL_COVERAGE;
84                 }
85                 return CoverageState.NO_COVERAGE;
86             }
87         }
88         return result;
89     }
90
91     public boolean referencesSameBytecodeAs(BasicBlock compBlock) {
92         return this.basicblock.referencesSameBytecodeAs(compBlock);
93     }
94     
95     public boolean equals(Object JavaDoc obj) {
96         boolean result = false;
97         if (obj instanceof RuntimeBasicBlockWrapper) {
98             RuntimeBasicBlockWrapper compWrapper = (RuntimeBasicBlockWrapper) obj;
99             result = this.basicblock.equals(compWrapper.basicblock);
100             result = result
101                     & this.entered == compWrapper.entered
102                     & this.exited == compWrapper.exited;
103             return result;
104         }
105         if (obj instanceof BasicBlock) {
106             IBasicBlock compBlock = (IBasicBlock) obj;
107             result = this.basicblock.equals(compBlock);
108             return result;
109         }
110         return false;
111     }
112     
113     public Object JavaDoc clone() {
114         RuntimeBasicBlockWrapper result =
115             new RuntimeBasicBlockWrapper(this.basicblock);
116         result.entered = this.entered;
117         result.exited = this.exited;
118         return result;
119     }
120     public IBasicBlock getWrappedBasicBlock() {
121         return basicblock;
122     }
123     
124     public String JavaDoc toString() {
125         return basicblock.toString();
126     }
127 }
128
Popular Tags