| 1 19 20 25 26 27 28 29 package soot.jimple.parser; 30 31 import soot.baf.*; 32 import soot.*; 33 import soot.jimple.*; 34 35 import soot.jimple.parser.parser.*; 36 import soot.jimple.parser.lexer.*; 37 import soot.jimple.parser.node.*; 38 import soot.jimple.parser.analysis.*; 39 40 import java.io.*; 41 import java.util.*; 42 43 44 48 public class SkeletonExtractorWalker extends Walker 49 { 50 51 public SkeletonExtractorWalker(SootResolver aResolver, SootClass aSootClass) 52 { 53 super(aSootClass, aResolver); 54 } 55 56 public SkeletonExtractorWalker(SootResolver aResolver) 57 { 58 super(aResolver); 59 } 60 61 62 public void caseAFile(AFile node) 63 { 64 inAFile(node); 65 { 66 Object temp[] = node.getModifier().toArray(); 67 for(int i = 0; i < temp.length; i++) 68 { 69 ((PModifier) temp[i]).apply(this); 70 } 71 } 72 if(node.getFileType() != null) 73 { 74 node.getFileType().apply(this); 75 } 76 if(node.getClassName() != null) 77 { 78 node.getClassName().apply(this); 79 } 80 81 82 String className = (String ) mProductions.removeLast(); 83 84 if(mSootClass == null) { 85 mSootClass = new SootClass(className); 86 mSootClass.setResolvingLevel(SootClass.SIGNATURES); 87 } else { 88 if(!className.equals(mSootClass.getName())) 89 throw new RuntimeException ("expected: " + className + ", but got: " + mSootClass.getName()); 90 } 91 92 if(node.getExtendsClause() != null) 93 { 94 node.getExtendsClause().apply(this); 95 } 96 if(node.getImplementsClause() != null) 97 { 98 node.getImplementsClause().apply(this); 99 } 100 if(node.getFileBody() != null) 101 { 102 node.getFileBody().apply(this); 103 } 104 outAFile(node); 105 } 106 107 108 public void outAFile(AFile node) 109 { 110 List implementsList = null; 111 String superClass = null; 112 113 String classType = null; 114 115 if(node.getImplementsClause() != null) { 116 implementsList = (List) mProductions.removeLast(); 117 } 118 if(node.getExtendsClause() != null) { 119 superClass = (String ) mProductions.removeLast(); 120 121 } 122 classType = (String ) mProductions.removeLast(); 123 124 int modifierFlags = processModifiers(node.getModifier()); 125 126 127 if(classType.equals("interface")) 128 modifierFlags |= Modifier.INTERFACE; 129 130 mSootClass.setModifiers(modifierFlags); 131 132 if(superClass != null) { 133 mSootClass.setSuperclass(mResolver.makeClassRef(superClass)); 134 } 135 136 if(implementsList != null) { 137 Iterator implIt = implementsList.iterator(); 138 while(implIt.hasNext()) { 139 SootClass interfaceClass = mResolver.makeClassRef((String ) implIt.next()); 140 mSootClass.addInterface(interfaceClass); 141 } 142 } 143 144 mProductions.addLast(mSootClass); 145 } 146 147 148 149 154 155 156 public void caseAMethodMember(AMethodMember node) 157 { 158 inAMethodMember(node); 159 { 160 Object temp[] = node.getModifier().toArray(); 161 for(int i = 0; i < temp.length; i++) 162 { 163 ((PModifier) temp[i]).apply(this); 164 } 165 } 166 if(node.getType() != null) 167 { 168 node.getType().apply(this); 169 } 170 if(node.getName() != null) 171 { 172 node.getName().apply(this); 173 } 174 if(node.getLParen() != null) 175 { 176 node.getLParen().apply(this); 177 } 178 if(node.getParameterList() != null) 179 { 180 node.getParameterList().apply(this); 181 } 182 if(node.getRParen() != null) 183 { 184 node.getRParen().apply(this); 185 } 186 if(node.getThrowsClause() != null) 187 { 188 node.getThrowsClause().apply(this); 189 } 190 194 outAMethodMember(node); 195 } 196 public void outAMethodMember(AMethodMember node) 197 { 198 int modifier = 0; 199 Type type; 200 String name; 201 List parameterList = null; 202 List throwsClause = null; 203 JimpleBody methodBody = null; 204 205 208 209 if(node.getThrowsClause() != null) 210 throwsClause = (List) mProductions.removeLast(); 211 212 if(node.getParameterList() != null) { 213 parameterList = (List) mProductions.removeLast(); 214 } 215 else { 216 parameterList = new ArrayList(); 217 } 218 219 Object o = mProductions.removeLast(); 220 221 222 name = (String ) o; 223 type = (Type) mProductions.removeLast(); 224 modifier = processModifiers(node.getModifier()); 225 226 SootMethod method; 227 228 if(throwsClause != null) 229 method = new SootMethod(name, parameterList, type, modifier, throwsClause); 230 else 231 method = new SootMethod(name, parameterList, type, modifier); 232 233 mSootClass.addMethod(method); 234 } 235 236 237 241 public void outAThrowsClause(AThrowsClause node) 242 { 243 List l = (List) mProductions.removeLast(); 244 245 Iterator it = l.iterator(); 246 List exceptionClasses = new ArrayList(l.size()); 247 248 while(it.hasNext()) { 249 String className = (String ) it.next(); 250 251 exceptionClasses.add(mResolver.makeClassRef(className)); 252 } 253 254 mProductions.addLast(exceptionClasses); 255 } 256 } 257 | Popular Tags |