diff --git a/platform/core-api/src/com/intellij/util/FileContentUtilCore.java b/platform/core-api/src/com/intellij/util/FileContentUtilCore.java index 2578fdeb5d58..93833db7002c 100644 --- a/platform/core-api/src/com/intellij/util/FileContentUtilCore.java +++ b/platform/core-api/src/com/intellij/util/FileContentUtilCore.java @@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent; import gnu.trove.THashSet; @@ -28,6 +29,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Set; /** @@ -47,28 +49,27 @@ public class FileContentUtilCore { saveOrReload(file, events); } - ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES) - .before(new ArrayList(events)); - ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES) - .after(new ArrayList(events)); + BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES); + List eventList = new ArrayList(events); + publisher.before(eventList); + publisher.after(eventList); } }); } - private static void saveOrReload(final VirtualFile virtualFile, Collection events) { - if (virtualFile == null || virtualFile.isDirectory() || !virtualFile.isValid()) { + private static void saveOrReload(VirtualFile file, Collection events) { + if (file == null || file.isDirectory() || !file.isValid()) { return; } - final FileDocumentManager documentManager = FileDocumentManager.getInstance(); - if (documentManager.isFileModified(virtualFile)) { - Document document = documentManager.getDocument(virtualFile); + + FileDocumentManager documentManager = FileDocumentManager.getInstance(); + if (documentManager.isFileModified(file)) { + Document document = documentManager.getDocument(file); if (document != null) { documentManager.saveDocument(document); } } - events.add( - new VFilePropertyChangeEvent(FORCE_RELOAD_REQUESTOR, virtualFile, VirtualFile.PROP_NAME, virtualFile.getName(), virtualFile.getName(), - false)); - } + events.add(new VFilePropertyChangeEvent(FORCE_RELOAD_REQUESTOR, file, VirtualFile.PROP_NAME, file.getName(), file.getName(), false)); + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 2c0566aeb8ad..05e47671122b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -188,7 +188,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { VirtualFile parent = file.getParent(); if (!(parent instanceof NewVirtualFile)) return; DirectoryInfo existing = myState.getInfo(((NewVirtualFile)file).getId()); - assert existing == null : file+" -> "+existing; + assert existing == null : file + " -> " + existing; IndexState newState = updateStateWithNewFile((NewVirtualFile)file, (NewVirtualFile)parent); replaceState(newState); } @@ -251,8 +251,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { if (parentInfo.hasLibraryClassRoot()) { String newDirPackageName = getPackageNameForSubdir(parentPackage, file.getName()); - state.fillMapWithLibraryClasses(file, newDirPackageName, (NewVirtualFile)parentInfo.getLibraryClassRoot(), null, interned, - null); + state.fillMapWithLibraryClasses(file, newDirPackageName, (NewVirtualFile)parentInfo.getLibraryClassRoot(), null, interned, null); } if (parentInfo.isInLibrarySource()) { @@ -303,12 +302,14 @@ public class DirectoryIndexImpl extends DirectoryIndex { IndexState copy = null; for (int id : list) { if (myState.getInfo(id) != null) { - if (copy == null) copy = myState.copy(new TIntProcedure() { - @Override - public boolean execute(int fid) { - return ArrayUtil.indexOf(list, fid) == -1; - } - }); + if (copy == null) { + copy = myState.copy(new TIntProcedure() { + @Override + public boolean execute(int fid) { + return ArrayUtil.indexOf(list, fid) == -1; + } + }); + } copy.myDirToInfoMap.remove(id); copy.setPackageName(id, null); @@ -342,7 +343,6 @@ public class DirectoryIndexImpl extends DirectoryIndex { } private boolean myBatchChangePlanned; - private static final boolean ourCanHaveBatchUpdate = true; @Override public void before(@NotNull List events) { @@ -354,40 +354,40 @@ public class DirectoryIndexImpl extends DirectoryIndex { int directoriesRemoved = 0; int directoriesCreated = 0; - for(VFileEvent event:events) { + for (VFileEvent event : events) { if (event instanceof VFileDeleteEvent) { VirtualFile file = event.getFile(); if (file != null && file.isDirectory()) { directoriesRemoved += 1 + countDirectories(file, MAX_DEPTH_TO_COUNT); } - } else if(event instanceof VFileCreateEvent) { + } + else if (event instanceof VFileCreateEvent) { VirtualFile file = event.getFile(); if (file != null && file.isDirectory() || - file == null && ((VFileCreateEvent)event).isDirectory() - ) { + file == null && ((VFileCreateEvent)event).isDirectory()) { directoriesCreated += 1 + countDirectories(file, MAX_DEPTH_TO_COUNT); } } } final boolean willDoBatchUpdate = directoriesCreated + directoriesRemoved > DIRECTORIES_CHANGED_THRESHOLD; - - if (willDoBatchUpdate && ourCanHaveBatchUpdate) { + if (willDoBatchUpdate) { myBatchChangePlanned = true; - LOG.info("Too many directories created / deleted: " + directoriesCreated + "," + directoriesRemoved + ", will rebuild indexstate"); - } else { + LOG.info("Too many directories created / deleted: " + directoriesCreated + "," + directoriesRemoved + ", will rebuild index state"); + } + else { for (VFileEvent event : events) { BulkVirtualFileListenerAdapter.fireBefore(this, event); } } } - private int countDirectories(VirtualFile file, int depth) { + private int countDirectories(@Nullable VirtualFile file, int depth) { if (!(file instanceof NewVirtualFile)) return 0; int counter = 0; - for(VirtualFile child:((NewVirtualFile)file).iterInDbChildren()) { - if (child.isDirectory()) counter += 1 + (depth > 0 ? countDirectories(child, depth - 1):0); + for (VirtualFile child : ((NewVirtualFile)file).iterInDbChildren()) { + if (child.isDirectory()) counter += 1 + (depth > 0 ? countDirectories(child, depth - 1) : 0); } return counter; } @@ -615,7 +615,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { if (ourUseRootIndexOnly) { return riInfo; } - + return assertConsistentResult(dir, riInfo, myState.getInfo(((NewVirtualFile)dir).getId())); } @@ -636,7 +636,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { if (ourUseRootIndexOnly) { return riType; } - + return assertConsistentResult(info, riType, myState.getRootTypeById(info.getSourceRootTypeId())); } return null; @@ -677,7 +677,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { if (ourUseRootIndexOnly) { return riResult; } - + return assertConsistentResult(dir, riResult, myState.getPackageNameForDirectory((NewVirtualFile)dir)); } @@ -1038,11 +1038,11 @@ public class DirectoryIndexImpl extends DirectoryIndex { @NotNull final NewVirtualFile sourceRoot, final int rootTypeId, @Nullable final ProgressIndicator progress, - final @Nullable TObjectIntHashMap interned - ) { + final @Nullable TObjectIntHashMap interned) { assertWritable(); if (!isValid(dir)) return; - assert VfsUtilCore.isAncestor(sourceRoot, dir, false) : "SourceRoot: "+sourceRoot+" ("+sourceRoot.getFileSystem()+"); dir: "+dir+" ("+dir.getFileSystem()+")"; + assert VfsUtilCore.isAncestor(sourceRoot, dir, false) : + "SourceRoot: "+sourceRoot+" ("+sourceRoot.getFileSystem()+"); dir: "+dir+" ("+dir.getFileSystem()+")"; VfsUtilCore.visitChildrenRecursively(dir, new DirectoryVisitor() { private final Stack myPackages = new Stack(); @@ -1061,7 +1061,8 @@ public class DirectoryIndexImpl extends DirectoryIndex { if (isAnotherRoot(id)) return null; // another source root starts here } - assert VfsUtilCore.isAncestor(dir, file, false) : "dir: " + dir + " (" + dir.getFileSystem() + "); file: " + file + " (" + file.getFileSystem() + ")"; + assert VfsUtilCore.isAncestor(dir, file, false) : + "dir: " + dir + " (" + dir.getFileSystem() + "); file: " + file + " (" + file.getFileSystem() + ")"; int flag = DirectoryInfo.createSourceRootTypeData(true, info.isInLibrarySource(), rootTypeId); info = with(id, info, null, null, sourceRoot, null, flag, null); @@ -1223,7 +1224,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { } return null; } - + private void initOrderEntries(@NotNull Module module, @NotNull MultiMap depEntries, @NotNull MultiMap libClassRootEntries, @@ -1614,19 +1615,19 @@ public class DirectoryIndexImpl extends DirectoryIndex { private void assertAncestor(@NotNull DirectoryInfo info, @NotNull VirtualFile root, int myId) { VirtualFile myFile = findFileById(myId); - assert myFile.getFileSystem() == root.getFileSystem() : myFile.getFileSystem() +", "+ root.getFileSystem() +"; my file: "+myFile+"; root: "+root + "; "+ - myFile.getParent().getPath().equals(root.getPath()); - assert VfsUtilCore.isAncestor(root, myFile, false) : "my file: "+myFile+" ("+ - ((NewVirtualFile)myFile).getId() +")" + myFile.getClass() + " - " +System.identityHashCode(myFile) + - "; root: "+root +" ("+ - ((NewVirtualFile)root).getId() +")" + root.getClass() + " - " +System.identityHashCode(root) + - "; equalsToParent:"+ (myFile.getParent() == null ? "" : myFile.getParent().getPath()).equals(root.getPath()) + - "; equalsToRoot:"+ myFile.equals(root) + - "; equalsToRootPath:"+ myFile.getPath().equals(root.getPath()) + - "; my contentRoot: "+info.getContentRoot()+ - "; my sourceRoot: "+info.getSourceRoot()+ - "; my classRoot: "+info.getLibraryClassRoot() + - "; path is substring: "+FileUtil.isAncestor(root.getPath(), myFile.getPath(), false) + assert myFile.getFileSystem() == root.getFileSystem() : + myFile.getFileSystem() + ", " + root.getFileSystem() + "; my file: " + myFile + "; root: " + root + "; " + + myFile.getParent().getPath().equals(root.getPath()); + assert VfsUtilCore.isAncestor(root, myFile, false) : + "my file: " + myFile + " (" + ((NewVirtualFile)myFile).getId() + ")" + myFile.getClass() + " - " + System.identityHashCode(myFile) + + "; root: " + root + " (" + ((NewVirtualFile)root).getId() + ")" + root.getClass() + " - " + System.identityHashCode(root) + + "; equalsToParent:" + (myFile.getParent() == null ? "" : myFile.getParent().getPath()).equals(root.getPath()) + + "; equalsToRoot:" + myFile.equals(root) + + "; equalsToRootPath:" + myFile.getPath().equals(root.getPath()) + + "; my contentRoot: " + info.getContentRoot() + + "; my sourceRoot: " + info.getSourceRoot() + + "; my classRoot: " + info.getLibraryClassRoot() + + "; path is substring: " + FileUtil.isAncestor(root.getPath(), myFile.getPath(), false) ; } -} \ No newline at end of file +}