Skip to content

Commit

Permalink
Making post work for method calls #17
Browse files Browse the repository at this point in the history
  • Loading branch information
thsaravana committed Aug 30, 2019
1 parent 125d659 commit 10a5394
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.madrapps'
version '0.5.1.2019.1'
version '0.5.2.2019.1'

sourceCompatibility = 1.8

Expand Down
10 changes: 1 addition & 9 deletions src/main/kotlin/com/madrapps/eventbus/FindUsages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,4 @@ internal fun Usage.getPostStatementSourcePsi() = toUElement()?.getParentOfTypeCa

internal fun Usage.getSubscribeMethodSourcePsi() = getType<UMethod>()?.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
}
internal fun Usage.file() = toUElement()?.sourcePsi?.containingFile
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -61,19 +64,13 @@ private class PostLineMarkerInfo(
val uElement = element.toUElement()?.getParentOfType<UCallExpression>()
if (uElement != null) {
val argument = uElement.valueArguments.firstOrNull()
val elementsToSearch: List<PsiElement> = 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 {
Expand Down

0 comments on commit 10a5394

Please sign in to comment.