1 5 package de.uka.ipd.coverage.recording; 6 7 import java.io.Serializable ; 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 12 25 public class BasicBlock implements IBasicBlock, Serializable { 26 27 private List successors = new ArrayList (); private List predecessors = new ArrayList (); private RegisteredMethod method; 30 private int startLine; private int endLine; 33 public BasicBlock(RegisteredMethod method) { 34 assert method != null : "RegisteredMethod for a BasicBlock must not be null"; this.method = method; 36 } 37 38 public RegisteredMethod getRegisteredMethod() { 39 return method; 40 } 41 42 45 public CoverageState covers(IBasicBlock obj) { 46 CoverageState result = CoverageState.NO_COVERAGE; 47 if (obj.referencesSameBytecodeAs(this)) { 48 result = CoverageState.FULL_COVERAGE; 49 } 50 return result; 51 } 52 53 66 public boolean referencesSameBytecodeAs(BasicBlock compBlock) { 67 boolean result = false; 68 if (method.equals(compBlock.method)) { 69 if (this.startLine == compBlock.startLine 70 && this.endLine == compBlock.endLine) { 71 result = true; 72 } 73 74 96 else if (compBlock.endLine >= this.startLine 97 && compBlock.startLine <= this.endLine) { 98 throw new AssertionError ("BasicBlock detected that has non-empty intersection" + " of another BasicBlock: " + this.toString() + " vs. " + compBlock.toString()); 101 } 102 } 103 return result; 104 } 105 106 protected void setEndLine(int endLine) { 107 this.endLine = endLine; 108 } 109 110 protected void setStartLine(int startLine) { 111 this.startLine = startLine; 112 } 113 114 public int getEndLine() { 115 return endLine; 116 } 117 118 public int getStartLine() { 119 return startLine; 120 } 121 122 126 public final void addSuccessor(BasicBlock successor) { 127 if (!successors.contains(successor)) { 128 this.successors.add(successor); 129 } 130 successor.addPredecessor(this); 131 } 132 133 private void addPredecessor(BasicBlock predecessor) { 134 if (!predecessors.contains(predecessor)) { 135 this.predecessors.add(predecessor); 136 } 137 } 138 139 public BasicBlock[] getSuccessors() { 140 return (BasicBlock[]) successors.toArray( 141 new BasicBlock[successors.size()]); 142 } 143 144 public BasicBlock[] getPredecessors() { 145 return (BasicBlock[]) predecessors.toArray( 146 new BasicBlock[predecessors.size()]); 147 } 148 149 public String toString() { 150 String result = "BasicBlock:"; result += " Method: " + getRegisteredMethod().getMethod().getName(); result += " PC[" + getStartLine() + ":" + getEndLine() + "]"; return result; 154 } 155 156 160 public boolean equals(Object obj) { 161 if (obj instanceof IBasicBlock) { 162 IBasicBlock compBlock = (IBasicBlock) obj; 163 if (compBlock.getStartLine()== startLine 164 && compBlock.getEndLine() == endLine 165 && compBlock.getRegisteredMethod().equals(method)) { 166 return true; 167 } 168 } 169 return false; 170 } 171 172 public int hashCode() { 173 return method.hashCode(); 174 } 175 176 } 177 | Popular Tags |