From ffda5895b666b6b03eed36d4c4363a3f2ebd97a1 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 20 Aug 2018 15:51:18 +0300 Subject: [PATCH] cleanup --- .../CompilerReferenceServiceBase.java | 7 ++- .../backwardRefs/DirtyScopeHolder.java | 21 ++++----- .../CompilerReferencesMultiModuleTest.kt | 1 - .../java/compiler/CompilerReferencesTest.java | 4 +- .../openapi/vfs/VirtualFileEvent.java | 16 +++---- .../psi/impl/file/impl/PsiVFSListener.java | 47 ++++++++++--------- .../newvfs/persistent/PersistentFSImpl.java | 2 +- 7 files changed, 50 insertions(+), 48 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java index 5cebf99850ff..107ff821dd3e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java @@ -553,10 +553,15 @@ public abstract class CompilerReferenceServiceBase getAllDirtyModulesForTest() { + return myDirtyScopeHolder.getAllDirtyModulesForTest(); + } + @Nullable public CompilerReferenceFindUsagesTestInfo getTestFindUsages(@NotNull PsiElement element) { if (!myReadDataLock.tryLock()) return null; diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java index 90dd5b90153c..e3beb88fb1f6 100644 --- a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java @@ -41,7 +41,7 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; -public class DirtyScopeHolder extends UserDataHolderBase { +class DirtyScopeHolder extends UserDataHolderBase { private final CompilerReferenceServiceBase myService; private final FileDocumentManager myFileDocManager; private final PsiDocumentManager myPsiDocManager; @@ -56,11 +56,10 @@ public class DirtyScopeHolder extends UserDataHolderBase { private final FileTypeRegistry myFileTypeRegistry = FileTypeRegistry.getInstance(); - public DirtyScopeHolder(@NotNull CompilerReferenceServiceBase service, - FileDocumentManager fileDocumentManager, - PsiDocumentManager psiDocumentManager, - BiConsumer> compilationAffectedModulesSubscription - ){ + DirtyScopeHolder(@NotNull CompilerReferenceServiceBase service, + FileDocumentManager fileDocumentManager, + PsiDocumentManager psiDocumentManager, + BiConsumer> compilationAffectedModulesSubscription) { myService = service; myFileDocManager = fileDocumentManager; myPsiDocManager = psiDocumentManager; @@ -103,7 +102,7 @@ public class DirtyScopeHolder extends UserDataHolderBase { } } - public void upToDateChecked(boolean isUpToDate) { + void upToDateChecked(boolean isUpToDate) { final Module[] modules = ReadAction.compute(() -> { final Project project = myService.getProject(); if (project.isDisposed()) { @@ -148,7 +147,7 @@ public class DirtyScopeHolder extends UserDataHolderBase { myExcludedFilesScope = ExcludedFromCompileFilesUtil.getExcludedFilesScope(descriptions, myService.getFileTypes(), myService.getProject(), myService.getFileIndex()); } - public GlobalSearchScope getDirtyScope() { + GlobalSearchScope getDirtyScope() { final Project project = myService.getProject(); return ReadAction.compute(() -> { synchronized (myLock) { @@ -174,7 +173,7 @@ public class DirtyScopeHolder extends UserDataHolderBase { } @NotNull - public Set getAllDirtyModules() { + Set getAllDirtyModules() { final Set dirtyModules = new THashSet<>(myVFSChangedModules); for (Document document : myFileDocManager.getUnsavedDocuments()) { final VirtualFile file = myFileDocManager.getFile(document); @@ -197,7 +196,7 @@ public class DirtyScopeHolder extends UserDataHolderBase { return getDirtyScope().contains(file); } - public void installVFSListener() { + void installVFSListener() { VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileListener() { @Override public void fileCreated(@NotNull VirtualFileEvent event) { @@ -277,7 +276,7 @@ public class DirtyScopeHolder extends UserDataHolderBase { @TestOnly @NotNull - public Set getAllDirtyModulesForTest() { + Set getAllDirtyModulesForTest() { synchronized (myLock) { return getAllDirtyModules(); } diff --git a/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesMultiModuleTest.kt b/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesMultiModuleTest.kt index cdaffae07a7a..b05fc2e7c3c3 100644 --- a/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesMultiModuleTest.kt +++ b/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesMultiModuleTest.kt @@ -82,6 +82,5 @@ class CompilerReferencesMultiModuleTest : CompilerReferencesTestBase() { private fun dirtyModules() = (CompilerReferenceService.getInstance(project) as CompilerReferenceServiceImpl) - .dirtyScopeHolder .allDirtyModulesForTest } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesTest.java b/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesTest.java index e09c7aba693c..46d9a28f1e9c 100644 --- a/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesTest.java +++ b/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesTest.java @@ -5,10 +5,8 @@ import com.intellij.JavaTestUtil; import com.intellij.compiler.CompilerDirectHierarchyInfo; import com.intellij.compiler.CompilerReferenceService; import com.intellij.compiler.backwardRefs.CompilerReferenceServiceImpl; -import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; @@ -154,7 +152,7 @@ public class CompilerReferencesTest extends CompilerReferencesTestBase { final CompilerReferenceServiceImpl compilerReferenceService = (CompilerReferenceServiceImpl) CompilerReferenceService .getInstance(myFixture.getProject()); compilerReferenceService.getScopeWithoutCodeReferences(foo); - assertOneElement(compilerReferenceService.getDirtyScopeHolder().getAllDirtyModulesForTest()); + assertOneElement(compilerReferenceService.getAllDirtyModulesForTest()); } public void testReverseExtensionRename() { diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileEvent.java index da08a924cbea..2256c3c3aa05 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileEvent.java @@ -23,7 +23,7 @@ import java.util.EventObject; /** * Provides data for a virtual file system change event. * - * @see com.intellij.openapi.vfs.VirtualFileListener + * @see VirtualFileListener */ public class VirtualFileEvent extends EventObject { private final VirtualFile myFile; @@ -47,11 +47,11 @@ public class VirtualFileEvent extends EventObject { } private VirtualFileEvent(@Nullable Object requestor, - @NotNull VirtualFile file, - @NotNull String fileName, - @Nullable VirtualFile parent, - long oldModificationStamp, - long newModificationStamp) { + @NotNull VirtualFile file, + @NotNull String fileName, + @Nullable VirtualFile parent, + long oldModificationStamp, + long newModificationStamp) { super(file); myFile = file; myFileName = fileName; @@ -107,7 +107,7 @@ public class VirtualFileEvent extends EventObject { * Returns the modification stamp of the file before the event. * * @return the modification stamp of the file before the event. - * @see com.intellij.openapi.vfs.VirtualFile#getModificationStamp() + * @see VirtualFile#getModificationStamp() */ public long getOldModificationStamp() { return myOldModificationStamp; @@ -117,7 +117,7 @@ public class VirtualFileEvent extends EventObject { * Returns the modification stamp of the file after the event. * * @return the modification stamp of the file after the event. - * @see com.intellij.openapi.vfs.VirtualFile#getModificationStamp() + * @see VirtualFile#getModificationStamp() */ public long getNewModificationStamp() { return myNewModificationStamp; diff --git a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java index 26f2274a0fb9..74e0285b8018 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java @@ -51,6 +51,28 @@ public class PsiVFSListener implements VirtualFileListener, BulkFileListener { private static final AtomicBoolean ourGlobalListenerInstalled = new AtomicBoolean(false); + public PsiVFSListener(Project project) { + installGlobalListener(); + + myProject = project; + myFileTypeManager = FileTypeManager.getInstance(); + myProjectRootManager = ProjectRootManager.getInstance(project); + myManager = (PsiManagerImpl) PsiManager.getInstance(project); + myFileManager = (FileManagerImpl) myManager.getFileManager(); + + StartupManager.getInstance(project).registerPreStartupActivity(() -> { + MessageBusConnection connection = project.getMessageBus().connect(project); + connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener()); + connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() { + @Override + public void fileTypesChanged(@NotNull FileTypeEvent e) { + myFileManager.processFileTypesChanged(); + } + }); + connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new MyFileDocumentManagerAdapter()); + }); + } + /** * This code is implemented as static method (and not static constructor, as it was done before) to prevent installing listeners in Upsource */ @@ -87,28 +109,6 @@ public class PsiVFSListener implements VirtualFileListener, BulkFileListener { } } - public PsiVFSListener(Project project) { - installGlobalListener(); - - myProject = project; - myFileTypeManager = FileTypeManager.getInstance(); - myProjectRootManager = ProjectRootManager.getInstance(project); - myManager = (PsiManagerImpl) PsiManager.getInstance(project); - myFileManager = (FileManagerImpl) myManager.getFileManager(); - - StartupManager.getInstance(project).registerPreStartupActivity(() -> { - MessageBusConnection connection = project.getMessageBus().connect(project); - connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener()); - connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() { - @Override - public void fileTypesChanged(@NotNull FileTypeEvent e) { - myFileManager.processFileTypesChanged(); - } - }); - connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new MyFileDocumentManagerAdapter()); - }); - } - @Nullable private PsiDirectory getCachedDirectory(VirtualFile parent) { return parent == null ? null : myFileManager.getCachedDirectory(parent); @@ -615,7 +615,8 @@ public class PsiVFSListener implements VirtualFileListener, BulkFileListener { } } ); - } else { + } + else { handleVfsChangeWithoutPsi(file); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index ffe0c5252bd5..b27274cb9dd2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -754,7 +754,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis @NotNull Set files, @NotNull Set middleDirs) { int endIndex = groupByPath(events, startIndex, files, middleDirs); - // since all events in the group are mutually non-conflicting, we can re-arrange creations/deletions together + // since all events in the group events[startIndex..endIndex) are mutually non-conflicting, we can re-arrange creations/deletions together groupCreations(events, startIndex, endIndex, outValidatedEvents, outApplyEvents); groupDeletions(events, startIndex, endIndex, outValidatedEvents, outApplyEvents); groupOthers(events, startIndex, endIndex, outValidatedEvents, outApplyEvents);