1   /***
2    * BranchEdge
3    *
4    * This represents an edge used in a Branch
5    * in a control flow graph.
6    */
7   
8   package junit.quilt.cover.generic;
9   
10  import junit.quilt.exception.InvalidTransitionException;
11  import org.apache.bcel.generic.*;
12  
13  public class BranchEdge extends FlowControlEdge
14  {
15      private String expr = null;
16      private boolean value = false;
17  
18      public BranchEdge(BlockVertex start,
19  		      BlockVertex target,
20  		      String expr,
21  		      boolean value) 
22      { 
23  	super( start, target );
24  	this.expr = expr;
25  	this.value = value;
26      }
27      
28      public void connect( MethodGen method,
29  			 InstructionList il,
30  			 InstructionHandle source,
31  			 InstructionHandle target )
32  	throws InvalidTransitionException
33      {
34  	if (source.getInstruction() instanceof IfInstruction) {
35  	    if (value) {
36  		((IfInstruction) source.getInstruction()).setTarget( target );
37  	    } else {
38  		if (source.getNext() != target) {
39  		    il.append( source, new GOTO( target ) );
40  		}
41  	    }
42  	} else {
43  	    throw new InvalidTransitionException("If instruction expected.");
44  	}
45  	
46      }
47  
48      public FlowControlEdge copy( BlockVertex start,
49  				 BlockVertex target ) {
50  	return new BranchEdge(start,
51  			      target,
52  			      expr,
53  			      value);
54      } 
55  
56      public String toString() { 
57  	String RC = "[B: ";
58  	if (!value) RC = RC + "!";
59  	RC = RC + expr + "->" + getTarget() + "]";
60  
61  	return RC; 
62      }
63  }
64  
65  
This page was automatically generated by Maven