1 20 21 26 27 28 package soot; 29 30 import soot.tagkit.*; 31 import soot.jimple.*; 32 import java.util.*; 33 import soot.util.*; 34 import soot.jimple.paddle.PaddleField; 35 import soot.jimple.spark.pag.SparkField; 36 37 40 public class SootField extends AbstractHost implements ClassMember, SparkField, Numberable, PaddleField 41 { 42 String name; 43 Type type; 44 int modifiers; 45 46 boolean isDeclared = false; 47 SootClass declaringClass; 48 boolean isPhantom = false; 49 50 51 public SootField(String name, Type type, int modifiers) 52 { 53 this.name = name; 54 this.type = type; 55 this.modifiers = modifiers; 56 if( type instanceof RefLikeType ) Scene.v().getFieldNumberer().add(this); 57 } 58 59 60 public SootField(String name, Type type) 61 { 62 this.name = name; 63 this.type = type; 64 this.modifiers = 0; 65 if( type instanceof RefLikeType ) Scene.v().getFieldNumberer().add(this); 66 } 67 68 public int equivHashCode() 69 { 70 return type.hashCode() * 101 + modifiers * 17 + name.hashCode(); 71 } 72 73 public String getName() 74 { 75 return name; 76 } 77 78 public String getSignature() { 79 return getSignature(declaringClass, getName(), getType()); 80 } 81 public static String getSignature(SootClass cl, String name, Type type) 82 { 83 StringBuffer buffer = new StringBuffer (); 84 85 buffer.append("<" + Scene.v().quotedNameOf(cl.getName()) + ": "); 86 buffer.append(type + " " + Scene.v().quotedNameOf(name) + ">"); 87 88 return buffer.toString().intern(); 89 90 } 91 92 public String getSubSignature() 93 { 94 StringBuffer buffer = new StringBuffer (); 95 buffer.append(getType() + " " + Scene.v().quotedNameOf(getName())); 96 return buffer.toString().intern(); 97 } 98 99 public SootClass getDeclaringClass() 100 { 101 if(!isDeclared) 102 throw new RuntimeException ("not declared: "+getName()+" "+getType()); 103 104 return declaringClass; 105 } 106 107 public boolean isPhantom() 108 { 109 return isPhantom; 110 } 111 112 public void setPhantom(boolean value) 113 { 114 if( value ) { 115 if( !Scene.v().allowsPhantomRefs() ) 116 throw new RuntimeException ( "Phantom refs not allowed" ); 117 if( declaringClass != null && !declaringClass.isPhantom() ) 118 throw new 119 RuntimeException ( "Declaring class would have to be phantom" ); 120 } 121 isPhantom = value; 122 } 123 124 public boolean isDeclared() 125 { 126 return isDeclared; 127 } 128 129 public void setName(String name) 130 { 131 this.name = name; 132 } 133 134 public Type getType() 135 { 136 return type; 137 } 138 139 public void setType(Type t) 140 { 141 this.type = t; 142 } 143 144 147 public boolean isPublic() 148 { 149 return Modifier.isPublic(this.getModifiers()); 150 } 151 152 155 public boolean isProtected() 156 { 157 return Modifier.isProtected(this.getModifiers()); 158 } 159 160 163 public boolean isPrivate() 164 { 165 return Modifier.isPrivate(this.getModifiers()); 166 } 167 168 171 public boolean isStatic() 172 { 173 return Modifier.isStatic(this.getModifiers()); 174 } 175 176 179 public boolean isFinal() 180 { 181 return Modifier.isFinal(this.getModifiers()); 182 } 183 184 185 186 public void setModifiers(int modifiers) 187 { 188 if (!declaringClass.isApplicationClass()) 189 throw new RuntimeException ("Cannot set modifiers of a field from a non-app class!"); 190 191 this.modifiers = modifiers; 192 } 193 194 public int getModifiers() 195 { 196 return modifiers; 197 } 198 199 public String toString() 200 { 201 return getSignature(); 202 } 203 204 205 private String getOriginalStyleDeclaration() 206 { 207 String qualifiers = Modifier.toString(modifiers) + " " + type.toString(); 208 qualifiers = qualifiers.trim(); 209 210 if(qualifiers.equals("")) 211 return Scene.v().quotedNameOf(name); 212 else 213 return qualifiers + " " + Scene.v().quotedNameOf(name) + ""; 214 215 } 216 217 218 public String getDeclaration() 219 { 220 return getOriginalStyleDeclaration(); 221 } 222 public final int getNumber() { 223 return number; 224 } 225 public final void setNumber(int number) { 226 this.number = number; 227 } 228 private int number = 0; 229 public SootFieldRef makeRef() { 230 return Scene.v().makeFieldRef(declaringClass, name, type, isStatic()); 231 } 232 } 233 234 235 236 237 238 239 | Popular Tags |