From 10a5394e91bedd460f57e3ff1b5f2f770ffbe918 Mon Sep 17 00:00:00 2001
From: thsaravana
Date: Fri, 30 Aug 2019 21:19:22 +0530
Subject: [PATCH] Making `post` work for method calls #17
---
build.gradle | 2 +-
.../com/madrapps/eventbus/FindUsages.kt | 10 +-------
.../eventbus/post/PostLineMarkerProvider.kt | 23 ++++++++-----------
3 files changed, 12 insertions(+), 23 deletions(-)
diff --git a/build.gradle b/build.gradle
index 398b5d8..95656db 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ plugins {
}
group 'com.madrapps'
-version '0.5.1.2019.1'
+version '0.5.2.2019.1'
sourceCompatibility = 1.8
diff --git a/src/main/kotlin/com/madrapps/eventbus/FindUsages.kt b/src/main/kotlin/com/madrapps/eventbus/FindUsages.kt
index e1e359a..e1accab 100644
--- a/src/main/kotlin/com/madrapps/eventbus/FindUsages.kt
+++ b/src/main/kotlin/com/madrapps/eventbus/FindUsages.kt
@@ -56,12 +56,4 @@ internal fun Usage.getPostStatementSourcePsi() = toUElement()?.getParentOfTypeCa
internal fun Usage.getSubscribeMethodSourcePsi() = getType()?.uastAnchor?.sourcePsi
-internal fun Usage.file() = toUElement()?.sourcePsi?.containingFile
-
-internal fun UQualifiedReferenceExpression.lastReceiver(): UExpression? {
- var temp = receiver
- while (temp is UQualifiedReferenceExpression) {
- temp = temp.receiver
- }
- return temp
-}
\ No newline at end of file
+internal fun Usage.file() = toUElement()?.sourcePsi?.containingFile
\ No newline at end of file
diff --git a/src/main/kotlin/com/madrapps/eventbus/post/PostLineMarkerProvider.kt b/src/main/kotlin/com/madrapps/eventbus/post/PostLineMarkerProvider.kt
index 917cd28..83d728c 100644
--- a/src/main/kotlin/com/madrapps/eventbus/post/PostLineMarkerProvider.kt
+++ b/src/main/kotlin/com/madrapps/eventbus/post/PostLineMarkerProvider.kt
@@ -15,7 +15,10 @@ import com.intellij.usages.UsageInfo2UsageAdapter
import com.intellij.util.concurrency.AppExecutorUtil
import com.madrapps.eventbus.*
import com.madrapps.eventbus.subscribe.isSubscribe
-import org.jetbrains.uast.*
+import org.jetbrains.uast.UCallExpression
+import org.jetbrains.uast.UImportStatement
+import org.jetbrains.uast.getParentOfType
+import org.jetbrains.uast.toUElement
class PostLineMarkerProvider : LineMarkerProvider {
@@ -61,19 +64,13 @@ private class PostLineMarkerInfo(
val uElement = element.toUElement()?.getParentOfType()
if (uElement != null) {
val argument = uElement.valueArguments.firstOrNull()
- val elementsToSearch: List = if (argument is UQualifiedReferenceExpression) {
- val sourcePsi = (argument.lastReceiver() as USimpleNameReferenceExpression).sourcePsi
- sourcePsi?.references?.mapNotNull { it.resolve() } ?: emptyList()
- } else {
- val resolve = (argument?.getExpressionType() as PsiClassType).resolve()
- if (resolve != null) {
- listOf(resolve)
- } else emptyList()
+ val resolve = (argument?.getExpressionType() as PsiClassType).resolve()
+ if (resolve != null) {
+ val collection = search(resolve)
+ usages = collection
+ .filter(UsageInfo::isSubscribe)
+ .map(::UsageInfo2UsageAdapter)
}
- val collection = search(elementsToSearch)
- usages = collection
- .filter(UsageInfo::isSubscribe)
- .map(::UsageInfo2UsageAdapter)
}
blog("PostLineMarker - ${usages.size} usages found")
ApplicationManager.getApplication().invokeLater {