|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.model.compiler; |
|
38 |
| |
|
39 |
| import java.awt.EventQueue; |
|
40 |
| import java.io.File; |
|
41 |
| import java.io.IOException; |
|
42 |
| import java.io.BufferedReader; |
|
43 |
| import java.io.FileReader; |
|
44 |
| |
|
45 |
| import java.util.List; |
|
46 |
| import java.util.HashMap; |
|
47 |
| import java.util.HashSet; |
|
48 |
| import java.util.Set; |
|
49 |
| import java.util.TreeMap; |
|
50 |
| |
|
51 |
| import edu.rice.cs.drjava.model.GlobalModel; |
|
52 |
| import edu.rice.cs.drjava.model.OpenDefinitionsDocument; |
|
53 |
| import edu.rice.cs.drjava.model.DrJavaFileUtils; |
|
54 |
| import edu.rice.cs.util.swing.Utilities; |
|
55 |
| |
|
56 |
| |
|
57 |
| public class LanguageLevelStackTraceMapper { |
|
58 |
| |
|
59 |
| |
|
60 |
| public static final edu.rice.cs.util.Log LOG = new edu.rice.cs.util.Log("llstm.txt",false); |
|
61 |
| |
|
62 |
| |
|
63 |
| private HashMap<String,TreeMap<Integer,Integer>> cache; |
|
64 |
| |
|
65 |
| |
|
66 |
| private GlobalModel aGModel; |
|
67 |
| |
|
68 |
| |
|
69 |
157
| public LanguageLevelStackTraceMapper(GlobalModel aGM){
|
|
70 |
157
| aGModel = aGM;
|
|
71 |
157
| cache = new HashMap<String,TreeMap<Integer,Integer>>();
|
|
72 |
| } |
|
73 |
| |
|
74 |
0
| public StackTraceElement replaceStackTraceElement(StackTraceElement s, File d, TreeMap<Integer,Integer> m) {
|
|
75 |
| |
|
76 |
0
| int jl = s.getLineNumber();
|
|
77 |
0
| int lll = m.containsKey(jl) ? m.get(jl) : -1;
|
|
78 |
| |
|
79 |
0
| return new StackTraceElement(s.getClassName(), s.getMethodName(), d.getName(), lll);
|
|
80 |
| } |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
0
| public StackTraceElement replaceStackTraceElement(StackTraceElement s, File d) {
|
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
0
| if (! matches(d, s)) return s;
|
|
95 |
0
| String fileName = d.getAbsolutePath();
|
|
96 |
0
| if (cache.containsKey(fileName)) return replaceStackTraceElement(s, d, cache.get(fileName));
|
|
97 |
| |
|
98 |
0
| String dn = d.getName();
|
|
99 |
0
| dn = dn.substring(0, dn.lastIndexOf('.')) + edu.rice.cs.drjava.config.OptionConstants.JAVA_FILE_EXTENSION;
|
|
100 |
0
| File javaFile = new File(d.getParentFile(), dn);
|
|
101 |
| |
|
102 |
0
| TreeMap<Integer, Integer> djToJavaMap = readLLLineBlock(javaFile);
|
|
103 |
| |
|
104 |
0
| cache.put(fileName, djToJavaMap);
|
|
105 |
| |
|
106 |
0
| return replaceStackTraceElement(s, d, djToJavaMap);
|
|
107 |
| } |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
453
| public StackTraceElement replaceStackTraceElement(StackTraceElement s, List<File> ds) {
|
|
114 |
453
| for (int i = 0; i < ds.size(); i++) {
|
|
115 |
0
| s = replaceStackTraceElement(s, ds.get(i));
|
|
116 |
| } |
|
117 |
453
| return s;
|
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
13
| public StackTraceElement[] replaceStackTrace(StackTraceElement[] ss, List<File> ds) {
|
|
127 |
13
| for(int i = 0; i < ss.length; i++) {
|
|
128 |
453
| ss[i] = replaceStackTraceElement(ss[i], ds);
|
|
129 |
| } |
|
130 |
13
| return ss;
|
|
131 |
| } |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
57
| public void clearCache() {
|
|
138 |
57
| cache = new HashMap<String,TreeMap<Integer,Integer>>();
|
|
139 |
| } |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
0
| private boolean matches(File f, StackTraceElement s) {
|
|
147 |
0
| LOG.log("matches(" + f + ", " + s + ")");
|
|
148 |
0
| if (s.getFileName() == null) return false;
|
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
0
| String fn = f.getPath();
|
|
156 |
| |
|
157 |
| |
|
158 |
0
| if (! DrJavaFileUtils.isLLFile(fn)) return false;
|
|
159 |
| |
|
160 |
| |
|
161 |
0
| String javaFn = DrJavaFileUtils.getJavaForLLFile(fn);
|
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
0
| return javaFn.endsWith(s.getFileName());
|
|
177 |
| } |
|
178 |
| |
|
179 |
0
| private TreeMap<Integer, Integer> createOneToOneMap(BufferedReader bufReader) {
|
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
0
| TreeMap<Integer, Integer> oneToOne = new TreeMap<Integer, Integer>();
|
|
187 |
0
| int lineNo = 1;
|
|
188 |
0
| oneToOne.put(lineNo,lineNo);
|
|
189 |
0
| try {
|
|
190 |
0
| String rdLine;
|
|
191 |
0
| while((rdLine = bufReader.readLine()) != null) {
|
|
192 |
0
| ++lineNo;
|
|
193 |
0
| oneToOne.put(lineNo,lineNo);
|
|
194 |
| } |
|
195 |
| } |
|
196 |
| catch(java.io.IOException e) { } |
|
197 |
0
| return oneToOne;
|
|
198 |
| } |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
0
| public TreeMap<Integer, Integer> readLLLineBlock(File LLFile){
|
|
204 |
| |
|
205 |
0
| BufferedReader bufReader = null;
|
|
206 |
0
| String rdLine = "";
|
|
207 |
| |
|
208 |
0
| try { bufReader = new BufferedReader(new FileReader(LLFile)); } catch(java.io.FileNotFoundException e){ }
|
|
209 |
| |
|
210 |
0
| try { rdLine = bufReader.readLine(); } catch(java.io.IOException e){ }
|
|
211 |
| |
|
212 |
0
| if (! rdLine.startsWith("// Language Level Converter line number map: dj*->java. Entries:")) {
|
|
213 |
| |
|
214 |
0
| return createOneToOneMap(bufReader);
|
|
215 |
| } |
|
216 |
| |
|
217 |
| |
|
218 |
0
| LOG.log("rdLine = '" + rdLine + "'");
|
|
219 |
0
| LOG.log("\tlastIndex = " + rdLine.lastIndexOf(" "));
|
|
220 |
0
| Integer mapSize = new Integer (rdLine.substring(rdLine.lastIndexOf(" ") + 1));
|
|
221 |
| |
|
222 |
0
| try { rdLine = bufReader.readLine(); } catch(java.io.IOException e){ }
|
|
223 |
| |
|
224 |
0
| if (rdLine.indexOf("//") != 0) mapSize = 0;
|
|
225 |
| |
|
226 |
| |
|
227 |
0
| TreeMap<Integer,Integer> javaDJMap = new TreeMap<Integer,Integer>();
|
|
228 |
| |
|
229 |
| |
|
230 |
| |
|
231 |
0
| String text = rdLine.substring(2).trim() + " ";
|
|
232 |
| |
|
233 |
0
| Integer djNum;
|
|
234 |
0
| Integer javaNum;
|
|
235 |
| |
|
236 |
| |
|
237 |
0
| for (int i = 0; i < mapSize; i++) {
|
|
238 |
0
| if (text.length() < 2) text = readNextLLBlockLine(bufReader);
|
|
239 |
0
| if (text == null) break;
|
|
240 |
| |
|
241 |
0
| int firstBlankPos = text.indexOf(" ");
|
|
242 |
0
| String numRnum = text.substring(0, firstBlankPos);
|
|
243 |
0
| text = text.substring(firstBlankPos).trim() + " ";
|
|
244 |
| |
|
245 |
0
| djNum = new Integer(numRnum.substring(0, numRnum.indexOf("->")));
|
|
246 |
0
| javaNum = new Integer(numRnum.substring(numRnum.indexOf("->") + 2));
|
|
247 |
| |
|
248 |
0
| javaDJMap.put(javaNum,djNum);
|
|
249 |
| } |
|
250 |
0
| return javaDJMap;
|
|
251 |
| } |
|
252 |
| |
|
253 |
| |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
0
| public TreeMap<Integer, Integer> readLLBlock(File LLFile) {
|
|
259 |
| |
|
260 |
0
| BufferedReader bufReader = null;
|
|
261 |
0
| String rdLine = "";
|
|
262 |
| |
|
263 |
0
| try { bufReader = new BufferedReader(new FileReader(LLFile)); } catch(java.io.FileNotFoundException e){ }
|
|
264 |
| |
|
265 |
0
| try { rdLine = bufReader.readLine(); } catch(java.io.IOException e){ }
|
|
266 |
| |
|
267 |
0
| if (! rdLine.startsWith("// Language Level Converter line number map: dj*->java. Entries:")) {
|
|
268 |
| |
|
269 |
0
| return createOneToOneMap(bufReader);
|
|
270 |
| } |
|
271 |
| |
|
272 |
0
| LOG.log("rdLine = '" + rdLine + "'");
|
|
273 |
0
| LOG.log("\tlastIndex = " + rdLine.lastIndexOf(" "));
|
|
274 |
0
| Integer mapSize = new Integer (rdLine.substring(rdLine.lastIndexOf(" ") + 1));
|
|
275 |
| |
|
276 |
0
| try { rdLine = bufReader.readLine(); } catch(java.io.IOException e){ }
|
|
277 |
| |
|
278 |
0
| if(rdLine.indexOf("//") != 0) mapSize = 0;
|
|
279 |
| |
|
280 |
0
| TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
|
|
281 |
| |
|
282 |
0
| String text = rdLine.substring(2).trim() + " ";
|
|
283 |
0
| String numRnum = "";
|
|
284 |
| |
|
285 |
0
| int djNum;
|
|
286 |
0
| int javaNum;
|
|
287 |
| |
|
288 |
0
| for(int i = 0; i < mapSize; i++) {
|
|
289 |
0
| if (text.length() < 2) text = readNextLLBlockLine(bufReader);
|
|
290 |
0
| if (text == null) break;
|
|
291 |
| |
|
292 |
0
| numRnum = text.substring(0, text.indexOf(" "));
|
|
293 |
| |
|
294 |
0
| djNum = Integer.parseInt(numRnum.substring(0, numRnum.indexOf("->")), 10);
|
|
295 |
0
| javaNum = Integer.parseInt(numRnum.substring(numRnum.indexOf("->") + 2), 10);
|
|
296 |
| |
|
297 |
0
| map.put(djNum, javaNum);
|
|
298 |
0
| text = text.substring(text.indexOf(" ")).trim() + " ";
|
|
299 |
| |
|
300 |
| } |
|
301 |
0
| return map;
|
|
302 |
| } |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
0
| private String readNextLLBlockLine(BufferedReader br) {
|
|
307 |
0
| String line = "";
|
|
308 |
0
| try { line = br.readLine(); } catch(java.io.IOException e){ }
|
|
309 |
| |
|
310 |
0
| if (line.indexOf("//") != 0) return null;
|
|
311 |
0
| line = line.substring(2).trim() + " ";
|
|
312 |
0
| return line;
|
|
313 |
| } |
|
314 |
| } |