reduce direct usage count of IndexingDataKeys.PROJECT

GitOrigin-RevId: ab7e8d6627f085402ca8224e5dcbc184cddd31e8
This commit is contained in:
Dmitro Batko
2020-01-15 14:23:40 +03:00
committed by intellij-monorepo-bot
parent 759b304340
commit c549b4e5b9
9 changed files with 25 additions and 27 deletions

View File

@@ -26,8 +26,7 @@ class JavaBinaryPlusExpressionIndexTest : BasePlatformTestCase() {
}
}
""").virtualFile
val content = FileContentImpl.createByFile(file)
content.putUserData(IndexingDataKeys.PROJECT, project)
val content = FileContentImpl.createByFile(file, project)
val data = JavaBinaryPlusExpressionIndex().indexer.map(content).entries.first().value.offsets!!
assertEquals(5, data.size)

View File

@@ -87,8 +87,7 @@ class JavaNullMethodArgumentIndexTest : BasePlatformTestCase() {
}
}
""").virtualFile
val content = FileContentImpl.createByFile(file)
content.putUserData(IndexingDataKeys.PROJECT, project)
val content = FileContentImpl.createByFile(file, project)
val data = JavaNullMethodArgumentIndex().indexer.map(content).keys
assertSize(8, data)

View File

@@ -181,8 +181,7 @@ class JavaPropertyDetectionTest : LightJavaCodeInsightFixtureTestCase() {
private fun assertJavaSimplePropertyIndex(text: String, expected: TIntObjectHashMap<PropertyIndexValue>) {
val file = myFixture.configureByText(JavaFileType.INSTANCE, text)
val content = FileContentImpl.createByFile(file.virtualFile)
content.putUserData(IndexingDataKeys.PROJECT, project)
val content = FileContentImpl.createByFile(file.virtualFile, project)
val data = JavaSimplePropertyIndex().indexer.map(content).values.firstOrNull() ?: TIntObjectHashMap()
assertEquals(expected, data)
}

View File

@@ -19,45 +19,46 @@ import com.intellij.json.JsonTestCase;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.indexing.FileContentImpl;
import java.io.IOException;
import java.util.Map;
import static com.jetbrains.jsonSchema.impl.JsonCachedValues.*;
public class JsonSchemaFileValuesIndexTest extends JsonTestCase {
public void testEmpty() {
public void testEmpty() throws IOException {
final VirtualFile file = myFixture.configureByFile("indexing/empty.json").getVirtualFile();
Map<String, String> map = new JsonSchemaFileValuesIndex().getIndexer().map(FileContentImpl.createByFile(file));
assertAllCacheNulls(map);
}
public void testSimple() {
public void testSimple() throws IOException {
final VirtualFile file = myFixture.configureByFile("indexing/empty.json").getVirtualFile();
Map<String, String> map = new JsonSchemaFileValuesIndex().getIndexer().map(FileContentImpl.createByFile(file));
assertAllCacheNulls(map);
}
public void testValid() {
public void testValid() throws IOException {
final VirtualFile file = myFixture.configureByFile("indexing/valid.json").getVirtualFile();
Map<String, String> map = new JsonSchemaFileValuesIndex().getIndexer().map(FileContentImpl.createByFile(file));
assertEquals("the-id", map.get(ID_CACHE_KEY));
assertCacheNull(map.get(URL_CACHE_KEY));
}
public void testValid2() {
public void testValid2() throws IOException {
final VirtualFile file = myFixture.configureByFile("indexing/valid2.json5").getVirtualFile();
Map<String, String> map = new JsonSchemaFileValuesIndex().getIndexer().map(FileContentImpl.createByFile(file));
assertEquals("the-schema", map.get(URL_CACHE_KEY));
assertCacheNull(map.get(ID_CACHE_KEY));
}
public void testInvalid() {
public void testInvalid() throws IOException {
final VirtualFile file = myFixture.configureByFile("indexing/invalid.json").getVirtualFile();
Map<String, String> map = new JsonSchemaFileValuesIndex().getIndexer().map(FileContentImpl.createByFile(file));
assertAllCacheNulls(map);
}
public void testStopsOnAllFound() {
public void testStopsOnAllFound() throws IOException {
final VirtualFile file = myFixture.configureByFile("indexing/duplicates.json5").getVirtualFile();
Map<String, String> map = new JsonSchemaFileValuesIndex().getIndexer().map(FileContentImpl.createByFile(file));
assertEquals("the-schema", map.get(URL_CACHE_KEY));

View File

@@ -44,8 +44,7 @@ public class CoreStubTreeLoader extends StubTreeLoader {
}
try {
final FileContent fc = new FileContentImpl(vFile, vFile.contentsToByteArray());
fc.putUserData(IndexingDataKeys.PROJECT, project);
final FileContent fc = FileContentImpl.createByFile(vFile, project);
final Stub element = StubTreeBuilder.buildStubTree(fc);
if (element instanceof PsiFileStub) {
return new StubTree((PsiFileStub)element);

View File

@@ -137,14 +137,16 @@ public class FileContentImpl extends IndexedFileImpl implements PsiDependentFile
}
}
@TestOnly
public static FileContent createByFile(@NotNull VirtualFile file) {
try {
return new FileContentImpl(file, file.contentsToByteArray());
}
catch (IOException e) {
throw new RuntimeException(e);
public static FileContent createByFile(@NotNull VirtualFile file) throws IOException {
return createByFile(file, null);
}
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);
}
return content;
}
@NotNull

View File

@@ -174,8 +174,7 @@ public class StubViewerPsiBasedTree implements ViewerPsiBasedTree {
LightVirtualFile file = new LightVirtualFile("stub", rootElement.getLanguage(), textToParse);
final FileContentImpl fc;
try {
fc = new FileContentImpl(file, file.contentsToByteArray());
fc.putUserData(IndexingDataKeys.PROJECT, project);
fc = (FileContentImpl)FileContentImpl.createByFile(file, project);
fc.putUserData(IndexingDataKeys.PSI_FILE, psiFile);
stub = StubTreeBuilder.buildStubTree(fc);
}

View File

@@ -138,8 +138,7 @@ public class HashBasedIndexGenerator<K, V> {
}
myIndexedFilesNumber.incrementAndGet();
try {
FileContentImpl fc = new FileContentImpl(f, f.contentsToByteArray());
fc.putUserData(IndexingDataKeys.PROJECT, project);
FileContentImpl fc = (FileContentImpl)FileContentImpl.createByFile(f, project);
byte[] hash = IndexedHashesSupport.getOrInitIndexedHash(fc, false);
int hashId = Math.abs(hashEnumerator.enumerate(hash));
if (!myIndex.update(hashId, fc).compute()) {

View File

@@ -26,6 +26,7 @@ import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.indexing.FileContentImpl;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -35,7 +36,7 @@ import java.util.Map;
*/
public class XmlPropertiesIndexTest extends BasePlatformTestCase {
public void testIndex() {
public void testIndex() throws IOException {
PsiFile psiFile = myFixture.configureByFile("foo.xml");
final VirtualFile file = psiFile.getVirtualFile();
Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file));
@@ -58,7 +59,7 @@ public class XmlPropertiesIndexTest extends BasePlatformTestCase {
assertEquals("bar", assertOneElement(values));
}
public void testSystemId() {
public void testSystemId() throws IOException {
PsiFile psiFile = myFixture.configureByFile("wrong.xml");
final VirtualFile file = psiFile.getVirtualFile();
Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file));