Code fragment analysis: analyze parents if there's no sensible scope for the default element (KT-29179)
This commit is contained in:
+6
-5
@@ -19,10 +19,12 @@ package org.jetbrains.kotlin.idea.caches.resolve
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.idea.project.ResolveElementCache
|
import org.jetbrains.kotlin.idea.project.ResolveElementCache
|
||||||
|
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypes2
|
||||||
import org.jetbrains.kotlin.resolve.*
|
import org.jetbrains.kotlin.resolve.*
|
||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoAfter
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoAfter
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
@@ -135,16 +137,15 @@ class CodeFragmentAnalyzer(
|
|||||||
}
|
}
|
||||||
is KtElement -> {
|
is KtElement -> {
|
||||||
bindingContext = resolutionFactory(context)
|
bindingContext = resolutionFactory(context)
|
||||||
scope = bindingContext[BindingContext.LEXICAL_SCOPE, context]
|
scope = context.getResolutionScope(bindingContext)
|
||||||
dataFlowInfo = bindingContext.getDataFlowInfoAfter(context)
|
dataFlowInfo = bindingContext.getDataFlowInfoAfter(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope == null) {
|
if (scope == null) {
|
||||||
val containingKtFile = context?.containingFile as? KtFile
|
val parentDeclaration = context?.getParentOfTypes2<KtDeclaration, KtFile>()
|
||||||
if (containingKtFile != null) {
|
if (parentDeclaration != null) {
|
||||||
bindingContext = resolveSession.bindingContext
|
return getContextInfo(parentDeclaration, resolutionFactory)
|
||||||
scope = resolveSession.fileScopeProvider.getFileResolutionScope(containingKtFile)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package kt29179
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val a = 1
|
||||||
|
fun bar() = 2
|
||||||
|
fun foo() {
|
||||||
|
3
|
||||||
|
//Breakpoint!
|
||||||
|
.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
A().foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPRESSION: bar()
|
||||||
|
// RESULT: 2: I
|
||||||
|
|
||||||
|
// EXPRESSION: this
|
||||||
|
// RESULT: instance of kt29179.A(id=ID): Lkt29179/A;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
LineBreakpoint created at kt29179.kt:9
|
||||||
|
Run Java
|
||||||
|
Connected to the target VM
|
||||||
|
kt29179.kt:9
|
||||||
|
Compile bytecode for bar()
|
||||||
|
Compile bytecode for this
|
||||||
|
Disconnected from the target VM
|
||||||
|
|
||||||
|
Process finished with exit code 0
|
||||||
Generated
+5
@@ -271,6 +271,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
|||||||
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/kt28087.kt");
|
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/kt28087.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt29179.kt")
|
||||||
|
public void testKt29179() throws Exception {
|
||||||
|
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/kt29179.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5554OnlyIntsShouldBeCoerced.kt")
|
@TestMetadata("kt5554OnlyIntsShouldBeCoerced.kt")
|
||||||
public void testKt5554OnlyIntsShouldBeCoerced() throws Exception {
|
public void testKt5554OnlyIntsShouldBeCoerced() throws Exception {
|
||||||
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/kt5554OnlyIntsShouldBeCoerced.kt");
|
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/kt5554OnlyIntsShouldBeCoerced.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user