1 20 21 package soot.dava.internal.AST; 22 23 import soot.*; 24 import java.util.*; 25 import soot.jimple.*; 26 import soot.dava.internal.SET.*; 27 import soot.dava.toolkits.base.AST.*; 28 import soot.dava.toolkits.base.AST.analysis.*; 29 30 public class ASTIfElseNode extends ASTControlFlowNode 31 { 32 private List ifBody, elseBody; 33 34 public ASTIfElseNode( SETNodeLabel label, ConditionExpr condition, List ifBody, List elseBody) 35 { 36 super( label, condition); 37 this.ifBody = ifBody; 38 this.elseBody = elseBody; 39 40 subBodies.add( ifBody); 41 subBodies.add( elseBody); 42 } 43 44 49 public ASTIfElseNode( SETNodeLabel label, ASTCondition condition, List ifBody, List elseBody) 50 { 51 super( label, condition); 52 this.ifBody = ifBody; 53 this.elseBody = elseBody; 54 55 subBodies.add( ifBody); 56 subBodies.add( elseBody); 57 } 58 59 63 public void replace(SETNodeLabel newLabel,ASTCondition newCond,List newBody,List bodyTwo){ 64 this.ifBody=newBody; 65 this.elseBody=bodyTwo; 66 subBodies= new ArrayList(); 67 subBodies.add(newBody); 68 subBodies.add(bodyTwo); 69 set_Condition(newCond); 70 set_Label(newLabel); 71 72 } 73 74 75 79 public void replaceBody(List ifBody,List elseBody){ 80 this.ifBody=ifBody; 81 this.elseBody=elseBody; 82 83 subBodies= new ArrayList(); 84 subBodies.add(ifBody); 85 subBodies.add(elseBody); 86 } 87 88 89 93 public void replaceElseBody(List elseBody){ 94 this.elseBody=elseBody; 95 96 subBodies= new ArrayList(); 97 subBodies.add(ifBody); 98 subBodies.add(elseBody); 99 } 100 101 102 106 public List getIfBody(){ 107 return ifBody; 108 } 109 110 public List getElseBody(){ 111 return elseBody; 112 } 113 114 115 116 117 public Object clone() 118 { 119 return new ASTIfElseNode( get_Label(), get_Condition(), ifBody, elseBody); 120 } 121 122 public void toString( UnitPrinter up ) 123 { 124 label_toString( up ); 125 126 up.literal( "if" ); 127 up.literal( " " ); 128 up.literal( "(" ); 129 condition.toString( up ); 130 up.literal( ")" ); 131 up.newline(); 132 133 up.literal( "{" ); 134 up.newline(); 135 136 up.incIndent(); 137 body_toString( up, ifBody ); 138 up.decIndent(); 139 140 up.literal( "}" ); 141 up.newline(); 142 143 up.literal( "else" ); 144 up.newline(); 145 146 up.literal( "{" ); 147 up.newline(); 148 149 up.incIndent(); 150 body_toString( up, elseBody ); 151 up.decIndent(); 152 153 up.literal( "}" ); 154 up.newline(); 155 } 156 157 public String toString() 158 { 159 StringBuffer b = new StringBuffer (); 160 161 b.append( label_toString()); 162 163 b.append( "if ("); 164 b.append( get_Condition().toString()); 165 b.append( ")"); 166 b.append( NEWLINE); 167 168 b.append( "{"); 169 b.append( NEWLINE); 170 171 b.append( body_toString(ifBody)); 172 173 b.append( "}"); 174 b.append( NEWLINE); 175 176 b.append( "else"); 177 b.append( NEWLINE); 178 179 b.append( "{"); 180 b.append( NEWLINE); 181 182 b.append( body_toString(elseBody)); 183 184 b.append( "}"); 185 b.append( NEWLINE); 186 187 return b.toString(); 188 } 189 190 195 public void apply(Analysis a){ 196 a.caseASTIfElseNode(this); 197 } 198 199 } 200 | Popular Tags |