From f7af927e8f35aa92488cf5bf21df2f65152cba58 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 8 Mar 2016 22:44:13 +0100 Subject: [PATCH] Don't set parameter names and register unresolved error correctly --- .../fixers/KotlinLastLambdaParameterFixer.kt | 29 +++--- .../codeInsight/smartEnter/SmartEnterTest.kt | 90 +------------------ 2 files changed, 22 insertions(+), 97 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt b/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt index 1fe521fa308..0883303316d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt @@ -19,9 +19,11 @@ package org.jetbrains.kotlin.idea.editor.fixers import com.intellij.lang.SmartEnterProcessorWithFixers import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiElement +import com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler +import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall @@ -29,8 +31,15 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class KotlinLastLambdaParameterFixer : SmartEnterProcessorWithFixers.Fixer() { override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) { - if (element !is KtCallExpression) return + if (element is KtCallExpression) { + addBracesIfNecessary(editor, element, processor) + } + else if (element is LeafPsiElement) { + registerErrorIfNecessary(element, processor) + } + } + private fun addBracesIfNecessary(editor: Editor, element: KtCallExpression, processor: KotlinSmartEnterHandler) { val bindingContext = element.analyze(BodyResolveMode.PARTIAL) val resolvedCall = element.getResolvedCall(bindingContext) ?: return @@ -47,16 +56,16 @@ class KotlinLastLambdaParameterFixer : SmartEnterProcessorWithFixers.Fixer\n}") - } + doc.insertString(offset, "{ }") + processor.registerUnresolvedError(offset + 2) } } } + + private fun registerErrorIfNecessary(element: LeafPsiElement, processor: KotlinSmartEnterHandler) { + if(element.elementType != KtTokens.LBRACE) return + if(element.parent?.parent?.parent?.parent !is KtCallExpression) return + + processor.registerUnresolvedError(element.endOffset + 1) + } } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/smartEnter/SmartEnterTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/smartEnter/SmartEnterTest.kt index 9ed91ef1c09..6b68cf7f1b8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/smartEnter/SmartEnterTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/smartEnter/SmartEnterTest.kt @@ -1281,7 +1281,7 @@ class SmartEnterTest : KotlinLightCodeInsightFixtureTestCase() { """ ) - fun testLambdaParamImplicit1() = doFileTest( + fun testLambdaParam() = doFileTest( """ fun foo(a: Any, block: () -> Unit) { } @@ -1294,49 +1294,7 @@ class SmartEnterTest : KotlinLightCodeInsightFixtureTestCase() { fun foo(a: Any, block: () -> Unit) { } fun test() { - foo(Any()) { - - } - } - """ - ) - - fun testLambdaParamImplicit2() = doFileTest( - """ - fun foo(a: Any, block: (Any) -> Unit) { - } - fun test() { - foo(Any() - } - """ - , - """ - fun foo(a: Any, block: (Any) -> Unit) { - } - fun test() { - foo(Any()) { - - } - } - """ - ) - - fun testLambdaParamExplicit1() = doFileTest( - """ - fun foo(a: Any, block: (Any, Any) -> Unit) { - } - fun test() { - foo(Any()) - } - """ - , - """ - fun foo(a: Any, block: (Any, Any) -> Unit) { - } - fun test() { - foo(Any()) { x1, x2 -> - - } + foo(Any()) { } } """ ) @@ -1354,49 +1312,7 @@ class SmartEnterTest : KotlinLightCodeInsightFixtureTestCase() { fun foo(a: Any, block: Any.() -> Unit) { } fun test() { - foo(Any()) { - - } - } - """ - ) - - fun testExtensionLambdaParamImplicit2() = doFileTest( - """ - fun foo(a: Any, block: Any.(Any) -> Unit) { - } - fun test() { - foo(Any() - } - """ - , - """ - fun foo(a: Any, block: Any.(Any) -> Unit) { - } - fun test() { - foo(Any()) { - - } - } - """ - ) - - fun testExtensionLambdaParamExplicit1() = doFileTest( - """ - fun foo(a: Any, block: Any.(Any, Any) -> Unit) { - } - fun test() { - foo(Any()) - } - """ - , - """ - fun foo(a: Any, block: Any.(Any, Any) -> Unit) { - } - fun test() { - foo(Any()) { x1, x2 -> - - } + foo(Any()) { } } """ )