From 478fc87cd4c91894d1f8c796e84da80100a89144 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 2 Jun 2014 02:03:30 +0400 Subject: [PATCH] test fixes and code unification --- .../impl/TranslatingCompilerFilesMonitor.java | 104 +++++++++--------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index 6fb96027dddc..b631df7fef90 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -28,6 +28,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.util.Function; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -102,7 +103,11 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { if (dbOnly) { return file.isDirectory()? ((NewVirtualFile)file).iterInDbChildren() : null; } - return null; + if (file.equals(fromFile) || !file.isDirectory()) { + return null; // skipping additional checks for the initial file and non-directory files + } + // optimization: for all files that are not under content of currently opened projects iterate over DB children + return isInContentOfOpenedProject(file)? null : ((NewVirtualFile)file).iterInDbChildren(); } }); } @@ -164,83 +169,80 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } notifyFilesDeleted(toMark); } - markDirtyIfSource(eventFile, false); + collectPathsAndNotify(eventFile, NOTIFY_CHANGED); } } } public void contentsChanged(@NotNull final VirtualFileEvent event) { - markDirtyIfSource(event.getFile(), false); + collectPathsAndNotify(event.getFile(), NOTIFY_CHANGED); } public void fileCreated(@NotNull final VirtualFileEvent event) { - processNewFile(event.getFile()); + collectPathsAndNotify(event.getFile(), NOTIFY_CHANGED); } public void fileCopied(@NotNull final VirtualFileCopyEvent event) { - processNewFile(event.getFile()); + collectPathsAndNotify(event.getFile(), NOTIFY_CHANGED); } public void fileMoved(@NotNull VirtualFileMoveEvent event) { - processNewFile(event.getFile()); + collectPathsAndNotify(event.getFile(), NOTIFY_CHANGED); } public void beforeFileDeletion(@NotNull final VirtualFileEvent event) { - final VirtualFile eventFile = event.getFile(); - if (isInContentOfOpenedProject(eventFile)) { - if ((LOG.isDebugEnabled() && eventFile.isDirectory()) || ourDebugMode) { - final String message = "Processing file deletion: " + eventFile.getPresentableUrl(); - LOG.debug(message); - if (ourDebugMode) { - System.out.println(message); - } - } - - final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); - - processRecursively(eventFile, true, new FileProcessor() { - public void execute(final VirtualFile file) { - pathsToMark.add(new File(file.getPath())); - } - }); - - notifyFilesDeleted(pathsToMark); - } + collectPathsAndNotify(event.getFile(), NOTIFY_DELETED); } public void beforeFileMovement(@NotNull final VirtualFileMoveEvent event) { - markDirtyIfSource(event.getFile(), true); - } - - private void markDirtyIfSource(final VirtualFile file, final boolean fromMove) { - if (isInContentOfOpenedProject(file)) { - final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); - processRecursively(file, false, new FileProcessor() { - public void execute(final VirtualFile file) { - pathsToMark.add(new File(file.getPath())); - } - }); - if (fromMove) { - notifyFilesDeleted(pathsToMark); - } - else { - notifyFilesChanged(pathsToMark); - } - } + collectPathsAndNotify(event.getFile(), NOTIFY_DELETED); } } - private static void processNewFile(final VirtualFile file) { - if (isInContentOfOpenedProject(file)) { - final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); - processRecursively(file, false, new FileProcessor() { - @Override - public void execute(VirtualFile file) { + + private static final Function, Void> NOTIFY_CHANGED = new Function, Void>() { + public Void fun(Collection files) { + notifyFilesChanged(files); + return null; + } + }; + + private static final Function, Void> NOTIFY_DELETED = new Function, Void>() { + public Void fun(Collection files) { + notifyFilesDeleted(files); + return null; + } + }; + + private static void collectPathsAndNotify(final VirtualFile file, final Function, Void> notification) { + final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); + final boolean inContent = isInContentOfOpenedProject(file); + if (inContent || !isIgnoredOrUnderIgnoredDirectory(file)) { + processRecursively(file, !inContent, new FileProcessor() { + public void execute(final VirtualFile file) { pathsToMark.add(new File(file.getPath())); } }); - notifyFilesChanged(pathsToMark); } + if (!pathsToMark.isEmpty()) { + notification.fun(pathsToMark); + } + } + + private static boolean isIgnoredOrUnderIgnoredDirectory(final VirtualFile file) { + final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); + if (fileTypeManager.isFileIgnored(file)) { + return true; + } + + VirtualFile current = file.getParent(); + while (current != null) { + if (fileTypeManager.isFileIgnored(current)) { + return true; + } + current = current.getParent(); + } + return false; } private static void notifyFilesChanged(Collection paths) {