Optimize KotlinPropertyAccessorsReferenceSearcher for case of no kt-files
Property names by accessors can be computed without resolving java descriptors #KT-11477 Fixed #KT-16890 Fixed
This commit is contained in:
+7
-5
@@ -59,11 +59,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
|
||||
|
||||
val originalGetterOrSetter = getterOrSetter.original
|
||||
|
||||
val names = listOfNotNull(
|
||||
propertyNameByGetMethodName(name),
|
||||
propertyNameBySetMethodName(name, withIsPrefix = true),
|
||||
propertyNameBySetMethodName(name, withIsPrefix = false)
|
||||
)
|
||||
val names = propertyNamesByAccessorName(name)
|
||||
|
||||
return names
|
||||
.flatMap {
|
||||
@@ -76,6 +72,12 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
|
||||
.firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod }
|
||||
}
|
||||
|
||||
fun propertyNamesByAccessorName(name: Name): List<Name> = listOfNotNull(
|
||||
propertyNameByGetMethodName(name),
|
||||
propertyNameBySetMethodName(name, withIsPrefix = true),
|
||||
propertyNameBySetMethodName(name, withIsPrefix = false)
|
||||
)
|
||||
|
||||
fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, syntheticScope: SyntheticScope) =
|
||||
findByGetterOrSetter(getterOrSetter,
|
||||
object : SyntheticScopes {
|
||||
|
||||
+13
-21
@@ -24,14 +24,10 @@ import com.intellij.psi.search.UsageSearchContext
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.compatibility.ExecutorProcessor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.idea.search.restrictToKotlinSources
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.synthetic.JavaSyntheticPropertiesScope
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.synthetic.canBePropertyAccessor
|
||||
|
||||
class KotlinPropertyAccessorsReferenceSearcher : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
|
||||
override fun processQuery(queryParameters: MethodReferencesSearch.SearchParameters, consumer: ExecutorProcessor<PsiReference>) {
|
||||
@@ -39,27 +35,23 @@ class KotlinPropertyAccessorsReferenceSearcher : QueryExecutorBase<PsiReference,
|
||||
val onlyKotlinFiles = queryParameters.effectiveSearchScope.restrictToKotlinSources()
|
||||
if (onlyKotlinFiles == GlobalSearchScope.EMPTY_SCOPE) return
|
||||
|
||||
val propertyName = propertyName(method) ?: return
|
||||
|
||||
queryParameters.optimizer!!.searchWord(
|
||||
propertyName,
|
||||
onlyKotlinFiles,
|
||||
UsageSearchContext.IN_CODE,
|
||||
true,
|
||||
method
|
||||
)
|
||||
for (propertyName in propertyNames(method)) {
|
||||
queryParameters.optimizer!!.searchWord(
|
||||
propertyName,
|
||||
onlyKotlinFiles,
|
||||
UsageSearchContext.IN_CODE,
|
||||
true,
|
||||
method
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun propertyName(method: PsiMethod): String? {
|
||||
private fun propertyNames(method: PsiMethod): List<String> {
|
||||
val unwrapped = method.namedUnwrappedElement
|
||||
if (unwrapped is KtProperty) {
|
||||
return unwrapped.getName()
|
||||
return listOfNotNull(unwrapped.getName())
|
||||
}
|
||||
|
||||
if (!canBePropertyAccessor(method.name)) return null
|
||||
val functionDescriptor = method.getJavaMethodDescriptor() ?: return null
|
||||
val syntheticExtensionsScope = JavaSyntheticPropertiesScope(LockBasedStorageManager(), LookupTracker.DO_NOTHING)
|
||||
val property = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(functionDescriptor, syntheticExtensionsScope) ?: return null
|
||||
return property.name.asString()
|
||||
return SyntheticJavaPropertyDescriptor.propertyNamesByAccessorName(Name.identifier(method.name)).map(Name::asString)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user