mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use a dedicated field instead of IndexingDataKeys.PROJECT
GitOrigin-RevId: 5b866d456ef26bbd17dc25ff4732078e54e7308a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c549b4e5b9
commit
c551615594
@@ -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<PsiFileStub> 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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ import com.intellij.psi.PsiFile;
|
||||
*/
|
||||
public class IndexingDataKeys {
|
||||
public static final Key<VirtualFile> VIRTUAL_FILE = new Key<>("Context virtual file");
|
||||
/**
|
||||
* @deprecated use {@link IndexedFileImpl#setProject(Project)} or {@link IndexedFileImpl#getProject()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Key<Project> PROJECT = new Key<>("Context project");
|
||||
public static final Key<PsiFile> PSI_FILE = new Key<>("PSI for stubs");
|
||||
public static final Key<CharSequence> FILE_TEXT_CONTENT_KEY = Key.create("file text content cached by stub indexer");
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -56,8 +56,7 @@ abstract class IndexGenerator<Value>(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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user