Before searching for descriptor of method, check if it can be property

This commit is contained in:
Dmitry Jemerov
2017-08-14 15:35:49 +02:00
parent 1fe3f84071
commit 34681b1459
2 changed files with 7 additions and 1 deletions
@@ -40,6 +40,10 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import java.util.* import java.util.*
import kotlin.properties.Delegates import kotlin.properties.Delegates
fun canBePropertyAccessor(identifier: String): Boolean {
return identifier.startsWith("get") || identifier.startsWith("is") || identifier.startsWith("set")
}
interface SyntheticJavaPropertyDescriptor : PropertyDescriptor { interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
val getMethod: FunctionDescriptor val getMethod: FunctionDescriptor
val setMethod: FunctionDescriptor? val setMethod: FunctionDescriptor?
@@ -49,7 +53,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
val name = getterOrSetter.name val name = getterOrSetter.name
if (name.isSpecial) return null if (name.isSpecial) return null
val identifier = name.identifier val identifier = name.identifier
if (!identifier.startsWith("get") && !identifier.startsWith("is") && !identifier.startsWith("set")) return null // optimization if (!canBePropertyAccessor(identifier)) return null // optimization
val classDescriptorOwner = getterOrSetter.containingDeclaration as? ClassDescriptor ?: return null val classDescriptorOwner = getterOrSetter.containingDeclaration as? ClassDescriptor ?: return null
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.synthetic.JavaSyntheticPropertiesScope import org.jetbrains.kotlin.synthetic.JavaSyntheticPropertiesScope
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.synthetic.canBePropertyAccessor
class KotlinPropertyAccessorsReferenceSearcher : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) { class KotlinPropertyAccessorsReferenceSearcher : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
override fun processQuery(queryParameters: MethodReferencesSearch.SearchParameters, consumer: Processor<PsiReference>) { override fun processQuery(queryParameters: MethodReferencesSearch.SearchParameters, consumer: Processor<PsiReference>) {
@@ -54,6 +55,7 @@ class KotlinPropertyAccessorsReferenceSearcher : QueryExecutorBase<PsiReference,
return unwrapped.getName() return unwrapped.getName()
} }
if (!canBePropertyAccessor(method.name)) return null
val functionDescriptor = method.getJavaMethodDescriptor() ?: return null val functionDescriptor = method.getJavaMethodDescriptor() ?: return null
val syntheticExtensionsScope = JavaSyntheticPropertiesScope(LockBasedStorageManager(), LookupTracker.DO_NOTHING) val syntheticExtensionsScope = JavaSyntheticPropertiesScope(LockBasedStorageManager(), LookupTracker.DO_NOTHING)
val property = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(functionDescriptor, syntheticExtensionsScope) ?: return null val property = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(functionDescriptor, syntheticExtensionsScope) ?: return null