1 19 20 package soot.javaToJimple; 21 import java.util.*; 22 23 public class MethodFinalsChecker extends polyglot.visit.NodeVisitor{ 24 25 private ArrayList inners; 26 private ArrayList finalLocals; 27 private HashMap typeToLocalsUsed; 28 private ArrayList ccallList; 29 30 public HashMap typeToLocalsUsed(){ 31 return typeToLocalsUsed; 32 } 33 34 public ArrayList finalLocals(){ 35 return finalLocals; 36 } 37 38 public ArrayList inners(){ 39 return inners; 40 } 41 42 public ArrayList ccallList(){ 43 return ccallList; 44 } 45 46 47 public MethodFinalsChecker(){ 48 finalLocals = new ArrayList(); 49 inners = new ArrayList(); 50 ccallList = new ArrayList(); 51 typeToLocalsUsed = new HashMap(); 52 } 53 54 public polyglot.ast.Node override(polyglot.ast.Node parent, polyglot.ast.Node n){ 55 if (n instanceof polyglot.ast.LocalClassDecl){ 56 inners.add(new polyglot.util.IdentityKey(((polyglot.ast.LocalClassDecl)n).decl().type())); 57 polyglot.ast.ClassBody localClassBody = ((polyglot.ast.LocalClassDecl)n).decl().body(); 58 LocalUsesChecker luc = new LocalUsesChecker(); 59 localClassBody.visit(luc); 60 typeToLocalsUsed.put(new polyglot.util.IdentityKey(((polyglot.ast.LocalClassDecl)n).decl().type()), luc.getLocals()); 61 return n; 62 } 63 else if (n instanceof polyglot.ast.New) { 64 if (((polyglot.ast.New)n).anonType() != null) { 65 inners.add(new polyglot.util.IdentityKey(((polyglot.ast.New)n).anonType())); 66 polyglot.ast.ClassBody anonClassBody = ((polyglot.ast.New)n).body(); 67 LocalUsesChecker luc = new LocalUsesChecker(); 68 anonClassBody.visit(luc); 69 typeToLocalsUsed.put(new polyglot.util.IdentityKey(((polyglot.ast.New)n).anonType()), luc.getLocals()); 70 return n; 71 } 72 } 73 return null; 74 } 75 76 public polyglot.visit.NodeVisitor enter(polyglot.ast.Node parent, polyglot.ast.Node n) { 77 78 79 if (n instanceof polyglot.ast.LocalDecl){ 80 polyglot.ast.LocalDecl ld = (polyglot.ast.LocalDecl)n; 81 if (ld.flags().isFinal()){ 82 if (!finalLocals.contains(new polyglot.util.IdentityKey(ld.localInstance()))){ 83 finalLocals.add(new polyglot.util.IdentityKey(ld.localInstance())); 84 } 85 } 86 } 87 if (n instanceof polyglot.ast.Formal){ 88 polyglot.ast.Formal ld = (polyglot.ast.Formal)n; 89 if (ld.flags().isFinal()){ 90 if (!finalLocals.contains(new polyglot.util.IdentityKey(ld.localInstance()))){ 91 finalLocals.add(new polyglot.util.IdentityKey(ld.localInstance())); 92 } 93 } 94 } 95 96 if (n instanceof polyglot.ast.ConstructorCall){ 97 ccallList.add(n); 98 } 99 return enter(n); 100 } 101 } 102 | Popular Tags |