Never find overriding parameter usages via old way
This commit is contained in:
@@ -58,17 +58,15 @@ val JetParameter.propertyDescriptor: PropertyDescriptor?
|
|||||||
get() = this.analyze().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this)
|
get() = this.analyze().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this)
|
||||||
|
|
||||||
fun PsiReference.checkUsageVsOriginalDescriptor(
|
fun PsiReference.checkUsageVsOriginalDescriptor(
|
||||||
target: JetDeclaration,
|
targetDescriptor: DeclarationDescriptor,
|
||||||
declarationToDescriptor: (JetDeclaration) -> DeclarationDescriptor? = {it.descriptor},
|
declarationToDescriptor: (JetDeclaration) -> DeclarationDescriptor? = {it.descriptor},
|
||||||
checker: (usageDescriptor: DeclarationDescriptor, targetDescriptor: DeclarationDescriptor) -> Boolean
|
checker: (usageDescriptor: DeclarationDescriptor, targetDescriptor: DeclarationDescriptor) -> Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return unwrappedTargets.any {
|
return unwrappedTargets
|
||||||
if (it is JetDeclaration) {
|
.filterIsInstance<JetDeclaration>()
|
||||||
|
.any {
|
||||||
val usageDescriptor = declarationToDescriptor(it)
|
val usageDescriptor = declarationToDescriptor(it)
|
||||||
val targetDescriptor = declarationToDescriptor(target)
|
usageDescriptor != null && checker(usageDescriptor, targetDescriptor)
|
||||||
usageDescriptor != null && targetDescriptor != null && checker(usageDescriptor, targetDescriptor)
|
|
||||||
}
|
|
||||||
else false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,8 +168,9 @@ private fun processClassDelegationCallsToSpecifiedConstructor(
|
|||||||
|
|
||||||
// Check if reference resolves to extension function whose receiver is the same as declaration's parent (or its superclass)
|
// Check if reference resolves to extension function whose receiver is the same as declaration's parent (or its superclass)
|
||||||
// Used in extension search
|
// Used in extension search
|
||||||
fun PsiReference.isExtensionOfDeclarationClassUsage(declaration: JetNamedDeclaration): Boolean =
|
fun PsiReference.isExtensionOfDeclarationClassUsage(declaration: JetNamedDeclaration): Boolean {
|
||||||
checkUsageVsOriginalDescriptor(declaration) { usageDescriptor, targetDescriptor ->
|
val descriptor = declaration.descriptor ?: return false
|
||||||
|
return checkUsageVsOriginalDescriptor(descriptor) { usageDescriptor, targetDescriptor ->
|
||||||
when {
|
when {
|
||||||
usageDescriptor == targetDescriptor -> false
|
usageDescriptor == targetDescriptor -> false
|
||||||
usageDescriptor !is FunctionDescriptor -> false
|
usageDescriptor !is FunctionDescriptor -> false
|
||||||
@@ -187,22 +186,34 @@ fun PsiReference.isExtensionOfDeclarationClassUsage(declaration: JetNamedDeclara
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if reference resolves to the declaration with the same parent
|
// Check if reference resolves to the declaration with the same parent
|
||||||
// Used in overload search
|
// Used in overload search
|
||||||
fun PsiReference.isUsageInContainingDeclaration(declaration: JetNamedDeclaration): Boolean =
|
fun PsiReference.isUsageInContainingDeclaration(declaration: JetNamedDeclaration): Boolean {
|
||||||
checkUsageVsOriginalDescriptor(declaration) { usageDescriptor, targetDescriptor ->
|
val descriptor = declaration.descriptor ?: return false
|
||||||
|
return checkUsageVsOriginalDescriptor(descriptor) { usageDescriptor, targetDescriptor ->
|
||||||
usageDescriptor != targetDescriptor
|
usageDescriptor != targetDescriptor
|
||||||
&& usageDescriptor.getContainingDeclaration() == targetDescriptor.getContainingDeclaration()
|
&& usageDescriptor.getContainingDeclaration() == targetDescriptor.getContainingDeclaration()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun PsiReference.isCallableOverrideUsage(declaration: JetNamedDeclaration): Boolean {
|
fun PsiReference.isCallableOverrideUsage(declaration: JetNamedDeclaration): Boolean {
|
||||||
val decl2Desc = { declaration: JetDeclaration ->
|
val toDescriptor: (JetDeclaration) -> DeclarationDescriptor? = { declaration ->
|
||||||
if (declaration is JetParameter && declaration.hasValOrVar()) declaration.propertyDescriptor else declaration.descriptor
|
if (declaration is JetParameter) {
|
||||||
|
// we don't treat parameters in overriding method as "override" here (overriding parameters usages are searched optionally and via searching of overriding methods first)
|
||||||
|
if (declaration.hasValOrVar()) declaration.propertyDescriptor else null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
declaration.descriptor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkUsageVsOriginalDescriptor(declaration, decl2Desc) { usageDescriptor, targetDescriptor ->
|
val descriptor = toDescriptor(declaration) ?: return false
|
||||||
usageDescriptor is CallableDescriptor && targetDescriptor is CallableDescriptor
|
|
||||||
|
return checkUsageVsOriginalDescriptor(descriptor, toDescriptor) { usageDescriptor, targetDescriptor ->
|
||||||
|
usageDescriptor is CallableDescriptor
|
||||||
|
&& targetDescriptor is CallableDescriptor
|
||||||
&& OverrideResolver.overrides(usageDescriptor, targetDescriptor)
|
&& OverrideResolver.overrides(usageDescriptor, targetDescriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user