From 7cd1baff9d331782a6a9130f91cdf4df7a227fa3 Mon Sep 17 00:00:00 2001 From: "Vitaliy.Bibaev" Date: Mon, 25 Dec 2017 18:21:12 +0300 Subject: [PATCH] Fix bug when chain is not detected if method expression is used --- .../streams/kotlin/psi/impl/KotlinChainBuilderBase.kt | 5 +++++ .../psi/streams/positive/location/AsMethodExpression.kt | 5 +++++ .../sequence/psi/streams/positive/location/AsProperty.kt | 5 +++++ .../streams/kotlin/psi/java/LocationPositiveChainTest.kt | 2 ++ 4 files changed, 17 insertions(+) create mode 100644 idea/testData/debugger/sequence/psi/streams/positive/location/AsMethodExpression.kt create mode 100644 idea/testData/debugger/sequence/psi/streams/positive/location/AsProperty.kt diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainBuilderBase.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainBuilderBase.kt index 4497601707d..9a891d5eafe 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainBuilderBase.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainBuilderBase.kt @@ -55,11 +55,16 @@ abstract class KotlinChainBuilderBase(private val transformer: ChainTransformer< private fun getLatestElementInScope(element: PsiElement?): PsiElement? { var current = element while (current != null) { + if (current is KtNamedFunction && current.hasInitializer()) { + break + } + val parent = current.parent if (parent is KtBlockExpression || parent is KtLambdaExpression) { break } + current = parent } diff --git a/idea/testData/debugger/sequence/psi/streams/positive/location/AsMethodExpression.kt b/idea/testData/debugger/sequence/psi/streams/positive/location/AsMethodExpression.kt new file mode 100644 index 00000000000..ecffd3afb32 --- /dev/null +++ b/idea/testData/debugger/sequence/psi/streams/positive/location/AsMethodExpression.kt @@ -0,0 +1,5 @@ +package location + +import java.util.stream.Stream + +fun method() = Stream.of(1, 2, 3).count() \ No newline at end of file diff --git a/idea/testData/debugger/sequence/psi/streams/positive/location/AsProperty.kt b/idea/testData/debugger/sequence/psi/streams/positive/location/AsProperty.kt new file mode 100644 index 00000000000..710f708bd02 --- /dev/null +++ b/idea/testData/debugger/sequence/psi/streams/positive/location/AsProperty.kt @@ -0,0 +1,5 @@ +package location + +import java.util.stream.Stream + +val property = Stream.of(1, 2, 3).findAny() \ No newline at end of file diff --git a/idea/tests/com/intellij/debugger/streams/kotlin/psi/java/LocationPositiveChainTest.kt b/idea/tests/com/intellij/debugger/streams/kotlin/psi/java/LocationPositiveChainTest.kt index 525f089324a..819c1b257f7 100644 --- a/idea/tests/com/intellij/debugger/streams/kotlin/psi/java/LocationPositiveChainTest.kt +++ b/idea/tests/com/intellij/debugger/streams/kotlin/psi/java/LocationPositiveChainTest.kt @@ -36,4 +36,6 @@ class LocationPositiveChainTest : PositiveJavaStreamTest("location") { fun testInString() = doTest() fun testInVariableName() = doTest() fun testInMethodReference() = doTest() + + fun testAsMethodExpression() = doTest() } \ No newline at end of file