From c525f2125f8232e1d218bc364c5c8a16f426a03a Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 23 Jun 2017 10:27:06 +0200 Subject: [PATCH] remove unused code and refactor to lambdas --- .../impl/TranslatingCompilerFilesMonitor.java | 145 ++++++------------ .../util/resources/misc/registry.properties | 3 - 2 files changed, 48 insertions(+), 100 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 54304b1214c8..31dbbdb13da0 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -19,7 +19,6 @@ import com.intellij.compiler.server.BuildManager; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -27,16 +26,12 @@ import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.util.Consumer; -import com.intellij.util.Function; -import com.intellij.util.concurrency.SequentialTaskExecutor; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.ide.PooledThreadExecutor; import java.io.File; import java.util.Collection; @@ -56,8 +51,6 @@ import java.util.Set; * 2. corresponding source file has been deleted */ public class TranslatingCompilerFilesMonitor { - private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.TranslatingCompilerFilesMonitor"); - private static final SequentialTaskExecutor ourFSEventQueue = new SequentialTaskExecutor("_build_notify_queue_", PooledThreadExecutor.INSTANCE); public TranslatingCompilerFilesMonitor(VirtualFileManager vfsManager, Application application) { vfsManager.addVirtualFileListener(new MyVfsListener(), application); @@ -121,108 +114,88 @@ public class TranslatingCompilerFilesMonitor { @Override public void propertyChanged(@NotNull final VirtualFilePropertyEvent event) { if (VirtualFile.PROP_NAME.equals(event.getPropertyName())) { - processEventFile("PropertyChanged", event.getFile(), (eventFile)->{ - if (isInContentOfOpenedProject(eventFile)) { - final VirtualFile parent = event.getParent(); - if (parent != null) { - final String oldName = (String)event.getOldValue(); - final String root = parent.getPath() + "/" + oldName; - final Set toMark = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY); - if (eventFile.isDirectory()) { - VfsUtilCore.visitChildrenRecursively(eventFile, new VirtualFileVisitor() { - private StringBuilder filePath = new StringBuilder(root); + final VirtualFile eventFile = event.getFile(); + if (isInContentOfOpenedProject(eventFile)) { + final VirtualFile parent = event.getParent(); + if (parent != null) { + final String oldName = (String)event.getOldValue(); + final String root = parent.getPath() + "/" + oldName; + final Set toMark = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY); + if (eventFile.isDirectory()) { + VfsUtilCore.visitChildrenRecursively(eventFile, new VirtualFileVisitor() { + private StringBuilder filePath = new StringBuilder(root); - @Override - public boolean visitFile(@NotNull VirtualFile child) { - if (child.isDirectory()) { - if (!Comparing.equal(child, eventFile)) { - filePath.append("/").append(child.getName()); - } - } - else { - String childPath = filePath.toString(); - if (!Comparing.equal(child, eventFile)) { - childPath += "/" + child.getName(); - } - toMark.add(new File(childPath)); - } - return true; - } - - @Override - public void afterChildrenVisited(@NotNull VirtualFile file) { - if (file.isDirectory() && !Comparing.equal(file, eventFile)) { - filePath.delete(filePath.length() - file.getName().length() - 1, filePath.length()); + @Override + public boolean visitFile(@NotNull VirtualFile child) { + if (child.isDirectory()) { + if (!Comparing.equal(child, eventFile)) { + filePath.append("/").append(child.getName()); } } - }); - } - else { - toMark.add(new File(root)); - } - notifyFilesDeleted(toMark); + else { + String childPath = filePath.toString(); + if (!Comparing.equal(child, eventFile)) { + childPath += "/" + child.getName(); + } + toMark.add(new File(childPath)); + } + return true; + } + + @Override + public void afterChildrenVisited(@NotNull VirtualFile file) { + if (file.isDirectory() && !Comparing.equal(file, eventFile)) { + filePath.delete(filePath.length() - file.getName().length() - 1, filePath.length()); + } + } + }); } - collectPathsAndNotify(eventFile, NOTIFY_CHANGED); + else { + toMark.add(new File(root)); + } + notifyFilesDeleted(toMark); } - }); + collectPathsAndNotify(eventFile, TranslatingCompilerFilesMonitor::notifyFilesChanged); + } } } @Override public void contentsChanged(@NotNull final VirtualFileEvent event) { - processEventFile("contentsChanged", event.getFile(), (eventFile)-> collectPathsAndNotify(eventFile, NOTIFY_CHANGED)); + collectPathsAndNotify(event.getFile(), TranslatingCompilerFilesMonitor::notifyFilesChanged); } @Override public void fileCreated(@NotNull final VirtualFileEvent event) { - processEventFile("fileCreated", event.getFile(), (eventFile)-> collectPathsAndNotify(eventFile, NOTIFY_CHANGED)); + collectPathsAndNotify(event.getFile(), TranslatingCompilerFilesMonitor::notifyFilesChanged); } @Override public void fileCopied(@NotNull final VirtualFileCopyEvent event) { - processEventFile("fileCopied", event.getFile(), (eventFile)-> collectPathsAndNotify(eventFile, NOTIFY_CHANGED)); + collectPathsAndNotify(event.getFile(), TranslatingCompilerFilesMonitor::notifyFilesChanged); } @Override public void fileMoved(@NotNull VirtualFileMoveEvent event) { - processEventFile("fileMoved", event.getFile(), (eventFile)-> collectPathsAndNotify(eventFile, NOTIFY_CHANGED)); + collectPathsAndNotify(event.getFile(), TranslatingCompilerFilesMonitor::notifyFilesChanged); } @Override public void beforeFileDeletion(@NotNull final VirtualFileEvent event) { - processEventFile("beforeFileDeletion", event.getFile(), (eventFile)-> collectPathsAndNotify(eventFile, NOTIFY_DELETED)); + collectPathsAndNotify(event.getFile(), TranslatingCompilerFilesMonitor::notifyFilesDeleted); } @Override public void beforeFileMovement(@NotNull final VirtualFileMoveEvent event) { - processEventFile("beforeFileMovement", event.getFile(), (eventFile)-> collectPathsAndNotify(eventFile, NOTIFY_DELETED)); + collectPathsAndNotify(event.getFile(), TranslatingCompilerFilesMonitor::notifyFilesChanged); } } - - private static final Function, Void> NOTIFY_CHANGED = files -> { - notifyFilesChanged(files); - return null; - }; - - private static final Function, Void> NOTIFY_DELETED = 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); + private static void collectPathsAndNotify(final VirtualFile file, final Consumer> notification) { if (!isIgnoredOrUnderIgnoredDirectory(file)) { - final boolean inContent = isInContentOfOpenedProject(file); - processRecursively(file, !inContent, new FileProcessor() { - @Override - public void execute(final VirtualFile file) { - pathsToMark.add(new File(file.getPath())); - } - }); - } - if (!pathsToMark.isEmpty()) { - notification.fun(pathsToMark); + final Set pathsToMark = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY); + processRecursively(file, !isInContentOfOpenedProject(file), f -> pathsToMark.add(new File(f.getPath()))); + notification.consume(pathsToMark); } } @@ -260,26 +233,4 @@ public class TranslatingCompilerFilesMonitor { } } - private static void processEventFile(String eventName, final VirtualFile file, final Consumer consumer) { - if (Registry.is("build.manager.async.fs.events", false)) { - if (LOG.isDebugEnabled()) { - LOG.debug("Processing " + eventName + "; file:" + file.getPath() + "; isValid=" + file.isValid()); - } - ourFSEventQueue.execute(()-> ApplicationManager.getApplication().runReadAction(()->{ - if (file.isValid()) { - consumer.consume(file); - } - else { - if (LOG.isDebugEnabled()) { - LOG.debug("File invalidated for event " + eventName + " before we were able to process it; " + file.getPath()); - } - BuildManager.getInstance().clearState(); - } - })); - } - else { - consumer.consume(file); - } - } - } diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 6dbdfb5bb223..f6b7fbd388a8 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -1103,9 +1103,6 @@ compiler.ref.index.restartRequired=true compiler.ref.chain.search=true compiler.ref.chain.search.description=Enables relevant method chain completion -build.manager.async.fs.events=false -build.manager.async.fs.events.description=Experimental: TranslatingCompilerFilesMonitor will process events from VFS asynchronously to minimize write-action duration - batch.inspections.use.psi.as.ref.table.key=false batch.inspections.use.psi.as.ref.table.key.description=Use PsiElement as key for RefManager's table typescript.service.node.arguments=