This commit is contained in:
Alexey Kudravtsev
2018-08-20 16:00:56 +03:00
parent fca8e9a209
commit ffda5895b6
7 changed files with 50 additions and 48 deletions
@@ -553,10 +553,15 @@ public abstract class CompilerReferenceServiceBase<Reader extends CompilerRefere
// should not be used in production code
@NotNull
public DirtyScopeHolder getDirtyScopeHolder() {
DirtyScopeHolder getDirtyScopeHolder() {
return myDirtyScopeHolder;
}
@TestOnly
public Set<Module> getAllDirtyModulesForTest() {
return myDirtyScopeHolder.getAllDirtyModulesForTest();
}
@Nullable
public CompilerReferenceFindUsagesTestInfo getTestFindUsages(@NotNull PsiElement element) {
if (!myReadDataLock.tryLock()) return null;
@@ -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<MessageBusConnection, Set<String>> compilationAffectedModulesSubscription
){
DirtyScopeHolder(@NotNull CompilerReferenceServiceBase<?> service,
FileDocumentManager fileDocumentManager,
PsiDocumentManager psiDocumentManager,
BiConsumer<? super MessageBusConnection, ? super Set<String>> 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<Module> getAllDirtyModules() {
Set<Module> getAllDirtyModules() {
final Set<Module> 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<Module> getAllDirtyModulesForTest() {
Set<Module> getAllDirtyModulesForTest() {
synchronized (myLock) {
return getAllDirtyModules();
}
@@ -82,6 +82,5 @@ class CompilerReferencesMultiModuleTest : CompilerReferencesTestBase() {
private fun dirtyModules() =
(CompilerReferenceService.getInstance(project) as CompilerReferenceServiceImpl)
.dirtyScopeHolder
.allDirtyModulesForTest
}
@@ -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() {
@@ -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;
@@ -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);
}
}
@@ -754,7 +754,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
@NotNull Set<? super String> files,
@NotNull Set<? super String> 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);