KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > javaToJimple > MethodFinalsChecker


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

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