|
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.io.File; |
|
40 |
| import java.io.IOException; |
|
41 |
| |
|
42 |
| import javax.swing.JButton; |
|
43 |
| import javax.swing.AbstractAction; |
|
44 |
| import java.awt.event.ActionEvent; |
|
45 |
| import javax.swing.JOptionPane; |
|
46 |
| import java.util.*; |
|
47 |
| |
|
48 |
| import edu.rice.cs.drjava.DrJava; |
|
49 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
50 |
| import edu.rice.cs.drjava.config.Option; |
|
51 |
| import edu.rice.cs.drjava.model.DJError; |
|
52 |
| import edu.rice.cs.drjava.model.GlobalModel; |
|
53 |
| import edu.rice.cs.drjava.model.OpenDefinitionsDocument; |
|
54 |
| import edu.rice.cs.drjava.model.DrJavaFileUtils; |
|
55 |
| import edu.rice.cs.drjava.model.definitions.InvalidPackageException; |
|
56 |
| import edu.rice.cs.plt.io.IOUtil; |
|
57 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
58 |
| import edu.rice.cs.plt.collect.CollectUtil; |
|
59 |
| import edu.rice.cs.util.FileOps; |
|
60 |
| import edu.rice.cs.util.UnexpectedException; |
|
61 |
| import edu.rice.cs.util.swing.Utilities; |
|
62 |
| import edu.rice.cs.javalanglevels.*; |
|
63 |
| import edu.rice.cs.javalanglevels.parser.*; |
|
64 |
| import edu.rice.cs.javalanglevels.tree.*; |
|
65 |
| import edu.rice.cs.util.swing.ScrollableListDialog; |
|
66 |
| |
|
67 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| public class DefaultCompilerModel implements CompilerModel { |
|
75 |
| |
|
76 |
| |
|
77 |
| private static edu.rice.cs.util.Log _log = new edu.rice.cs.util.Log("DefaultCompilerModel.txt", false); |
|
78 |
| |
|
79 |
| |
|
80 |
| private final List<CompilerInterface> _compilers; |
|
81 |
| |
|
82 |
| |
|
83 |
| private CompilerInterface _active; |
|
84 |
| |
|
85 |
| |
|
86 |
| private final CompilerEventNotifier _notifier = new CompilerEventNotifier(); |
|
87 |
| |
|
88 |
| |
|
89 |
| private final GlobalModel _model; |
|
90 |
| |
|
91 |
| |
|
92 |
| private CompilerErrorModel _compilerErrorModel; |
|
93 |
| |
|
94 |
| |
|
95 |
| private Object _compilerLock = new Object(); |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| public LanguageLevelStackTraceMapper _LLSTM; |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
157
| public DefaultCompilerModel(GlobalModel m, Iterable<? extends CompilerInterface> compilers) {
|
|
107 |
| |
|
108 |
157
| _compilers = new ArrayList<CompilerInterface>();
|
|
109 |
157
| ArrayList<String> compilerNames = new ArrayList<String>();
|
|
110 |
| |
|
111 |
471
| for (CompilerInterface i : compilers) { _compilers.add(i); compilerNames.add(i.getName());}
|
|
112 |
| |
|
113 |
157
| OptionConstants.COMPILER_PREFERENCE_CONTROL.setList(compilerNames);
|
|
114 |
| |
|
115 |
157
| String dCompName = DrJava.getConfig().getSetting(OptionConstants.DEFAULT_COMPILER_PREFERENCE);
|
|
116 |
| |
|
117 |
157
| if (_compilers.size() > 0) {
|
|
118 |
157
| if (! dCompName.equals(OptionConstants.COMPILER_PREFERENCE_CONTROL.NO_PREFERENCE) &&
|
|
119 |
| compilerNames.contains(dCompName)) |
|
120 |
0
| _active = _compilers.get(compilerNames.indexOf(dCompName));
|
|
121 |
| else |
|
122 |
157
| _active = _compilers.get(0);
|
|
123 |
| } |
|
124 |
| else |
|
125 |
0
| _active = NoCompilerAvailable.ONLY;
|
|
126 |
| |
|
127 |
157
| _model = m;
|
|
128 |
157
| _compilerErrorModel = new CompilerErrorModel(new DJError[0], _model);
|
|
129 |
157
| _LLSTM = new LanguageLevelStackTraceMapper(_model);
|
|
130 |
| } |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
18
| public Object getCompilerLock() { return _compilerLock; }
|
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
317
| public void addListener(CompilerListener listener) { _notifier.addListener(listener); }
|
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
3
| public void removeListener(CompilerListener listener) { _notifier.removeListener(listener); }
|
|
151 |
| |
|
152 |
| |
|
153 |
0
| public void removeAllListeners() { _notifier.removeAllListeners(); }
|
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
11
| public void compileAll() throws IOException {
|
|
170 |
11
| if (_prepareForCompile()) { _doCompile(_model.getOpenDefinitionsDocuments()); }
|
|
171 |
0
| else _notifier.compileAborted(new UnexpectedException("Some modified open files are unsaved"));
|
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
0
| public void compileProject() throws IOException {
|
|
186 |
0
| if (! _model.isProjectActive())
|
|
187 |
0
| throw new UnexpectedException("compileProject invoked when DrJava is not in project mode");
|
|
188 |
| |
|
189 |
0
| if (_prepareForCompile()) { _doCompile(_model.getProjectDocuments()); }
|
|
190 |
0
| else _notifier.compileAborted(new UnexpectedException("Project contains unsaved modified files"));
|
|
191 |
| } |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
0
| public void compile(List<OpenDefinitionsDocument> defDocs) throws IOException {
|
|
205 |
0
| if (_prepareForCompile()) { _doCompile(defDocs); }
|
|
206 |
0
| else _notifier.compileAborted(new UnexpectedException("The files to be compiled include unsaved modified files"));
|
|
207 |
| } |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
48
| public void compile(OpenDefinitionsDocument doc) throws IOException {
|
|
221 |
46
| if (_prepareForCompile()) { _doCompile(Arrays.asList(doc)); }
|
|
222 |
2
| else _notifier.compileAborted(new UnexpectedException(doc + "is modified but unsaved"));
|
|
223 |
| } |
|
224 |
| |
|
225 |
| |
|
226 |
| |
|
227 |
| |
|
228 |
59
| private boolean _prepareForCompile() {
|
|
229 |
6
| if (_model.hasModifiedDocuments()) _notifier.saveBeforeCompile();
|
|
230 |
| |
|
231 |
59
| return ! _model.hasModifiedDocuments();
|
|
232 |
| } |
|
233 |
| |
|
234 |
| |
|
235 |
57
| private void _doCompile(List<OpenDefinitionsDocument> docs) throws IOException {
|
|
236 |
57
| _LLSTM.clearCache();
|
|
237 |
57
| final ArrayList<File> filesToCompile = new ArrayList<File>();
|
|
238 |
57
| final ArrayList<File> excludedFiles = new ArrayList<File>();
|
|
239 |
57
| final ArrayList<DJError> packageErrors = new ArrayList<DJError>();
|
|
240 |
57
| for (OpenDefinitionsDocument doc : docs) {
|
|
241 |
71
| if (doc.isSourceFile()) {
|
|
242 |
61
| File f = doc.getFile();
|
|
243 |
| |
|
244 |
60
| if (f != null && f != FileOps.NULL_FILE) { filesToCompile.add(f); }
|
|
245 |
60
| doc.setCachedClassFile(FileOps.NULL_FILE);
|
|
246 |
| |
|
247 |
60
| try { doc.getSourceRoot(); }
|
|
248 |
| catch (InvalidPackageException e) { |
|
249 |
0
| packageErrors.add(new DJError(f, e.getMessage(), false));
|
|
250 |
| } |
|
251 |
| } |
|
252 |
10
| else excludedFiles.add(doc.getFile());
|
|
253 |
| } |
|
254 |
| |
|
255 |
56
| Utilities.invokeLater(new Runnable() { public void run() { _notifier.compileStarted(); } });
|
|
256 |
56
| try {
|
|
257 |
0
| if (! packageErrors.isEmpty()) { _distributeErrors(packageErrors); }
|
|
258 |
| else { |
|
259 |
56
| try {
|
|
260 |
56
| File buildDir = _model.getBuildDirectory();
|
|
261 |
56
| if (buildDir != null && buildDir != FileOps.NULL_FILE && ! buildDir.exists() && ! buildDir.mkdirs()) {
|
|
262 |
0
| throw new IOException("Could not create build directory: " + buildDir);
|
|
263 |
| } |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
| |
|
268 |
| |
|
269 |
| |
|
270 |
| |
|
271 |
56
| _compileFiles(filesToCompile, buildDir);
|
|
272 |
| } |
|
273 |
| catch (Throwable t) { |
|
274 |
0
| DJError err = new DJError(t.toString(), false);
|
|
275 |
0
| _distributeErrors(Arrays.asList(err));
|
|
276 |
0
| throw new UnexpectedException(t);
|
|
277 |
| } |
|
278 |
| } |
|
279 |
| } |
|
280 |
| finally { |
|
281 |
56
| Utilities.invokeLater(new Runnable() {
|
|
282 |
56
| public void run() { _notifier.compileEnded(_model.getWorkingDirectory(), excludedFiles); }
|
|
283 |
| }); |
|
284 |
| } |
|
285 |
| } |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
0
| private LinkedList<DJError> _parseExceptions2CompilerErrors(LinkedList<JExprParseException> pes) {
|
|
292 |
0
| final LinkedList<DJError> errors = new LinkedList<DJError>();
|
|
293 |
0
| Iterator<JExprParseException> iter = pes.iterator();
|
|
294 |
0
| while (iter.hasNext()) {
|
|
295 |
0
| JExprParseException pe = iter.next();
|
|
296 |
0
| errors.addLast(new DJError(pe.getFile(), pe.currentToken.beginLine-1, pe.currentToken.beginColumn-1,
|
|
297 |
| pe.getMessage(), false)); |
|
298 |
| } |
|
299 |
0
| return errors;
|
|
300 |
| } |
|
301 |
| |
|
302 |
| |
|
303 |
0
| private LinkedList<DJError> _visitorErrors2CompilerErrors(LinkedList<Pair<String, JExpressionIF>> visitorErrors) {
|
|
304 |
0
| final LinkedList<DJError> errors = new LinkedList<DJError>();
|
|
305 |
0
| Iterator<Pair<String, JExpressionIF>> iter = visitorErrors.iterator();
|
|
306 |
0
| while (iter.hasNext()) {
|
|
307 |
0
| Pair<String, JExpressionIF> pair = iter.next();
|
|
308 |
0
| String message = pair.getFirst();
|
|
309 |
| |
|
310 |
0
| JExpressionIF jexpr = pair.getSecond();
|
|
311 |
| |
|
312 |
0
| SourceInfo si;
|
|
313 |
0
| if (jexpr == null) si = SourceInfo.NO_INFO;
|
|
314 |
0
| else si = pair.getSecond().getSourceInfo();
|
|
315 |
| |
|
316 |
0
| errors.addLast(new DJError(si.getFile(), si.getStartLine()-1, si.getStartColumn()-1, message, false));
|
|
317 |
| } |
|
318 |
0
| return errors;
|
|
319 |
| } |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
| |
|
325 |
| |
|
326 |
| |
|
327 |
| |
|
328 |
56
| private void _compileFiles(List<File> files, File buildDir) throws IOException {
|
|
329 |
56
| if (! files.isEmpty()) {
|
|
330 |
| |
|
331 |
55
| if (buildDir == FileOps.NULL_FILE) buildDir = null;
|
|
332 |
0
| if (buildDir != null) buildDir = IOUtil.attemptCanonicalFile(buildDir);
|
|
333 |
| |
|
334 |
55
| List<File> classPath = CollectUtil.makeList(_model.getClassPath());
|
|
335 |
| |
|
336 |
| |
|
337 |
55
| List<File> bootClassPath = null;
|
|
338 |
55
| String bootProp = System.getProperty("drjava.bootclasspath");
|
|
339 |
0
| if (bootProp != null) { bootClassPath = CollectUtil.makeList(IOUtil.parsePath(bootProp)); }
|
|
340 |
| |
|
341 |
55
| final LinkedList<DJError> errors = new LinkedList<DJError>();
|
|
342 |
| |
|
343 |
55
| List<? extends File> preprocessedFiles = _compileLanguageLevelsFiles(files, errors, classPath, bootClassPath);
|
|
344 |
| |
|
345 |
55
| if (errors.isEmpty()) {
|
|
346 |
55
| CompilerInterface compiler = getActiveCompiler();
|
|
347 |
| |
|
348 |
| |
|
349 |
55
| synchronized(_compilerLock) {
|
|
350 |
55
| if (preprocessedFiles == null) {
|
|
351 |
55
| errors.addAll(compiler.compile(files, classPath, null, buildDir, bootClassPath, null, true));
|
|
352 |
| } |
|
353 |
| else { |
|
354 |
| |
|
355 |
| |
|
356 |
0
| errors.addAll(compiler.compile(preprocessedFiles, classPath, null, buildDir, bootClassPath, null, false));
|
|
357 |
| } |
|
358 |
| } |
|
359 |
| } |
|
360 |
55
| _distributeErrors(errors);
|
|
361 |
| } |
|
362 |
| else { |
|
363 |
| |
|
364 |
1
| _distributeErrors(Collections.<DJError>emptyList());
|
|
365 |
| } |
|
366 |
| } |
|
367 |
| |
|
368 |
| |
|
369 |
0
| private static List<File> _testFileSort(List<File> files) {
|
|
370 |
0
| LinkedList<File> testFiles = new LinkedList<File>();
|
|
371 |
0
| LinkedList<File> otherFiles = new LinkedList<File>();
|
|
372 |
0
| for (File f: files) {
|
|
373 |
0
| if (f.getName().contains("Test")) testFiles.add(f);
|
|
374 |
0
| else otherFiles.add(f);
|
|
375 |
| } |
|
376 |
0
| otherFiles.addAll(testFiles);
|
|
377 |
0
| return otherFiles;
|
|
378 |
| } |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
55
| private List<File> _compileLanguageLevelsFiles(List<File> files, List<DJError> errors,
|
|
385 |
| Iterable<File> classPath, Iterable<File> bootClassPath) { |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
55
| HashSet<File> javaFileSet = new HashSet<File>();
|
|
390 |
55
| LinkedList<File> newFiles = new LinkedList<File>();
|
|
391 |
55
| final LinkedList<File> filesToBeClosed = new LinkedList<File>();
|
|
392 |
| |
|
393 |
55
| boolean containsLanguageLevels = false;
|
|
394 |
55
| for (File f : files) {
|
|
395 |
60
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
396 |
60
| String fileName = canonicalFile.getPath();
|
|
397 |
60
| if (DrJavaFileUtils.isLLFile(fileName)) {
|
|
398 |
0
| containsLanguageLevels = true;
|
|
399 |
0
| File javaFile = new File(DrJavaFileUtils.getJavaForLLFile(fileName));
|
|
400 |
| |
|
401 |
| |
|
402 |
0
| if (files.contains(javaFile)) filesToBeClosed.add(javaFile);
|
|
403 |
| |
|
404 |
| else |
|
405 |
| |
|
406 |
0
| javaFile.delete();
|
|
407 |
| |
|
408 |
0
| javaFileSet.add(javaFile);
|
|
409 |
0
| newFiles.add(javaFile);
|
|
410 |
| } |
|
411 |
60
| else javaFileSet.add(canonicalFile);
|
|
412 |
| } |
|
413 |
| |
|
414 |
55
| for (File f: filesToBeClosed) {
|
|
415 |
0
| if (files.contains(DrJavaFileUtils.getDJForJavaFile(f)) ||
|
|
416 |
| files.contains(DrJavaFileUtils.getDJ0ForJavaFile(f)) || |
|
417 |
| files.contains(DrJavaFileUtils.getDJ1ForJavaFile(f)) || |
|
418 |
| files.contains(DrJavaFileUtils.getDJ2ForJavaFile(f))) { |
|
419 |
0
| files.remove(f);
|
|
420 |
| } |
|
421 |
| } |
|
422 |
| |
|
423 |
55
| if (!filesToBeClosed.isEmpty()) {
|
|
424 |
0
| final JButton closeButton = new JButton(new AbstractAction("Close Files") {
|
|
425 |
0
| public void actionPerformed(ActionEvent e) {
|
|
426 |
| |
|
427 |
| } |
|
428 |
| }); |
|
429 |
0
| final JButton keepButton = new JButton(new AbstractAction("Keep Open") {
|
|
430 |
0
| public void actionPerformed(ActionEvent e) {
|
|
431 |
| |
|
432 |
0
| filesToBeClosed.clear();
|
|
433 |
| } |
|
434 |
| }); |
|
435 |
0
| ScrollableListDialog<File> dialog = new ScrollableListDialog.Builder<File>()
|
|
436 |
0
| .setTitle("Java File" + (filesToBeClosed.size() == 1?"":"s") + " Need to Be Closed")
|
|
437 |
0
| .setText("The following .java " + (filesToBeClosed.size() == 1?
|
|
438 |
| "file has a matching .dj? file": |
|
439 |
| "files have matching .dj? files") + " open.\n" + |
|
440 |
0
| (filesToBeClosed.size() == 1?
|
|
441 |
| "This .java file needs": |
|
442 |
| "These .java files need") + " to be closed for proper compiling.") |
|
443 |
| .setItems(filesToBeClosed) |
|
444 |
| .setMessageType(JOptionPane.WARNING_MESSAGE) |
|
445 |
| .setFitToScreen(true) |
|
446 |
| .clearButtons() |
|
447 |
| .addButton(closeButton) |
|
448 |
| .addButton(keepButton) |
|
449 |
| .build(); |
|
450 |
| |
|
451 |
0
| dialog.showDialog();
|
|
452 |
| |
|
453 |
0
| LinkedList<OpenDefinitionsDocument> docsToBeClosed = new LinkedList<OpenDefinitionsDocument>();
|
|
454 |
0
| for(File f: filesToBeClosed) {
|
|
455 |
0
| try {
|
|
456 |
0
| docsToBeClosed.add(_model.getDocumentForFile(f));
|
|
457 |
| } |
|
458 |
| catch(IOException ioe) { } |
|
459 |
| } |
|
460 |
0
| _model.closeFiles(docsToBeClosed);
|
|
461 |
| |
|
462 |
0
| for(File f: filesToBeClosed) {
|
|
463 |
| |
|
464 |
0
| f.delete();
|
|
465 |
| } |
|
466 |
| } |
|
467 |
| |
|
468 |
55
| if (containsLanguageLevels) {
|
|
469 |
| |
|
470 |
0
| final File buildDir = _model.getBuildDirectory();
|
|
471 |
0
| final File sourceDir = _model.getProjectRoot();
|
|
472 |
0
| if (!DrJava.getConfig().getSetting(OptionConstants.DELETE_LL_CLASS_FILES)
|
|
473 |
| .equals(OptionConstants.DELETE_LL_CLASS_FILES_CHOICES.get(0))) { |
|
474 |
| |
|
475 |
0
| final HashSet<File> dirsWithLLFiles = new HashSet<File>();
|
|
476 |
0
| for(File f: newFiles) {
|
|
477 |
0
| try {
|
|
478 |
0
| File dir = f.getParentFile();
|
|
479 |
0
| if (buildDir != null && buildDir != FileOps.NULL_FILE &&
|
|
480 |
| sourceDir != null && sourceDir != FileOps.NULL_FILE) { |
|
481 |
| |
|
482 |
0
| String rel = edu.rice.cs.util.FileOps.stringMakeRelativeTo(dir,sourceDir);
|
|
483 |
0
| dir = new File(buildDir,rel);
|
|
484 |
| } |
|
485 |
0
| dirsWithLLFiles.add(dir);
|
|
486 |
| } |
|
487 |
| catch(IOException ioe) { } |
|
488 |
| } |
|
489 |
| |
|
490 |
0
| if (DrJava.getConfig().getSetting(OptionConstants.DELETE_LL_CLASS_FILES)
|
|
491 |
| .equals(OptionConstants.DELETE_LL_CLASS_FILES_CHOICES.get(1))) { |
|
492 |
| |
|
493 |
0
| final JButton deleteButton = new JButton(new AbstractAction("Delete Class Files") {
|
|
494 |
0
| public void actionPerformed(ActionEvent e) {
|
|
495 |
| |
|
496 |
| } |
|
497 |
| }); |
|
498 |
0
| final JButton keepButton = new JButton(new AbstractAction("Keep Class Files") {
|
|
499 |
0
| public void actionPerformed(ActionEvent e) {
|
|
500 |
| |
|
501 |
0
| dirsWithLLFiles.clear();
|
|
502 |
| } |
|
503 |
| }); |
|
504 |
0
| ScrollableListDialog<File> dialog = new ScrollableListDialog.Builder<File>()
|
|
505 |
| .setTitle("Delete Class Files") |
|
506 |
| .setText("We suggest that you delete all class files in the directories with language\n" + |
|
507 |
| "level files. Do you want to delete the class files in the following director" + |
|
508 |
0
| (dirsWithLLFiles.size() == 1?"y":"ies") + "?")
|
|
509 |
| .setItems(new ArrayList<File>(dirsWithLLFiles)) |
|
510 |
| .setMessageType(JOptionPane.QUESTION_MESSAGE) |
|
511 |
| .setFitToScreen(true) |
|
512 |
| .clearButtons() |
|
513 |
| .addButton(deleteButton) |
|
514 |
| .addButton(keepButton) |
|
515 |
| .build(); |
|
516 |
| |
|
517 |
0
| dialog.showDialog();
|
|
518 |
| } |
|
519 |
| |
|
520 |
| |
|
521 |
| |
|
522 |
0
| for(File f: dirsWithLLFiles) {
|
|
523 |
0
| f.listFiles(new java.io.FilenameFilter() {
|
|
524 |
0
| public boolean accept(File dir, String name) {
|
|
525 |
0
| int endPos = name.lastIndexOf(".class");
|
|
526 |
0
| if (endPos < 0) return false;
|
|
527 |
0
| new File(dir, name).delete();
|
|
528 |
| |
|
529 |
0
| return false;
|
|
530 |
| } |
|
531 |
| }); |
|
532 |
| } |
|
533 |
| } |
|
534 |
| |
|
535 |
| |
|
536 |
0
| LanguageLevelConverter llc = new LanguageLevelConverter();
|
|
537 |
0
| Options llOpts;
|
|
538 |
0
| if (bootClassPath == null) { llOpts = new Options(getActiveCompiler().version(), classPath); }
|
|
539 |
0
| else { llOpts = new Options(getActiveCompiler().version(), classPath, bootClassPath); }
|
|
540 |
| |
|
541 |
| |
|
542 |
| |
|
543 |
| |
|
544 |
| |
|
545 |
| |
|
546 |
0
| Map<File,Set<String>> sourceToTopLevelClassMap = new HashMap<File,Set<String>>();
|
|
547 |
0
| Pair<LinkedList<JExprParseException>, LinkedList<Pair<String, JExpressionIF>>> llErrors =
|
|
548 |
| llc.convert(_testFileSort(files).toArray(new File[0]), llOpts, sourceToTopLevelClassMap); |
|
549 |
| |
|
550 |
0
| errors.addAll(_parseExceptions2CompilerErrors(llErrors.getFirst()));
|
|
551 |
0
| errors.addAll(_visitorErrors2CompilerErrors(llErrors.getSecond()));
|
|
552 |
| |
|
553 |
| |
|
554 |
| |
|
555 |
| |
|
556 |
| } |
|
557 |
| |
|
558 |
0
| if (containsLanguageLevels) { return new LinkedList<File>(javaFileSet); }
|
|
559 |
55
| else { return null; }
|
|
560 |
| } |
|
561 |
| |
|
562 |
| |
|
563 |
| |
|
564 |
| |
|
565 |
56
| private void _distributeErrors(List<? extends DJError> errors) throws IOException {
|
|
566 |
| |
|
567 |
| |
|
568 |
56
| _compilerErrorModel = new CompilerErrorModel(errors.toArray(new DJError[0]), _model);
|
|
569 |
56
| _model.setNumCompErrors(_compilerErrorModel.getNumCompErrors());
|
|
570 |
| } |
|
571 |
| |
|
572 |
| |
|
573 |
| |
|
574 |
| |
|
575 |
185
| public CompilerErrorModel getCompilerErrorModel() { return _compilerErrorModel; }
|
|
576 |
| |
|
577 |
| |
|
578 |
159
| public int getNumErrors() { return getCompilerErrorModel().getNumErrors(); }
|
|
579 |
| |
|
580 |
| |
|
581 |
0
| public int getNumCompErrors() { return getCompilerErrorModel().getNumCompErrors(); }
|
|
582 |
| |
|
583 |
| |
|
584 |
0
| public int getNumWarnings() { return getCompilerErrorModel().getNumWarnings(); }
|
|
585 |
| |
|
586 |
| |
|
587 |
5
| public void resetCompilerErrors() {
|
|
588 |
| |
|
589 |
5
| _compilerErrorModel = new CompilerErrorModel(new DJError[0], _model);
|
|
590 |
| } |
|
591 |
| |
|
592 |
| |
|
593 |
| |
|
594 |
| |
|
595 |
| |
|
596 |
| |
|
597 |
38
| public Iterable<CompilerInterface> getAvailableCompilers() {
|
|
598 |
0
| if (_compilers.isEmpty()) { return IterUtil.singleton(NoCompilerAvailable.ONLY); }
|
|
599 |
38
| else { return IterUtil.snapshot(_compilers); }
|
|
600 |
| } |
|
601 |
| |
|
602 |
| |
|
603 |
| |
|
604 |
| |
|
605 |
| |
|
606 |
962
| public CompilerInterface getActiveCompiler() { return _active; }
|
|
607 |
| |
|
608 |
| |
|
609 |
| |
|
610 |
| |
|
611 |
| |
|
612 |
| |
|
613 |
| |
|
614 |
| |
|
615 |
0
| public void setActiveCompiler(CompilerInterface compiler) {
|
|
616 |
0
| if (_compilers.isEmpty() && compiler.equals(NoCompilerAvailable.ONLY)) {
|
|
617 |
| |
|
618 |
| } |
|
619 |
0
| else if (_compilers.contains(compiler)) {
|
|
620 |
0
| _active = compiler;
|
|
621 |
0
| _notifier.activeCompilerChanged();
|
|
622 |
| } |
|
623 |
| else { |
|
624 |
0
| throw new IllegalArgumentException("Compiler is not in the list of available compilers: " + compiler);
|
|
625 |
| } |
|
626 |
| } |
|
627 |
| |
|
628 |
| |
|
629 |
0
| public void addCompiler(CompilerInterface compiler) {
|
|
630 |
0
| if (_compilers.isEmpty()) {
|
|
631 |
0
| _active = compiler;
|
|
632 |
| } |
|
633 |
0
| _compilers.add(compiler);
|
|
634 |
| } |
|
635 |
| |
|
636 |
| |
|
637 |
| |
|
638 |
| |
|
639 |
| |
|
640 |
| |
|
641 |
0
| public void smartDeleteClassFiles(Map<File,Set<String>> sourceToTopLevelClassMap) {
|
|
642 |
0
| final File buildDir = _model.getBuildDirectory();
|
|
643 |
0
| final File sourceDir = _model.getProjectRoot();
|
|
644 |
| |
|
645 |
| |
|
646 |
| |
|
647 |
| |
|
648 |
0
| Map<File,Set<String>> dirToClassNameMap = new HashMap<File,Set<String>>();
|
|
649 |
0
| for(Map.Entry<File,Set<String>> e: sourceToTopLevelClassMap.entrySet()) {
|
|
650 |
0
| try {
|
|
651 |
0
| File dir = e.getKey().getParentFile();
|
|
652 |
0
| if (buildDir != null && buildDir != FileOps.NULL_FILE &&
|
|
653 |
| sourceDir != null && sourceDir != FileOps.NULL_FILE) { |
|
654 |
| |
|
655 |
0
| String rel = edu.rice.cs.util.FileOps.stringMakeRelativeTo(dir,sourceDir);
|
|
656 |
0
| dir = new File(buildDir,rel);
|
|
657 |
| } |
|
658 |
0
| Set<String> classNames = dirToClassNameMap.get(dir);
|
|
659 |
0
| if (classNames == null) classNames = new HashSet<String>();
|
|
660 |
0
| classNames.addAll(e.getValue());
|
|
661 |
0
| dirToClassNameMap.put(dir,classNames);
|
|
662 |
| |
|
663 |
| |
|
664 |
| |
|
665 |
| |
|
666 |
| } |
|
667 |
| catch(IOException ioe) { } |
|
668 |
| } |
|
669 |
| |
|
670 |
| |
|
671 |
0
| for(final Map.Entry<File,Set<String>> e: dirToClassNameMap.entrySet()) {
|
|
672 |
| |
|
673 |
| |
|
674 |
0
| e.getKey().listFiles(new java.io.FilenameFilter() {
|
|
675 |
0
| public boolean accept(File dir, String name) {
|
|
676 |
| |
|
677 |
0
| int endPos = name.lastIndexOf(".class");
|
|
678 |
0
| if (endPos < 0) return false;
|
|
679 |
0
| int dollarPos = name.indexOf('$');
|
|
680 |
0
| if ((dollarPos >= 0) && (dollarPos < endPos)) endPos = dollarPos;
|
|
681 |
| |
|
682 |
0
| Set<String> classNames = e.getValue();
|
|
683 |
0
| if (classNames.contains(name.substring(0,endPos))) {
|
|
684 |
| |
|
685 |
0
| new File(dir, name).delete();
|
|
686 |
| |
|
687 |
| |
|
688 |
| } |
|
689 |
0
| return false;
|
|
690 |
| } |
|
691 |
| }); |
|
692 |
| } |
|
693 |
| } |
|
694 |
| |
|
695 |
| |
|
696 |
| |
|
697 |
| |
|
698 |
13
| public LanguageLevelStackTraceMapper getLLSTM() { return _LLSTM; }
|
|
699 |
| } |