KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > editors > parser > JimpleMethod


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 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 ca.mcgill.sable.soot.editors.parser;
21
22 import java.util.*;
23
24 import ca.mcgill.sable.soot.editors.JimpleOutlineObject;
25
26
27 public class JimpleMethod {
28
29
30     private String JavaDoc val;
31     private String JavaDoc label;
32     private String JavaDoc type;
33     private ArrayList modifiers;
34     private int imageType;
35         
36     public static boolean isMethod(String JavaDoc val){
37         if ((val.indexOf("(") != -1) && (val.indexOf(")") != -1)) return true;
38         return false;
39     }
40     
41     public JimpleMethod(String JavaDoc val){
42         setVal(val);
43     }
44     
45     public void parseMethod(){
46         StringTokenizer st = new StringTokenizer(getVal());
47         int numTokens = st.countTokens();
48         String JavaDoc tempLabel = "";
49         boolean addLabel = false;
50         while (st.hasMoreTokens()){
51             String JavaDoc next = st.nextToken();
52             if (JimpleModifier.isModifier(next)) {
53                 if (getModifiers() == null){
54                     setModifiers(new ArrayList());
55                 }
56                 getModifiers().add(next);
57             }
58             if (next.indexOf("(") != -1){
59                 addLabel = true;
60             }
61             if (addLabel){
62                 tempLabel = tempLabel + next;
63                 tempLabel = tempLabel + " ";
64             }
65         
66         }
67         setLabel(tempLabel);
68     }
69     
70     public void findImageType(){
71         if (getModifiers() == null){
72             setImageType(JimpleOutlineObject.NONE_METHOD);
73             return;
74         }
75         if (getModifiers().contains("public")) {
76             setImageType(JimpleOutlineObject.PUBLIC_METHOD);
77         }
78         else if (getModifiers().contains("protected")) {
79             setImageType(JimpleOutlineObject.PROTECTED_METHOD);
80         }
81         else if (getModifiers().contains("private")) {
82             setImageType(JimpleOutlineObject.PRIVATE_METHOD);
83         }
84         else {
85             setImageType(JimpleOutlineObject.NONE_METHOD);
86         }
87     }
88     
89     public BitSet findDecorators() {
90         BitSet bits = new BitSet();
91         if (getModifiers() == null) return bits;
92         if (getModifiers().contains("abstract")){
93             bits.set(JimpleOutlineObject.ABSTRACT_DEC);
94         }
95         if (getModifiers().contains("final")){
96             bits.set(JimpleOutlineObject.FINAL_DEC);
97         }
98         if (getModifiers().contains("static")){
99             bits.set(JimpleOutlineObject.STATIC_DEC);
100         }
101         if (getModifiers().contains("synchronized")){
102             bits.set(JimpleOutlineObject.SYNCHRONIZED_DEC);
103         }
104         return bits;
105     }
106     
107     /**
108      * @return
109      */

110     public int getImageType() {
111         return imageType;
112     }
113
114     /**
115      * @return
116      */

117     public String JavaDoc getLabel() {
118         return label;
119     }
120
121     /**
122      * @return
123      */

124     public ArrayList getModifiers() {
125         return modifiers;
126     }
127
128     /**
129      * @return
130      */

131     public String JavaDoc getType() {
132         return type;
133     }
134
135     /**
136      * @return
137      */

138     public String JavaDoc getVal() {
139         return val;
140     }
141
142     /**
143      * @param i
144      */

145     public void setImageType(int i) {
146         imageType = i;
147     }
148
149     /**
150      * @param string
151      */

152     public void setLabel(String JavaDoc string) {
153         label = string;
154     }
155
156     /**
157      * @param list
158      */

159     public void setModifiers(ArrayList list) {
160         modifiers = list;
161     }
162
163     /**
164      * @param string
165      */

166     public void setType(String JavaDoc string) {
167         type = string;
168     }
169
170     /**
171      * @param string
172      */

173     public void setVal(String JavaDoc string) {
174         val = string;
175     }
176
177 }
178
Popular Tags