KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > parser > CstPoolExtractor


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2000 Patrice Pominville
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 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 package soot.jimple.parser;
28
29 import soot.baf.*;
30 import soot.*;
31 import soot.jimple.*;
32 import soot.util.*;
33
34 import soot.jimple.parser.parser.*;
35 import soot.jimple.parser.lexer.*;
36 import soot.jimple.parser.node.*;
37 import soot.jimple.parser.analysis.*;
38
39 import java.io.*;
40 import java.util.*;
41
42
43 /**
44  * Walks a jimple AST, extracting all the contained reference
45  * type names.
46  */

47
48 class CstPoolExtractor
49 {
50
51     private Set mRefTypes = null;
52     private Start mParseTree;
53
54     public CstPoolExtractor(Start parseTree)
55     {
56         mParseTree = parseTree;
57     }
58
59     public Set getCstPool()
60     {
61         if(mRefTypes == null) {
62             mRefTypes = new HashSet();
63             CstPoolExtractorWalker walker = new CstPoolExtractorWalker();
64             mParseTree.apply(walker);
65             mParseTree = null; // allow garbage collection
66
}
67         return mRefTypes;
68     }
69                 
70
71     private class CstPoolExtractorWalker extends DepthFirstAdapter
72     {
73         CstPoolExtractorWalker()
74         {
75         }
76    
77         public void inStart(Start node)
78         {
79             defaultIn(node);
80         }
81
82
83         public void outAQuotedClassName(AQuotedClassName node)
84         {
85         String JavaDoc tokenString = node.getQuotedName().getText();
86         tokenString = tokenString.substring(1, tokenString.length() -1 );
87         tokenString = StringTools.getUnEscapedStringOf(tokenString);
88
89             mRefTypes.add(tokenString);
90        
91         }
92
93         public void outAIdentClassName(AIdentClassName node)
94         {
95         String JavaDoc tokenString = node.getIdentifier().getText();
96         tokenString = StringTools.getUnEscapedStringOf(tokenString);
97         
98         mRefTypes.add(tokenString);
99         }
100
101         public void outAFullIdentClassName(AFullIdentClassName node)
102         {
103         String JavaDoc tokenString = node.getFullIdentifier().getText();
104         tokenString = StringTools.getUnEscapedStringOf(tokenString);
105         
106             mRefTypes.add(tokenString);
107         }
108
109         public void outAQuotedNonvoidType(AQuotedNonvoidType node)
110         {
111         String JavaDoc tokenString = node.getQuotedName().getText();
112         tokenString = tokenString.substring(1, tokenString.length() -1 );
113         tokenString = StringTools.getUnEscapedStringOf(tokenString);
114
115             mRefTypes.add(tokenString);
116         }
117    
118         public void outAFullIdentNonvoidType(AFullIdentNonvoidType node)
119         {
120         String JavaDoc tokenString = node.getFullIdentifier().getText();
121         tokenString = StringTools.getUnEscapedStringOf(tokenString);
122
123             mRefTypes.add(tokenString);
124         }
125     
126         public void outAIdentNonvoidType(AIdentNonvoidType node)
127         {
128         String JavaDoc tokenString = node.getIdentifier().getText();
129         tokenString = StringTools.getUnEscapedStringOf(tokenString);
130         
131             mRefTypes.add(tokenString);
132         }
133     }
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Popular Tags