diff --git a/java/java-tests/testSrc/com/intellij/util/indexing/impl/perFileVersion/PersistentSubIndexerVersionEnumeratorTest.java b/java/java-tests/testSrc/com/intellij/util/indexing/impl/perFileVersion/PersistentSubIndexerVersionEnumeratorTest.java index ea40e777f93c..d83e8aef2f41 100644 --- a/java/java-tests/testSrc/com/intellij/util/indexing/impl/perFileVersion/PersistentSubIndexerVersionEnumeratorTest.java +++ b/java/java-tests/testSrc/com/intellij/util/indexing/impl/perFileVersion/PersistentSubIndexerVersionEnumeratorTest.java @@ -155,7 +155,7 @@ public class PersistentSubIndexerVersionEnumeratorTest extends LightJavaCodeInsi VirtualFile file = file(attribute); file.putUserData(ATTRIBUTE_KEY, attribute); try { - myMap.setIndexedState(((VirtualFileWithId) file).getId(), new IndexedFileImpl(file)); + myMap.setIndexedState(((VirtualFileWithId) file).getId(), new IndexedFileImpl(file, getProject())); } catch (IOException e) { LOG.error(e); @@ -169,7 +169,7 @@ public class PersistentSubIndexerVersionEnumeratorTest extends LightJavaCodeInsi VirtualFile file = file(attribute); file.putUserData(ATTRIBUTE_KEY, attribute); try { - return myMap.isIndexed(((VirtualFileWithId)file).getId(), new IndexedFileImpl(file)); + return myMap.isIndexed(((VirtualFileWithId)file).getId(), new IndexedFileImpl(file, getProject())); } catch (IOException e) { LOG.error(e); diff --git a/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java b/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java index ecb2385140c1..1d577088b2d1 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java +++ b/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java @@ -58,7 +58,7 @@ public class FileContentImpl extends IndexedFileImpl implements PsiDependentFile byte[] content, long stamp, boolean physicalContent) { - super(file, FileTypeRegistry.getInstance().getFileTypeByFile(file, content)); + super(file, FileTypeRegistry.getInstance().getFileTypeByFile(file, content), null); myContentAsText = contentAsText; myContent = content; myStamp = stamp; @@ -254,4 +254,9 @@ public class FileContentImpl extends IndexedFileImpl implements PsiDependentFile } return psi; } + + @Override + public Project getProject() { + return getUserData(IndexingDataKeys.PROJECT); + } } diff --git a/platform/core-impl/src/com/intellij/util/indexing/IndexedFileImpl.java b/platform/core-impl/src/com/intellij/util/indexing/IndexedFileImpl.java index 9cbb66af4ee8..502800761956 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/IndexedFileImpl.java +++ b/platform/core-impl/src/com/intellij/util/indexing/IndexedFileImpl.java @@ -11,15 +11,17 @@ public class IndexedFileImpl extends UserDataHolderBase implements IndexedFile { protected final VirtualFile myFile; protected final String myFileName; protected final FileType myFileType; + private final Project myProject; - public IndexedFileImpl(@NotNull VirtualFile file) { - this(file, file.getFileType()); + public IndexedFileImpl(@NotNull VirtualFile file, Project project) { + this(file, file.getFileType(), project); } - public IndexedFileImpl(@NotNull VirtualFile file, @NotNull FileType type) { + public IndexedFileImpl(@NotNull VirtualFile file, @NotNull FileType type, Project project) { myFile = file; myFileName = file.getName(); myFileType = type; + myProject = project; } @NotNull @@ -42,6 +44,6 @@ public class IndexedFileImpl extends UserDataHolderBase implements IndexedFile { @Override public Project getProject() { - return getUserData(IndexingDataKeys.PROJECT); + return myProject; } } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java index 53c54be54ecc..1c8912f9230d 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java @@ -10,6 +10,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VirtualFile; @@ -50,7 +51,8 @@ public class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension canHaveStub(file); public static boolean canHaveStub(@NotNull VirtualFile file) { - FileType fileType = SubstitutedFileType.substituteFileType(file, file.getFileType(), ProjectUtil.guessProjectForFile(file)); + Project project = ProjectUtil.guessProjectForFile(file); + FileType fileType = SubstitutedFileType.substituteFileType(file, file.getFileType(), project); if (fileType instanceof LanguageFileType) { final Language l = ((LanguageFileType)fileType).getLanguage(); final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l); @@ -66,7 +68,7 @@ public class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension myFiles = new ArrayList<>(); + private final Project myProject; private final boolean myDoTraceForFilesToBeIndexed = LOG.isTraceEnabled(); + UnindexedFilesFinder(@NotNull Project project) { + myProject = project; + } + @NotNull @Override public List getFiles() { @@ -2249,7 +2254,7 @@ public final class FileBasedIndexImpl extends FileBasedIndex { return true; } getFileTypeManager().freezeFileTypeTemporarilyIn(file, () -> { - IndexedFile fileContent = new IndexedFileImpl(file); + IndexedFile fileContent = new IndexedFileImpl(file, myProject); boolean isUptoDate = true; boolean isDirectory = file.isDirectory(); @@ -2326,8 +2331,8 @@ public final class FileBasedIndexImpl extends FileBasedIndex { } @NotNull - CollectingContentIterator createContentIterator() { - return new UnindexedFilesFinder(); + CollectingContentIterator createContentIterator(@NotNull Project project) { + return new UnindexedFilesFinder(project); } @Override diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java index 2ff0674b3e4a..6ae03d47193b 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java @@ -58,7 +58,7 @@ public final class UnindexedFilesUpdater extends DumbModeTask { myIndex.clearIndicesIfNecessary(); - CollectingContentIterator finder = myIndex.createContentIterator(); + CollectingContentIterator finder = myIndex.createContentIterator(myProject); snapshot = PerformanceWatcher.takeSnapshot(); myIndex.iterateIndexableFilesConcurrently(finder, myProject, indicator);