Minor. Reformat usagesSearch/utils.kt
This commit is contained in:
@@ -31,9 +31,9 @@ import org.jetbrains.kotlin.asJava.toLightMethods
|
|||||||
import org.jetbrains.kotlin.asJava.unwrapped
|
import org.jetbrains.kotlin.asJava.unwrapped
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaMethodDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToParameterDescriptorIfAny
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToParameterDescriptorIfAny
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaMethodDescriptor
|
||||||
import org.jetbrains.kotlin.idea.references.unwrappedTargets
|
import org.jetbrains.kotlin.idea.references.unwrappedTargets
|
||||||
import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchRequest
|
import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchRequest
|
||||||
import org.jetbrains.kotlin.idea.search.declarationsSearch.searchInheritors
|
import org.jetbrains.kotlin.idea.search.declarationsSearch.searchInheritors
|
||||||
@@ -68,7 +68,7 @@ val KtParameter.propertyDescriptor: PropertyDescriptor?
|
|||||||
|
|
||||||
fun PsiReference.checkUsageVsOriginalDescriptor(
|
fun PsiReference.checkUsageVsOriginalDescriptor(
|
||||||
targetDescriptor: DeclarationDescriptor,
|
targetDescriptor: DeclarationDescriptor,
|
||||||
declarationToDescriptor: (KtDeclaration) -> DeclarationDescriptor? = {it.descriptor},
|
declarationToDescriptor: (KtDeclaration) -> DeclarationDescriptor? = { it.descriptor },
|
||||||
checker: (usageDescriptor: DeclarationDescriptor, targetDescriptor: DeclarationDescriptor) -> Boolean
|
checker: (usageDescriptor: DeclarationDescriptor, targetDescriptor: DeclarationDescriptor) -> Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return unwrappedTargets
|
return unwrappedTargets
|
||||||
@@ -82,7 +82,7 @@ fun PsiReference.checkUsageVsOriginalDescriptor(
|
|||||||
fun PsiReference.isImportUsage(): Boolean =
|
fun PsiReference.isImportUsage(): Boolean =
|
||||||
element!!.getNonStrictParentOfType<KtImportDirective>() != null
|
element!!.getNonStrictParentOfType<KtImportDirective>() != null
|
||||||
|
|
||||||
fun PsiReference.isConstructorUsage(ktClassOrObject: KtClassOrObject): Boolean = with (element!!) {
|
fun PsiReference.isConstructorUsage(ktClassOrObject: KtClassOrObject): Boolean = with(element!!) {
|
||||||
fun checkJavaUsage(): Boolean {
|
fun checkJavaUsage(): Boolean {
|
||||||
val call = getNonStrictParentOfType<PsiConstructorCall>()
|
val call = getNonStrictParentOfType<PsiConstructorCall>()
|
||||||
return call == parent && call?.resolveConstructor()?.containingClass?.navigationElement == ktClassOrObject
|
return call == parent && call?.resolveConstructor()?.containingClass?.navigationElement == ktClassOrObject
|
||||||
@@ -132,7 +132,10 @@ fun PsiElement.buildProcessDelegationCallConstructorUsagesTask(scope: SearchScop
|
|||||||
return { task1() && task2() }
|
return { task1() && task2() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun PsiElement.buildProcessDelegationCallKotlinConstructorUsagesTask(scope: SearchScope, process: (KtCallElement) -> Boolean): () -> Boolean {
|
private fun PsiElement.buildProcessDelegationCallKotlinConstructorUsagesTask(
|
||||||
|
scope: SearchScope,
|
||||||
|
process: (KtCallElement) -> Boolean
|
||||||
|
): () -> Boolean {
|
||||||
val element = unwrapped
|
val element = unwrapped
|
||||||
if (element != null && element !in scope) return { true }
|
if (element != null && element !in scope) return { true }
|
||||||
|
|
||||||
@@ -151,7 +154,10 @@ private fun PsiElement.buildProcessDelegationCallKotlinConstructorUsagesTask(sco
|
|||||||
return { processInheritorsDelegatingCallToSpecifiedConstructor(klass, scope, descriptor, process) }
|
return { processInheritorsDelegatingCallToSpecifiedConstructor(klass, scope, descriptor, process) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun PsiElement.buildProcessDelegationCallJavaConstructorUsagesTask(scope: SearchScope, process: (KtCallElement) -> Boolean): () -> Boolean {
|
private fun PsiElement.buildProcessDelegationCallJavaConstructorUsagesTask(
|
||||||
|
scope: SearchScope,
|
||||||
|
process: (KtCallElement) -> Boolean
|
||||||
|
): () -> Boolean {
|
||||||
if (this is KtLightElement<*, *>) return { true }
|
if (this is KtLightElement<*, *>) return { true }
|
||||||
// TODO: Temporary hack to avoid NPE while KotlinNoOriginLightMethod is around
|
// TODO: Temporary hack to avoid NPE while KotlinNoOriginLightMethod is around
|
||||||
if (this is KtLightMethod && this.kotlinOrigin == null) return { true }
|
if (this is KtLightMethod && this.kotlinOrigin == null) return { true }
|
||||||
@@ -237,8 +243,7 @@ fun PsiReference.isCallableOverrideUsage(declaration: KtNamedDeclaration): Boole
|
|||||||
if (declaration is KtParameter) {
|
if (declaration is KtParameter) {
|
||||||
// we don't treat parameters in overriding method as "override" here (overriding parameters usages are searched optionally and via searching of overriding methods first)
|
// 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
|
if (declaration.hasValOrVar()) declaration.propertyDescriptor else null
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
declaration.descriptor as? CallableDescriptor
|
declaration.descriptor as? CallableDescriptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,8 +268,7 @@ fun PsiElement.searchReferencesOrMethodReferences(): Collection<PsiReference> {
|
|||||||
val lightMethods = toLightMethods()
|
val lightMethods = toLightMethods()
|
||||||
return if (lightMethods.isNotEmpty()) {
|
return if (lightMethods.isNotEmpty()) {
|
||||||
lightMethods.flatMapTo(LinkedHashSet()) { MethodReferencesSearch.search(it) }
|
lightMethods.flatMapTo(LinkedHashSet()) { MethodReferencesSearch.search(it) }
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ReferencesSearch.search(this).findAll()
|
ReferencesSearch.search(this).findAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user