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 """).virtualFile
val content = FileContentImpl.createByFile(file) val content = FileContentImpl.createByFile(file, project)
content.putUserData(IndexingDataKeys.PROJECT, project)
val data = JavaBinaryPlusExpressionIndex().indexer.map(content).entries.first().value.offsets!! val data = JavaBinaryPlusExpressionIndex().indexer.map(content).entries.first().value.offsets!!
assertEquals(5, data.size) assertEquals(5, data.size)

View File

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

View File

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

View File

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

View File

@@ -44,8 +44,7 @@ public class CoreStubTreeLoader extends StubTreeLoader {
} }
try { try {
final FileContent fc = new FileContentImpl(vFile, vFile.contentsToByteArray()); final FileContent fc = FileContentImpl.createByFile(vFile, project);
fc.putUserData(IndexingDataKeys.PROJECT, project);
final Stub element = StubTreeBuilder.buildStubTree(fc); final Stub element = StubTreeBuilder.buildStubTree(fc);
if (element instanceof PsiFileStub) { if (element instanceof PsiFileStub) {
return new StubTree((PsiFileStub)element); 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) throws IOException {
public static FileContent createByFile(@NotNull VirtualFile file) { return createByFile(file, null);
try { }
return new FileContentImpl(file, file.contentsToByteArray());
} public static FileContent createByFile(@NotNull VirtualFile file, @Nullable Project project) throws IOException {
catch (IOException e) { FileContentImpl content = new FileContentImpl(file, file.contentsToByteArray());
throw new RuntimeException(e); if (project != null) {
content.putUserData(IndexingDataKeys.PROJECT, project);
} }
return content;
} }
@NotNull @NotNull

View File

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

View File

@@ -138,8 +138,7 @@ public class HashBasedIndexGenerator<K, V> {
} }
myIndexedFilesNumber.incrementAndGet(); myIndexedFilesNumber.incrementAndGet();
try { try {
FileContentImpl fc = new FileContentImpl(f, f.contentsToByteArray()); FileContentImpl fc = (FileContentImpl)FileContentImpl.createByFile(f, project);
fc.putUserData(IndexingDataKeys.PROJECT, project);
byte[] hash = IndexedHashesSupport.getOrInitIndexedHash(fc, false); byte[] hash = IndexedHashesSupport.getOrInitIndexedHash(fc, false);
int hashId = Math.abs(hashEnumerator.enumerate(hash)); int hashId = Math.abs(hashEnumerator.enumerate(hash));
if (!myIndex.update(hashId, fc).compute()) { 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 com.intellij.util.indexing.FileContentImpl;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -35,7 +36,7 @@ import java.util.Map;
*/ */
public class XmlPropertiesIndexTest extends BasePlatformTestCase { public class XmlPropertiesIndexTest extends BasePlatformTestCase {
public void testIndex() { public void testIndex() throws IOException {
PsiFile psiFile = myFixture.configureByFile("foo.xml"); PsiFile psiFile = myFixture.configureByFile("foo.xml");
final VirtualFile file = psiFile.getVirtualFile(); final VirtualFile file = psiFile.getVirtualFile();
Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file)); Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file));
@@ -58,7 +59,7 @@ public class XmlPropertiesIndexTest extends BasePlatformTestCase {
assertEquals("bar", assertOneElement(values)); assertEquals("bar", assertOneElement(values));
} }
public void testSystemId() { public void testSystemId() throws IOException {
PsiFile psiFile = myFixture.configureByFile("wrong.xml"); PsiFile psiFile = myFixture.configureByFile("wrong.xml");
final VirtualFile file = psiFile.getVirtualFile(); final VirtualFile file = psiFile.getVirtualFile();
Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file)); Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file));