@@ -40,7 +40,7 @@ class JvmBlockingBridgePsiAugmentProvider : PsiAugmentProvider() {
4040
4141 private class JvmBlockingBridgeCachedValueProvider (
4242 private val element : PsiElement ,
43- private val psiAugmentGenerator : () -> List <PsiElement >
43+ private val psiAugmentGenerator : () -> List <PsiElement >,
4444 ) : CachedValueProvider<List<PsiElement>> {
4545 companion object {
4646 internal val guard = RecursionManager .createGuard<PsiElement >(" kjbb.augment" )
@@ -57,24 +57,40 @@ class JvmBlockingBridgePsiAugmentProvider : PsiAugmentProvider() {
5757
5858internal fun PsiExtensibleClass.generateAugmentElements (): List <PsiElement > {
5959 return this .ownMethods.asSequence()
60- .filter { it.canHaveBlockingBridge () }
60+ .filter { it.isCompanionedWithBlockingBrideInThisOrSuper () }
6161 .filterIsInstance<KtLightMethod >()
6262 .map { it.generateLightMethod() }
6363 .toList()
6464}
6565
66- internal fun PsiMethod.canHaveBlockingBridge (): Boolean {
67- return if (this is KtLightMethod && isSuspend()
66+ internal fun PsiMethod.isCompanionedWithBlockingBrideInThisOrSuper (): Boolean {
67+ return if (isSuspend()
6868 && Name .isValidIdentifier(this .name)
6969 && this .hasAnnotation(JvmBlockingBridge ::class .qualifiedName!! )
70- && ! this .containingClass.isInterface
7170 ) {
72- ! hasOverridingMethod()
71+ true
7372 } else {
74- false
73+ return findOverrides()?.any { it.isCompanionedWithBlockingBrideInThisOrSuper() } == true
7574 }
7675}
7776
77+ /* *
78+ * @return `null` if top-level method
79+ */
80+ internal fun PsiMethod.findOverrides (): Sequence <PsiMethod >? {
81+ return containingClass?.superClasses
82+ ?.flatMap { it.methods.asSequence() }
83+ ?.filter {
84+ it.hasSameSignatureWith(this )
85+ }
86+ }
87+
88+ internal fun PsiMethod.hasSameSignatureWith (another : PsiMethod ): Boolean {
89+ return this .hierarchicalMethodSignature == another.hierarchicalMethodSignature
90+ }
91+
92+ internal val PsiClass .superClasses: Sequence <PsiClass > get() = this .superTypes.asSequence().mapNotNull { it.resolve() }
93+
7894internal fun PsiMethod.hasOverridingMethod (): Boolean {
7995 var any = false
8096 forEachOverridingMethod {
@@ -103,10 +119,10 @@ internal val PsiMethod.overridingMethods: List<PsiMethod>
103119 return mutableList
104120 }
105121
106- internal fun KtLightMethod .isSuspend (): Boolean =
122+ internal fun PsiMethod .isSuspend (): Boolean =
107123 this .modifierList.text.contains(" suspend" )
108124
109- internal fun KtLightMethod .isJvmStatic (): Boolean = hasAnnotation(JvmStatic ::class .qualifiedName!! )
125+ internal fun PsiMethod .isJvmStatic (): Boolean = hasAnnotation(JvmStatic ::class .qualifiedName!! )
110126
111127internal fun KtLightMethod.generateLightMethod (): PsiMethod {
112128 val originMethod = this
0 commit comments