mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
index: set project to FileContent instance on its creation
GitOrigin-RevId: d5b68bf0115a7e8080da752329104e5e977625f2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b5187cc9aa
commit
c006f4c717
@@ -3,6 +3,7 @@ package com.intellij.psi.stubs;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Attachment;
|
||||
import com.intellij.openapi.diagnostic.ExceptionWithAttachments;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -90,8 +91,11 @@ public final class StubTextInconsistencyException extends RuntimeException imple
|
||||
|
||||
@NotNull
|
||||
private static List<PsiFileStub> restoreStubsFromText(FileViewProvider viewProvider) {
|
||||
FileContentImpl fc = (FileContentImpl)FileContentImpl.createByText(viewProvider.getVirtualFile(), viewProvider.getContents());
|
||||
fc.setProject(viewProvider.getManager().getProject());
|
||||
Project project = viewProvider.getManager().getProject();
|
||||
FileContentImpl fc = (FileContentImpl)FileContentImpl.createByText(viewProvider.getVirtualFile(),
|
||||
viewProvider.getContents(),
|
||||
project);
|
||||
fc.setProject(project);
|
||||
PsiFileStubImpl copyTree = (PsiFileStubImpl) StubTreeBuilder.buildStubTree(fc);
|
||||
return copyTree == null ? Collections.emptyList() : Arrays.asList(copyTree.getStubRoots());
|
||||
}
|
||||
|
||||
@@ -104,12 +104,22 @@ public final class FileContentImpl extends IndexedFileImpl implements PsiDepende
|
||||
return new FileContentImpl(file, fileType, null, () -> content, true);
|
||||
}
|
||||
|
||||
public static @NotNull FileContent createByContent(@NotNull VirtualFile file,
|
||||
public static @NotNull FileContentImpl createByContent(@NotNull VirtualFile file,
|
||||
@NotNull NotNullComputable<byte[]> contentComputable) {
|
||||
FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFile(file);
|
||||
return new FileContentImpl(file, fileType, null, contentComputable, true);
|
||||
}
|
||||
|
||||
public static @NotNull FileContent createByContent(@NotNull VirtualFile file,
|
||||
@NotNull NotNullComputable<byte[]> contentComputable,
|
||||
@Nullable Project project) {
|
||||
FileContentImpl fileContent = createByContent(file, contentComputable);
|
||||
if (project != null) {
|
||||
fileContent.setProject(project);
|
||||
}
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
public static @NotNull FileContent createByFile(@NotNull VirtualFile file) throws IOException {
|
||||
return createByFile(file, null);
|
||||
}
|
||||
@@ -122,15 +132,19 @@ public final class FileContentImpl extends IndexedFileImpl implements PsiDepende
|
||||
return content;
|
||||
}
|
||||
|
||||
public static @NotNull FileContent createByText(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText) {
|
||||
public static @NotNull FileContent createByText(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText, @Nullable Project project) {
|
||||
FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFile(file);
|
||||
return new FileContentImpl(file,
|
||||
fileType,
|
||||
contentAsText,
|
||||
() -> {
|
||||
throw new IllegalStateException("Content must be converted from 'contentAsText'");
|
||||
},
|
||||
false);
|
||||
FileContentImpl content = new FileContentImpl(file,
|
||||
fileType,
|
||||
contentAsText,
|
||||
() -> {
|
||||
throw new IllegalStateException("Content must be converted from 'contentAsText'");
|
||||
},
|
||||
false);
|
||||
if (project != null) {
|
||||
content.setProject(project);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1035,11 +1035,11 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
newFc = previousContentAndStamp.getFirst();
|
||||
}
|
||||
else {
|
||||
newFc = (FileContentImpl)FileContentImpl.createByText(vFile, contentText);
|
||||
newFc = (FileContentImpl)FileContentImpl.createByText(vFile, contentText, project);
|
||||
document.putUserData(ourFileContentKey, new WeakReference<>(Pair.create(newFc, currentDocStamp)));
|
||||
}
|
||||
|
||||
initFileContent(newFc, project, dominantContentFile);
|
||||
initFileContent(newFc, dominantContentFile);
|
||||
newFc.ensureThreadSafeLighterAST();
|
||||
|
||||
if (content instanceof AuthenticContent) {
|
||||
@@ -1083,9 +1083,9 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
if (psiFile != null) {
|
||||
Map<ID, Map> indexValues = CachedValuesManager.getCachedValue(psiFile, () -> {
|
||||
try {
|
||||
FileContentImpl fc = psiFile instanceof PsiBinaryFile ? (FileContentImpl)FileContentImpl.createByFile(virtualFile)
|
||||
: (FileContentImpl)FileContentImpl.createByText(virtualFile, psiFile.getViewProvider().getContents());
|
||||
initFileContent(fc, project, psiFile);
|
||||
FileContentImpl fc = psiFile instanceof PsiBinaryFile ? (FileContentImpl)FileContentImpl.createByFile(virtualFile, project)
|
||||
: (FileContentImpl)FileContentImpl.createByText(virtualFile, psiFile.getViewProvider().getContents(), project);
|
||||
initFileContent(fc, psiFile);
|
||||
Map<ID, Map> result = FactoryMap.create(key -> getIndex(key).getExtension().getIndexer().map(fc));
|
||||
return CachedValueProvider.Result.createSingleDependency(result, psiFile);
|
||||
}
|
||||
@@ -1342,12 +1342,12 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
if (fc == null) {
|
||||
fc = (FileContentImpl)FileContentImpl.createByContent(file, () -> getBytesOrNull(content));
|
||||
fc = (FileContentImpl)FileContentImpl.createByContent(file, () -> getBytesOrNull(content), guessedProject);
|
||||
fc.setSubstituteFileType(indexedFile.getFileType());
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
psiFile = content.getUserData(IndexingDataKeys.PSI_FILE);
|
||||
initFileContent(fc, guessedProject, psiFile);
|
||||
initFileContent(fc, psiFile);
|
||||
|
||||
fileTypeRef.set(fc.getFileType());
|
||||
|
||||
@@ -1442,13 +1442,11 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
fc.putUserData(IndexingDataKeys.PSI_FILE, null);
|
||||
}
|
||||
|
||||
private static void initFileContent(@NotNull FileContentImpl fc, Project project, PsiFile psiFile) {
|
||||
private static void initFileContent(@NotNull FileContentImpl fc, PsiFile psiFile) {
|
||||
if (psiFile != null) {
|
||||
psiFile.putUserData(PsiFileImpl.BUILDING_STUB, true);
|
||||
fc.putUserData(IndexingDataKeys.PSI_FILE, psiFile);
|
||||
}
|
||||
|
||||
fc.setProject(project);
|
||||
}
|
||||
|
||||
@Nullable("null in case index update is not necessary or the update has failed")
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.testFramework.HeavyPlatformTestCase
|
||||
import com.intellij.util.ArrayUtil
|
||||
import com.intellij.util.ThrowableRunnable
|
||||
import com.intellij.util.io.write
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import java.nio.charset.StandardCharsets
|
||||
@@ -53,7 +52,7 @@ class FileContentImplTest : HeavyPlatformTestCase() {
|
||||
val text = "a\r\nb"
|
||||
val textBytes = text.toByteArray()
|
||||
val virtualFile = createInputFile(textBytes)
|
||||
val content = FileContentImpl.createByText(virtualFile, text)
|
||||
val content = FileContentImpl.createByText(virtualFile, text, project)
|
||||
assertEquals(text, content.contentAsText)
|
||||
assertArrayEquals(textBytes, content.content)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user