From dd8b6673603ac3e6d44615fa97c4d3c13cc06dd9 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 27 Apr 2016 16:48:02 +0300 Subject: [PATCH] Don't analyze function body if only parameter analyze is requested --- .../kotlin/idea/project/ResolveElementCache.kt | 8 ++++++++ .../kotlin/idea/ResolveElementCacheTest.kt | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt index 67c8c3b39bd..b2648f1f566 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt @@ -243,6 +243,14 @@ class ResolveElementCache( return elementOfAdditionalResolve } + is KtDeclaration -> { + if (element is KtParameter && !KtPsiUtil.isLocal(element)) { + return null + } + + return elementOfAdditionalResolve + } + else -> return elementOfAdditionalResolve } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt index 92cec8bb128..efbc950dd94 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt @@ -323,6 +323,22 @@ class C(param1: String = "", param2: Int = 0) { ) } + fun testNoBodyResolveOnFunctionParameterAnalyze() { + val file = configureWithKotlin( + """ + fun test(a: String) { + unresolved // Check diagnostics is empty even in FULL mode when starting analyzing for parameter + } + """) + + val function = file.declarations[0] as KtNamedFunction + val functionParameter = function.valueParameters.first() + + val context = functionParameter.analyze(BodyResolveMode.FULL) + + assertEmpty(context.diagnostics.all()) + } + private fun configureWithKotlin(@Language("kotlin") text: String): KtFile { return myFixture.configureByText("Test.kt", text.trimIndent()) as KtFile }