KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 package ca.mcgill.sable.soot.editors.parser;
22
23 import java.util.*;
24
25 public class JimpleBody {
26
27     private String JavaDoc text;
28     private ArrayList textArr;
29     private ArrayList methods;
30     private ArrayList fields;
31     
32     
33     public JimpleBody(String JavaDoc text, ArrayList textArr){
34         setText(text);
35         setTextArr(textArr);
36     }
37     
38     public boolean isJimpleBody() {
39     
40         return true;
41     }
42     
43     
44     public void parseBody(){
45         
46         // getTextArr().get(1) -> class line
47
// ignore empty lines, first line with { and last
48
// line with }
49
setFields(new ArrayList());
50         setMethods(new ArrayList());
51         
52         Iterator it = getTextArr().iterator();
53         int counter = 0;
54         boolean inMethod = false;
55         while (it.hasNext()){
56             String JavaDoc temp = (String JavaDoc)it.next();
57             if ((temp.trim().equals("}")) && (inMethod)){
58                 inMethod = false;
59             }
60             if (!inMethod){
61                 if (counter < 2){
62                 }
63                 else if (JimpleField.isField(temp)){
64                     getFields().add(temp);
65                 }
66                 else if (JimpleMethod.isMethod(temp)){
67                     getMethods().add(temp);
68                     if (temp.indexOf(";") != -1){
69                     }
70                     else{
71                         inMethod = true;
72                     }
73                 }
74             }
75             counter++;
76         }
77         
78     }
79     
80     /**
81      * @return String
82      */

83     public String JavaDoc getText() {
84         return text;
85     }
86
87     /**
88      * Sets the text.
89      * @param text The text to set
90      */

91     public void setText(String JavaDoc text) {
92         this.text = text;
93     }
94
95     /**
96      * @return
97      */

98     public ArrayList getTextArr() {
99         return textArr;
100     }
101
102     /**
103      * @param list
104      */

105     public void setTextArr(ArrayList list) {
106         textArr = list;
107     }
108
109     /**
110      * @param list
111      */

112     public void setFields(ArrayList list) {
113         fields = list;
114     }
115
116     /**
117      * @param list
118      */

119     public void setMethods(ArrayList list) {
120         methods = list;
121     }
122
123     /**
124      * @return
125      */

126     public ArrayList getFields() {
127         return fields;
128     }
129
130     /**
131      * @return
132      */

133     public ArrayList getMethods() {
134         return methods;
135     }
136
137 }
138
Popular Tags