private void stateChangedImpl(List<FileObject> currentFiles) { Map<VisageSource, CancellableTask<CompilationInfo>> toRemove = new HashMap<VisageSource, CancellableTask<CompilationInfo>>(); Map<VisageSource, CancellableTask<CompilationInfo>> toAdd = new HashMap<VisageSource, CancellableTask<CompilationInfo>>(); synchronized (this) { List<FileObject> addedFiles = new ArrayList<FileObject>(currentFiles); List<FileObject> removedFiles = new ArrayList<FileObject>(file2Task.keySet()); addedFiles.removeAll(file2Task.keySet()); removedFiles.removeAll(currentFiles); // remove old tasks: for (FileObject r : removedFiles) { VisageSource source = file2JS.remove(r); if (source == null) { // TODO: log continue; } toRemove.put(source, file2Task.remove(r)); } // add new tasks: for (FileObject a : addedFiles) { if (a == null) continue; if (!a.isValid()) { continue; } VisageSource js = VisageSource.forFileObject(a); if (js != null) { CancellableTask<CompilationInfo> task = createTask(a); toAdd.put(js, task); file2Task.put(a, task); file2JS.put(a, js); } } } LOG.log(Level.FINEST, BEFORE_ADDING_REMOVING_TASKS); for (Entry<VisageSource, CancellableTask<CompilationInfo>> e : toRemove.entrySet()) { VisageTaskProcessor.removePhaseCompletionTask(e.getKey(), e.getValue()); } for (Entry<VisageSource, CancellableTask<CompilationInfo>> e : toAdd.entrySet()) { try { VisageTaskProcessor.addPhaseCompletionTask(e.getKey(), e.getValue(), phase, priority); // } catch (FileObjects.InvalidFileException ie) { // LOG.info("VisageSource.addPhaseCompletionTask called on deleted file"); // //NOI18N } catch (IOException ex) { ErrorManager.getDefault().notify(ex); } } }