Files
openide/java/java-tests/testSrc/com/intellij/util/indexing/StubIndexTest.kt
Izmar Verhage 06190372c4 Deprecate AbstractStubIndex::get and migrate usages
In this commit we implement a logical implication of the fact
that StubIndex::get is deprecated, combined with the fact that
AbstractStubIndex::get is not deprecated but calls
StubIndex::get with the exact same arguments it received. The
absence of deprecation of AbstractStubIndex::get obfuscates
the fact that we want to phase out StubIndex::get calls.

Apart from deprecating said method, we add some convenience
methods in AbstractStubIndex inheritors that ensure a few things:
- The not-deprecated and preferred StubIndex::getElements is
  called with appropriate arguments, including a properly
  specialised requiredClass argument.
- Shorter syntax and DRY: only 3 arguments are required to pass
  into the convenience method, whereas getElements requires 2
  more. These 2 arguments are fields of the AbstractStubIndex
  inheritor, so it makes little sense to get them from there
  and pass them into StubIndex::getElements everywhere.

Wherever we can, these convenience methods are now used.

If you have access to JetBrains internal resources, also see:
https://jetbrains.team/p/ij/reviews/112930/timeline
https://jetbrains.slack.com/archives/CMDBCUBGE/p1691509451975689

GitOrigin-RevId: c51ef4de44aa85841799640b1ece9d291208dc69
2023-08-11 16:14:17 +00:00

36 lines
2.0 KiB
Kotlin

// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.indexing
import com.intellij.psi.impl.java.stubs.index.JavaShortClassNameIndex
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.testFramework.SkipSlowTestLocally
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
@SkipSlowTestLocally
class StubIndexTest : JavaCodeInsightFixtureTestCase() {
fun `test stub index query for single file with matching key`() {
val clazz = myFixture.addClass("class Foo {}")
val file = clazz.containingFile
val indexQueryResultOptimized = JavaShortClassNameIndex.getInstance().getClasses("Foo", myFixture.project,
GlobalSearchScope.fileScope(file))
assertEquals(clazz, assertOneElement(indexQueryResultOptimized))
val indexQueryResultNotOptimized = JavaShortClassNameIndex.getInstance().getClasses("Foo", myFixture.project,
GlobalSearchScope.allScope(myFixture.project))
assertEquals(clazz, assertOneElement(indexQueryResultNotOptimized))
}
fun `test stub index query for single file without matching key`() {
val file = myFixture.addClass("class Foo {}").containingFile
val indexQueryResultOptimized = JavaShortClassNameIndex.getInstance().getClasses("Bar", myFixture.project,
GlobalSearchScope.fileScope(file))
assertEmpty(indexQueryResultOptimized)
val indexQueryResultNotOptimized = JavaShortClassNameIndex.getInstance().getClasses("Bar", myFixture.project,
GlobalSearchScope.allScope(myFixture.project))
assertEmpty(indexQueryResultNotOptimized)
}
}