Lines 40-47
Link Here
|
40 |
*/ |
40 |
*/ |
41 |
package org.netbeans.modules.parsing.impl.indexing.errors; |
41 |
package org.netbeans.modules.parsing.impl.indexing.errors; |
42 |
|
42 |
|
|
|
43 |
import java.beans.PropertyChangeEvent; |
43 |
import org.netbeans.api.java.classpath.ClassPath; |
44 |
import org.netbeans.api.java.classpath.ClassPath; |
44 |
import java.awt.Image; |
45 |
import java.awt.Image; |
|
|
46 |
import java.beans.PropertyChangeListener; |
45 |
import java.io.File; |
47 |
import java.io.File; |
46 |
import java.io.IOException; |
48 |
import java.io.IOException; |
47 |
import java.net.URL; |
49 |
import java.net.URL; |
Lines 59-71
Link Here
|
59 |
import org.netbeans.api.fileinfo.NonRecursiveFolder; |
61 |
import org.netbeans.api.fileinfo.NonRecursiveFolder; |
60 |
import org.netbeans.api.project.FileOwnerQuery; |
62 |
import org.netbeans.api.project.FileOwnerQuery; |
61 |
import org.netbeans.api.project.Project; |
63 |
import org.netbeans.api.project.Project; |
|
|
64 |
import org.netbeans.api.project.ui.OpenProjects; |
62 |
import org.netbeans.modules.masterfs.providers.AnnotationProvider; |
65 |
import org.netbeans.modules.masterfs.providers.AnnotationProvider; |
63 |
import org.netbeans.modules.masterfs.providers.InterceptionListener; |
66 |
import org.netbeans.modules.masterfs.providers.InterceptionListener; |
64 |
import org.openide.filesystems.FileObject; |
67 |
import org.openide.filesystems.FileObject; |
65 |
import org.openide.filesystems.FileStateInvalidException; |
68 |
import org.openide.filesystems.FileStateInvalidException; |
66 |
import org.openide.filesystems.FileStatusEvent; |
69 |
import org.openide.filesystems.FileStatusEvent; |
67 |
import org.openide.filesystems.FileUtil; |
70 |
import org.openide.filesystems.FileUtil; |
|
|
71 |
import org.openide.util.Exceptions; |
68 |
import org.openide.util.Lookup; |
72 |
import org.openide.util.Lookup; |
|
|
73 |
import org.openide.util.Mutex.ExceptionAction; |
69 |
import org.openide.util.RequestProcessor; |
74 |
import org.openide.util.RequestProcessor; |
70 |
|
75 |
|
71 |
import static org.openide.util.ImageUtilities.assignToolTipToImage; |
76 |
import static org.openide.util.ImageUtilities.assignToolTipToImage; |
Lines 237-245
Link Here
|
237 |
return null; |
242 |
return null; |
238 |
} |
243 |
} |
239 |
|
244 |
|
240 |
private static final int IN_ERROR_REC = 1; |
245 |
static final int IN_ERROR_REC = 1; |
241 |
private static final int IN_ERROR_NONREC = 2; |
246 |
static final int IN_ERROR_NONREC = 2; |
242 |
private static final int INVALID = 4; |
247 |
static final int INVALID = 4; |
|
|
248 |
static final int FILE_IN_ERROR_NONREC_HACK = 8; |
243 |
|
249 |
|
244 |
private Map<FileObject, Integer> knownFiles2Error = new WeakHashMap<FileObject, Integer>(); |
250 |
private Map<FileObject, Integer> knownFiles2Error = new WeakHashMap<FileObject, Integer>(); |
245 |
|
251 |
|
Lines 276-282
Link Here
|
276 |
|
282 |
|
277 |
private long cumulativeTime; |
283 |
private long cumulativeTime; |
278 |
private Collection<FileObject> toProcess = null; |
284 |
private Collection<FileObject> toProcess = null; |
279 |
|
285 |
|
280 |
private final RequestProcessor.Task WORKER = new RequestProcessor("ErrorAnnotator worker", 1).create(new Runnable() { |
286 |
private final RequestProcessor.Task WORKER = new RequestProcessor("ErrorAnnotator worker", 1).create(new Runnable() { |
281 |
public void run() { |
287 |
public void run() { |
282 |
long startTime = System.currentTimeMillis(); |
288 |
long startTime = System.currentTimeMillis(); |
Lines 345-348
Link Here
|
345 |
Logger.getLogger(ErrorAnnotator.class.getName()).log(Level.FINE, "time spent in error annotations computation: {0}, cumulative time: {1}", new Object[] {(endTime - startTime), (cumulativeTime += (endTime - startTime))}); |
351 |
Logger.getLogger(ErrorAnnotator.class.getName()).log(Level.FINE, "time spent in error annotations computation: {0}, cumulative time: {1}", new Object[] {(endTime - startTime), (cumulativeTime += (endTime - startTime))}); |
346 |
} |
352 |
} |
347 |
}); |
353 |
}); |
|
|
354 |
|
355 |
private static void fillInErrorCache(FileObject root, Map<FileObject, Integer> errors) { |
356 |
TaskCache.getDefault().fillIn(root, errors); |
357 |
} |
358 |
|
359 |
private static final RequestProcessor PRELOAD_WORKER = new RequestProcessor("ErrorAnnotator preload worker", 1, true, false); |
360 |
private final Set<FileObject> preloaded = new HashSet<FileObject>(); |
361 |
|
362 |
private void preloadAll() { |
363 |
long start = System.currentTimeMillis(); |
364 |
try { |
365 |
TaskCache.getDefault().refreshTransaction(new ExceptionAction<Void>() { |
366 |
@Override |
367 |
public Void run() throws Exception { |
368 |
synchronized(ErrorAnnotator.this) { |
369 |
Project[] open = OpenProjects.getDefault().getOpenProjects(); |
370 |
Set<FileObject> removed = new HashSet<FileObject>(preloaded); |
371 |
|
372 |
for (Project prj : open) { |
373 |
if (Thread.interrupted()) { |
374 |
return null; |
375 |
} |
376 |
for (FileObject root : Utilities.findIndexedRootsUnderDirectory(prj, prj.getProjectDirectory())) { |
377 |
if (Thread.interrupted()) { |
378 |
return null; |
379 |
} |
380 |
fillInErrorCache(root, knownFiles2Error); |
381 |
if (Thread.interrupted()) { |
382 |
return null; |
383 |
} |
384 |
removed.remove(root); |
385 |
preloaded.add(root); |
386 |
} |
387 |
} |
388 |
|
389 |
preloaded.removeAll(removed); |
390 |
|
391 |
return null; |
392 |
} |
393 |
} |
394 |
}); |
395 |
} catch (IOException ex) { |
396 |
Exceptions.printStackTrace(ex); |
397 |
} finally { |
398 |
long end = System.currentTimeMillis(); |
399 |
|
400 |
System.err.println("preloading took: " + (end - start)); |
401 |
} |
402 |
} |
403 |
|
404 |
private final RequestProcessor.Task preloadTask = PRELOAD_WORKER.create(new Runnable() { |
405 |
@Override |
406 |
public void run() { |
407 |
preloadAll(); |
408 |
} |
409 |
}); |
410 |
|
411 |
private static final class ProjectOpenedListenerImpl implements PropertyChangeListener { |
412 |
|
413 |
@Override |
414 |
public void propertyChange(PropertyChangeEvent evt) { |
415 |
ErrorAnnotator a = getAnnotator(); |
416 |
|
417 |
a.preloadTask.cancel(); |
418 |
a.preloadTask.schedule(0); |
419 |
} |
420 |
|
421 |
} |
422 |
|
423 |
public static void setProjectListener() { |
424 |
OpenProjects.getDefault().addPropertyChangeListener(new ProjectOpenedListenerImpl()); |
425 |
} |
348 |
} |
426 |
} |