From 7009b261d6bc28e7cfdd17852884e3f5da6ab280 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 22 Oct 2018 19:24:39 +0300 Subject: [PATCH] Don't rank local classes (KT-27712) Allow enable ranking even for single source file in tests #KT-27712 --- .../src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt | 6 +++++- .../jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt | 3 +++ ...stopInObjectLiteralInInlineCallWithClosureInAnonymous.kt | 2 ++ .../kotlin/idea/debugger/KotlinDebuggerTestBase.kt | 5 ++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt index ff4d6a4fc48..198875872fb 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.io.FileUtilRt import com.intellij.psi.search.GlobalSearchScope import com.sun.jdi.Location +import org.jetbrains.annotations.TestOnly import org.jetbrains.kotlin.asJava.finder.JavaElementFinder import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.idea.KotlinFileTypeFactory @@ -42,6 +43,9 @@ import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* object DebuggerUtils { + @TestOnly + var forceRanking = false + fun findSourceFileForClassIncludeLibrarySources( project: Project, scope: GlobalSearchScope, @@ -74,7 +78,7 @@ object DebuggerUtils { if (filesWithExactName.isEmpty()) return null - if (filesWithExactName.size == 1) { + if (filesWithExactName.size == 1 && !forceRanking) { return filesWithExactName.single() } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt index 9e9604839b7..a7ac8cea0c8 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypes2 import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypes3 import org.jetbrains.kotlin.psi.psiUtil.isAncestor import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.varargParameterPosition import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.utils.keysToMap @@ -107,6 +108,8 @@ abstract class FileRankingCalculator(private val checkClassFqName: Boolean = tru } private fun rankingForClassName(fqName: String, descriptor: ClassDescriptor, bindingContext: BindingContext): Ranking { + if (DescriptorUtils.isLocal(descriptor)) return Ranking.ZERO + val expectedFqName = makeTypeMapper(bindingContext).mapType(descriptor).className return when { checkClassFqName -> if (expectedFqName == fqName) MAJOR else LOW diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInObjectLiteralInInlineCallWithClosureInAnonymous.kt b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInObjectLiteralInInlineCallWithClosureInAnonymous.kt index e0f38eb7c3b..cdbfd45122a 100644 --- a/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInObjectLiteralInInlineCallWithClosureInAnonymous.kt +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInObjectLiteralInInlineCallWithClosureInAnonymous.kt @@ -1,5 +1,7 @@ package stopInObjectLiteralInInlineCallWithClosureInAnonymous +// FORCE_RANKING + fun main(args: Array) { val a = 12 diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt index e8fd93911a5..36551918efd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt @@ -65,7 +65,6 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.InTextDirectivesUtils.findStringWithPrefixes import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import java.io.File -import java.lang.AssertionError import javax.swing.SwingUtilities abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { @@ -113,6 +112,8 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { debuggerSettings.SKIP_CLASSLOADERS = fileText.getValueForSetting("SKIP_CLASSLOADERS", oldSettings!!.SKIP_CLASSLOADERS) debuggerSettings.TRACING_FILTERS_ENABLED = fileText.getValueForSetting("TRACING_FILTERS_ENABLED", oldSettings!!.TRACING_FILTERS_ENABLED) debuggerSettings.SKIP_GETTERS = fileText.getValueForSetting("SKIP_GETTERS", oldSettings!!.SKIP_GETTERS) + + DebuggerUtils.forceRanking = InTextDirectivesUtils.isDirectiveDefined(fileText, "FORCE_RANKING") } private fun String.getValueForSetting(name: String, defaultValue: Boolean): Boolean { @@ -137,6 +138,8 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { debuggerSettings.SKIP_CLASSLOADERS = oldSettings!!.SKIP_CLASSLOADERS debuggerSettings.TRACING_FILTERS_ENABLED = oldSettings!!.TRACING_FILTERS_ENABLED debuggerSettings.SKIP_GETTERS = oldSettings!!.SKIP_GETTERS + + DebuggerUtils.forceRanking = false } protected val dp: DebugProcessImpl