diff --git a/platform/core-impl/src/com/intellij/psi/stubs/StubTextInconsistencyException.java b/platform/core-impl/src/com/intellij/psi/stubs/StubTextInconsistencyException.java index 28efcf9ead07..1fa513882204 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/StubTextInconsistencyException.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/StubTextInconsistencyException.java @@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.ExceptionWithAttachments; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; import com.intellij.psi.impl.DebugUtil; import com.intellij.psi.impl.FreeThreadedFileViewProvider; import com.intellij.psi.impl.source.PsiFileImpl; @@ -106,7 +107,7 @@ public class StubTextInconsistencyException extends RuntimeException implements @NotNull private static List restoreStubsFromText(FileViewProvider viewProvider) { FileContentImpl fc = new FileContentImpl(viewProvider.getVirtualFile(), viewProvider.getContents(), 0); - fc.putUserData(IndexingDataKeys.PROJECT, viewProvider.getManager().getProject()); + fc.setProject(viewProvider.getManager().getProject()); PsiFileStubImpl copyTree = (PsiFileStubImpl) StubTreeBuilder.buildStubTree(fc); return copyTree == null ? Collections.emptyList() : Arrays.asList(copyTree.getStubRoots()); } 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 56d3fa7cb299..385bb6e88f0b 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java +++ b/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java @@ -21,7 +21,6 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.TestOnly; import java.io.IOException; import java.nio.charset.Charset; @@ -144,7 +143,7 @@ public class FileContentImpl extends IndexedFileImpl implements PsiDependentFile public static FileContent createByFile(@NotNull VirtualFile file, @Nullable Project project) throws IOException { FileContentImpl content = new FileContentImpl(file, file.contentsToByteArray()); if (project != null) { - content.putUserData(IndexingDataKeys.PROJECT, project); + content.setProject(project); } return content; } @@ -253,6 +252,7 @@ public class FileContentImpl extends IndexedFileImpl implements PsiDependentFile @Override public Project getProject() { - return getUserData(IndexingDataKeys.PROJECT); + Project project = super.getProject(); + return project != null ? project : 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 502800761956..f135794d5a32 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/IndexedFileImpl.java +++ b/platform/core-impl/src/com/intellij/util/indexing/IndexedFileImpl.java @@ -5,13 +5,15 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +@ApiStatus.Internal public class IndexedFileImpl extends UserDataHolderBase implements IndexedFile { protected final VirtualFile myFile; protected final String myFileName; protected final FileType myFileType; - private final Project myProject; + private volatile Project myProject; public IndexedFileImpl(@NotNull VirtualFile file, Project project) { this(file, file.getFileType(), project); @@ -46,4 +48,8 @@ public class IndexedFileImpl extends UserDataHolderBase implements IndexedFile { public Project getProject() { return myProject; } + + public void setProject(@NotNull Project project) { + myProject = project; + } } diff --git a/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java b/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java index de178df4e405..76200a2a5b20 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java +++ b/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java @@ -26,6 +26,10 @@ import com.intellij.psi.PsiFile; */ public class IndexingDataKeys { public static final Key VIRTUAL_FILE = new Key<>("Context virtual file"); + /** + * @deprecated use {@link IndexedFileImpl#setProject(Project)} or {@link IndexedFileImpl#getProject()} instead + */ + @Deprecated public static final Key PROJECT = new Key<>("Context project"); public static final Key PSI_FILE = new Key<>("PSI for stubs"); public static final Key FILE_TEXT_CONTENT_KEY = Key.create("file text content cached by stub indexer"); diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java index 1a429ac4c573..0f20bd922576 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java @@ -45,8 +45,11 @@ final class StubTreeLoaderImpl extends StubTreeLoader { byte[] content = vFile.contentsToByteArray(); vFile.setPreloadedContentHint(content); try { - final FileContent fc = new FileContentImpl(vFile, content); - fc.putUserData(IndexingDataKeys.PROJECT, project); + FileContentImpl content1 = new FileContentImpl(vFile, content); + if (project != null) { + content1.setProject(project); + } + final FileContent fc = content1; if (psiFile != null && !vFile.getFileType().isBinary()) { fc.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, psiFile.getViewProvider().getContents()); // but don't reuse psiFile itself to avoid loading its contents. If we load AST, the stub will be thrown out anyway. @@ -253,7 +256,7 @@ final class StubTreeLoaderImpl extends StubTreeLoader { try { PrebuiltStubsProvider provider = PrebuiltStubsKt.getPrebuiltStubsProvider().forFileType(virtualFile.getFileType()); if (provider != null) { - canBePrebuilt = provider.findStub(new FileContentImpl(virtualFile, virtualFile.contentsToByteArray())) != null; + canBePrebuilt = provider.findStub(FileContentImpl.createByFile(virtualFile)) != null; } } catch (Exception e) { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index 27b833f6e375..c7213522ef2f 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -1259,7 +1259,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { fc.putUserData(IndexingDataKeys.PSI_FILE, psiFile); } - fc.putUserData(IndexingDataKeys.PROJECT, project); + fc.setProject(project); } boolean updateSingleIndex(@NotNull ID indexId, @Nullable VirtualFile file, int inputId, @Nullable FileContent currentFC) { diff --git a/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt b/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt index 032a47b07458..e0ce9089f07b 100644 --- a/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt +++ b/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt @@ -56,8 +56,7 @@ abstract class IndexGenerator(private val indexStorageFilePath: String) { stats: Stats): Boolean { try { if (fileFilter.accept(file)) { - val fileContent = FileContentImpl( - file, file.contentsToByteArray()) + val fileContent = FileContentImpl.createByFile(file) as FileContentImpl val hashCode = hashing.hashString(fileContent)