1 19 20 26 27 35 package soot.dava.internal.javaRep; 36 37 import soot.*; 38 39 import java.util.*; 40 41 import soot.jimple.*; 42 import soot.util.IterableSet; 43 import soot.grimp.*; 44 import soot.dava.*; 45 46 public class DVariableDeclarationStmt extends AbstractUnit implements Stmt { 47 48 Type declarationType = null; 49 50 List declarations = null; 51 52 DavaBody davaBody = null; 54 55 public DVariableDeclarationStmt(Type decType, DavaBody davaBody) { 56 if (declarationType != null) 57 throw new RuntimeException ( 58 "creating a VariableDeclaration which has already been created"); 59 else { 60 declarationType = decType; 61 declarations = new ArrayList(); 62 this.davaBody=davaBody; 63 } 64 } 65 66 public List getDeclarations() { 67 return declarations; 68 } 69 70 public void addLocal(Local add) { 71 declarations.add(add); 72 } 73 74 public void removeLocal(Local remove) { 75 for (int i = 0; i < declarations.size(); i++) { 76 Local temp = (Local) declarations.get(i); 77 if (temp.getName().compareTo(remove.getName()) == 0) { 78 declarations.remove(i); 81 return; 82 } 83 } 84 } 85 86 public Type getType() { 87 return declarationType; 88 } 89 90 public boolean isOfType(Type type) { 91 if (type.toString().compareTo(declarationType.toString()) == 0) 92 return true; 93 else 94 return false; 95 } 96 97 public Object clone() { 98 DVariableDeclarationStmt temp = new DVariableDeclarationStmt( 99 declarationType,davaBody); 100 Iterator it = declarations.iterator(); 101 while (it.hasNext()) { 102 Local obj = (Local) it.next(); 103 104 Value temp1 = Grimp.cloneIfNecessary(obj); 105 if (temp1 instanceof Local) 106 temp.addLocal((Local) temp1); 107 } 108 return temp; 109 } 110 111 public String toString() { 112 StringBuffer b = new StringBuffer (); 113 114 if (declarations.size() == 0) 115 return b.toString(); 116 117 String type = declarationType.toString(); 118 119 if (type.equals("null_type")) 120 b.append("Object"); 121 else 122 b.append(type); 123 b.append(" "); 124 125 Iterator decIt = declarations.iterator(); 126 while (decIt.hasNext()) { 127 Local tempDec = (Local) decIt.next(); 128 b.append(tempDec.getName()); 129 130 if (decIt.hasNext()) 131 b.append(", "); 132 } 133 return b.toString(); 134 } 135 136 public void toString(UnitPrinter up) { 137 if (declarations.size() == 0) 138 return; 139 140 if (!(up instanceof DavaUnitPrinter)) 141 throw new RuntimeException ( 142 "DavaBody should always be printed using the DavaUnitPrinter"); 143 else { 144 DavaUnitPrinter dup = (DavaUnitPrinter) up; 145 146 String type = declarationType.toString(); 147 148 if (type.equals("null_type")) 149 dup.printString("Object"); 150 else{ 151 152 153 163 164 Map options = PhaseOptions.v().getPhaseOptions("db.renamer"); 165 boolean force = PhaseOptions.getBoolean(options, "remove-fully-qualified"); 166 168 169 if (force) { 170 IterableSet set = davaBody.get_PackagesUsed(); 171 172 String packageName = null; 174 if (type.lastIndexOf('.') > 0) { packageName = type.substring(0, type.lastIndexOf('.')); 176 } 177 if (packageName != null) { 178 if (!set.contains(packageName)) { 182 davaBody.addPackage(packageName); 184 } else { 186 } 188 189 type = type.substring(type.lastIndexOf('.') + 1); 191 } 192 } 193 194 195 dup.printString(type); 196 } 197 dup.printString(" "); 198 199 Iterator decIt = declarations.iterator(); 200 while (decIt.hasNext()) { 201 Local tempDec = (Local) decIt.next(); 202 dup.printString(tempDec.getName()); 203 if (decIt.hasNext()) 204 dup.printString(", "); 205 } 206 } 207 } 208 209 214 215 public boolean fallsThrough() { 216 return true; 217 } 218 219 public boolean branches() { 220 return false; 221 } 222 223 public boolean containsInvokeExpr() { 224 return false; 225 } 226 227 public InvokeExpr getInvokeExpr() { 228 throw new RuntimeException ( 229 "getInvokeExpr() called with no invokeExpr present!"); 230 } 231 232 public ValueBox getInvokeExprBox() { 233 throw new RuntimeException ( 234 "getInvokeExprBox() called with no invokeExpr present!"); 235 } 236 237 public boolean containsArrayRef() { 238 return false; 239 } 240 241 public ArrayRef getArrayRef() { 242 throw new RuntimeException ( 243 "getArrayRef() called with no ArrayRef present!"); 244 } 245 246 public ValueBox getArrayRefBox() { 247 throw new RuntimeException ( 248 "getArrayRefBox() called with no ArrayRef present!"); 249 } 250 251 public boolean containsFieldRef() { 252 return false; 253 } 254 255 public FieldRef getFieldRef() { 256 throw new RuntimeException ( 257 "getFieldRef() called with no FieldRef present!"); 258 } 259 260 public ValueBox getFieldRefBox() { 261 throw new RuntimeException ( 262 "getFieldRefBox() called with no FieldRef present!"); 263 } 264 265 } 266 | Popular Tags |