From 6066d19de5a093b54870e1a9aff08aa7f65a115d Mon Sep 17 00:00:00 2001 From: Lingzhang Date: Thu, 27 Mar 2014 15:17:52 -0400 Subject: [PATCH] Added KT-4579 makeTypeExplicitInLambda and makeTypeImplicitInLambda intentions --- .../jet/generators/tests/GenerateTests.kt | 2 + .../after.kt.template | 1 + .../before.kt.template | 1 + .../description.html | 5 + .../after.kt.template | 1 + .../before.kt.template | 1 + .../description.html | 5 + idea/src/META-INF/plugin.xml | 10 ++ .../jetbrains/jet/plugin/JetBundle.properties | 4 + .../MakeTypeExplicitInLambdaIntention.kt | 113 +++++++++++++ .../MakeTypeImplicitInLambdaIntention.kt | 95 +++++++++++ .../coercionToUnit.kt | 9 ++ .../coercionToUnit.kt.after | 9 ++ .../emptyParamListWithBrackets.kt | 4 + .../emptyParamListWithIt.kt | 9 ++ .../emptyParamListWithIt.kt.after | 9 ++ .../emptyParamListWithWhiteSpace.kt | 5 + .../emptyParamListWithWhiteSpace.kt.after | 6 + .../emptyParamListWithoutItWithArrow.kt | 3 + .../emptyParamListWithoutItWithArrow.kt.after | 3 + .../invalidCursorPosition.kt | 4 + .../lambdaWithLambdaAsParam.kt | 8 + .../lambdaWithLambdaAsParam.kt.after | 8 + .../makeTypeExplicitInLambda/manyNewlines.kt | 8 + .../manyNewlines.kt.after | 6 + .../makeTypeExplicitInLambda/multipleParam.kt | 10 ++ .../multipleParam.kt.after | 10 ++ .../paramDeclaredReturnNotDeclared.kt | 3 + .../paramDeclaredReturnNotDeclared.kt.after | 3 + .../returnDeclaredParamNotDeclared.kt | 3 + .../returnDeclaredParamNotDeclared.kt.after | 3 + .../shortenReferencesForParams.kt | 3 + .../shortenReferencesForParams.kt.after | 3 + .../shortenReferencesForReceiver.kt | 3 + .../shortenReferencesForReceiver.kt.after | 3 + .../makeTypeExplicitInLambda/singleParam.kt | 9 ++ .../singleParam.kt.after | 9 ++ .../singleParamWithReceiver.kt | 9 ++ .../singleParamWithReceiver.kt.after | 9 ++ .../typesAlreadyExplicit.kt | 4 + .../typesNotInferable.kt | 6 + .../explicitReceiverType.kt | 9 ++ .../explicitReceiverType.kt.after | 9 ++ .../explicitReturnType.kt | 3 + .../explicitReturnType.kt.after | 3 + .../invalidCursorPosition.kt | 4 + .../lambdaWithLambdaAsParam.kt | 8 + .../lambdaWithLambdaAsParam.kt.after | 8 + .../multipleExplicitParams.kt | 3 + .../multipleExplicitParams.kt.after | 3 + .../paramDeclaredReturnNotDeclared.kt | 3 + .../paramDeclaredReturnNotDeclared.kt.after | 3 + .../returnDeclaredParamNotDeclared.kt | 3 + .../returnDeclaredParamNotDeclared.kt.after | 3 + .../singleExplicitParam.kt | 3 + .../singleExplicitParam.kt.after | 3 + .../typesAlreadyImplicit.kt | 8 + ...DontChangeFunctionReturnTypeToErrorType.kt | 4 + .../AbstractCodeTransformationTest.java | 8 + .../CodeTransformationTestGenerated.java | 150 +++++++++++++++++- 60 files changed, 656 insertions(+), 1 deletion(-) create mode 100644 idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/description.html create mode 100644 idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/description.html create mode 100644 idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeExplicitInLambdaIntention.kt create mode 100644 idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithBrackets.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/invalidCursorPosition.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt.after create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/typesAlreadyExplicit.kt create mode 100644 idea/testData/intentions/makeTypeExplicitInLambda/typesNotInferable.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt.after create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt.after create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/invalidCursorPosition.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt.after create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt.after create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt.after create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt.after create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt.after create mode 100644 idea/testData/intentions/makeTypeImplicitInLambda/typesAlreadyImplicit.kt diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index a542d1248f7..e83d8cdbccd 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -409,6 +409,8 @@ fun main(args: Array) { model("intentions/removeExplicitTypeArguments", testMethod = "doTestRemoveExplicitTypeArguments") model("intentions/convertAssertToIf", testMethod = "doTestConvertAssertToIfWithThrowIntention") model("intentions/convertIfToAssert", testMethod = "doTestConvertIfWithThrowToAssertIntention") + model("intentions/makeTypeExplicitInLambda", testMethod = "doTestMakeTypeExplicitInLambda") + model("intentions/makeTypeImplicitInLambda", testMethod = "doTestMakeTypeImplicitInLambda") } testClass(javaClass()) { diff --git a/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/after.kt.template b/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/after.kt.template new file mode 100644 index 00000000000..c073304e986 --- /dev/null +++ b/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/after.kt.template @@ -0,0 +1 @@ +foo(1, 2, {(a: Int, b: Int): Int -> a + b}) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/before.kt.template b/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/before.kt.template new file mode 100644 index 00000000000..475b9ecfe58 --- /dev/null +++ b/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/before.kt.template @@ -0,0 +1 @@ +foo(1, 2, {a, b -> a + b}) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/description.html b/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/description.html new file mode 100644 index 00000000000..80c06d8b76b --- /dev/null +++ b/idea/resources/intentionDescriptions/MakeTypeExplicitInLambdaIntention/description.html @@ -0,0 +1,5 @@ + + +This intention makes types of parameters, receiver, and return type explicit in a lambda expression. + + \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/after.kt.template b/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/after.kt.template new file mode 100644 index 00000000000..475b9ecfe58 --- /dev/null +++ b/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/after.kt.template @@ -0,0 +1 @@ +foo(1, 2, {a, b -> a + b}) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/before.kt.template b/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/before.kt.template new file mode 100644 index 00000000000..9c9d53293ce --- /dev/null +++ b/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/before.kt.template @@ -0,0 +1 @@ +foo(1, 2, {(a: Int, b:Int): Int -> a + b}) \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/description.html b/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/description.html new file mode 100644 index 00000000000..19458639f5c --- /dev/null +++ b/idea/resources/intentionDescriptions/MakeTypeImplicitInLambdaIntention/description.html @@ -0,0 +1,5 @@ + + +This intention makes types of parameters, receiver, and return type implicit in a lambda expression + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 56dc561e620..850f7b2eb7d 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -687,6 +687,16 @@ Kotlin + + org.jetbrains.jet.plugin.intentions.MakeTypeExplicitInLambdaIntention + Kotlin + + + + org.jetbrains.jet.plugin.intentions.MakeTypeImplicitInLambdaIntention + Kotlin + + ( + "make.type.explicit.in.lambda", javaClass()) { + + override fun isApplicableTo(element: JetFunctionLiteralExpression): Boolean { + throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") + } + + override fun isApplicableTo(element: JetFunctionLiteralExpression, editor: Editor): Boolean { + val openBraceOffset = element.getLeftCurlyBrace().getStartOffset() + val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset() + val caretLocation = editor.getCaretModel().getOffset() + val arrow = element.getFunctionLiteral().getArrowNode() + if (arrow != null && !(openBraceOffset < caretLocation && caretLocation < arrow.getStartOffset() + 2) && + caretLocation != closeBraceOffset) return false + else if (arrow == null && caretLocation != openBraceOffset + 1 && caretLocation != closeBraceOffset) return false + + val context = AnalyzerFacadeWithCache.getContextForElement(element) + val func = context[BindingContext.FUNCTION, element.getFunctionLiteral()] + if (func == null || ErrorUtils.containsErrorType(func)) return false + + if (hasImplicitReturnType(element) && func.getReturnType() != null) return true + if (hasImplicitReceiverType(element) && func.getReceiverParameter()?.getType() != null) return true + + val params = element.getValueParameters() + return params.any { it.getTypeReference() == null } + } + + override fun applyTo(element: JetFunctionLiteralExpression, editor: Editor) { + val functionLiteral = element.getFunctionLiteral() + val context = AnalyzerFacadeWithCache.getContextForElement(element) + val func = context[BindingContext.FUNCTION, functionLiteral]!! + + // Step 1: make the parameters types explicit + val valueParameters = func.getValueParameters() + val parameterString = valueParameters.map({descriptor -> "" + descriptor.getName() + + ": " + DescriptorRenderer.SOURCE_CODE.renderType(descriptor.getType()) + }).makeString(", ", "(", ")") + val newParameterList = JetPsiFactory.createParameterList(element.getProject(), parameterString) + val oldParameterList = functionLiteral.getValueParameterList() + if (oldParameterList != null) { + oldParameterList.replace(newParameterList) + } + else { + val openBraceElement = functionLiteral.getOpenBraceNode().getPsi() + val nextSibling = openBraceElement?.getNextSibling() + val addNewline = nextSibling is PsiWhiteSpace && "\n" in nextSibling.getText() + val whitespaceAndArrow = JetPsiFactory.createWhitespaceAndArrow(element.getProject()) + functionLiteral.addRangeAfter(whitespaceAndArrow.first, whitespaceAndArrow.second, openBraceElement) + functionLiteral.addAfter(newParameterList, openBraceElement) + if (addNewline) { + functionLiteral.addAfter(JetPsiFactory.createNewLine(element.getProject()), openBraceElement) + } + } + ShortenReferences.process(element.getValueParameters()) + + // Step 2: make the return type explicit + val expectedReturnType = func.getReturnType() + if (hasImplicitReturnType(element) && expectedReturnType != null) { + val paramList = functionLiteral.getValueParameterList() + val returnTypeColon = JetPsiFactory.createColon(element.getProject()) + val returnTypeExpr = JetPsiFactory.createType(element.getProject(), DescriptorRenderer.SOURCE_CODE.renderType(expectedReturnType)) + ShortenReferences.process(returnTypeExpr) + functionLiteral.addAfter(returnTypeExpr, paramList) + functionLiteral.addAfter(returnTypeColon, paramList) + } + + // Step 3: make the receiver type explicit + val expectedReceiverType = func.getReceiverParameter()?.getType() + if (hasImplicitReceiverType(element) && expectedReceiverType != null) { + val receiverTypeString = DescriptorRenderer.SOURCE_CODE.renderType(expectedReceiverType) + val paramListString = functionLiteral.getValueParameterList()?.getText() + val paramListWithReceiver = JetPsiFactory.createExpression(element.getProject(), receiverTypeString + "." + paramListString) + ShortenReferences.process(paramListWithReceiver) + functionLiteral.getValueParameterList()?.replace(paramListWithReceiver) + } + } + + private fun hasImplicitReturnType(element: JetFunctionLiteralExpression): Boolean { + return !element.hasDeclaredReturnType() + } + + private fun hasImplicitReceiverType(element: JetFunctionLiteralExpression): Boolean { + return element.getFunctionLiteral().getReceiverTypeRef() == null + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt new file mode 100644 index 00000000000..2b5b6d2e620 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt @@ -0,0 +1,95 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression +import org.jetbrains.jet.lang.psi.JetPsiFactory +import org.jetbrains.jet.lexer.JetTokens + +public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention( + "make.type.implicit.in.lambda", javaClass()) { + override fun isApplicableTo(element: JetFunctionLiteralExpression): Boolean { + throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") + } + + override fun isApplicableTo(element: JetFunctionLiteralExpression, editor: Editor): Boolean { + val openBraceOffset = element.getLeftCurlyBrace().getStartOffset() + val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset() + val caretLocation = editor.getCaretModel().getOffset() + val arrow = element.getFunctionLiteral().getArrowNode() + if (arrow != null && !(openBraceOffset < caretLocation && caretLocation < arrow.getStartOffset() + 2) && + caretLocation != closeBraceOffset) return false + else if (arrow == null && caretLocation != openBraceOffset + 1 && caretLocation != closeBraceOffset) return false + return hasExplicitReturnType(element) || hasExplicitReceiverType(element) || hasExplicitParamType(element) + } + + override fun applyTo(element: JetFunctionLiteralExpression, editor: Editor) { + val functionLiteral = element.getFunctionLiteral() + val oldParameterList = functionLiteral.getValueParameterList() + + if (hasExplicitReturnType(element)) { + val childAfterParamList = oldParameterList?.getNextSibling() + val arrow = functionLiteral.getArrowNode()?.getPsi() + val childBeforeArrow = arrow?.getPrevSibling() + functionLiteral.deleteChildRange(childAfterParamList, childBeforeArrow) + val whiteSpaceBeforeArrow = JetPsiFactory.createWhiteSpace(element.getProject()) + functionLiteral.addBefore(whiteSpaceBeforeArrow, arrow) + } + + if (hasExplicitReceiverType(element)) { + val childAfterBrace = functionLiteral.getOpenBraceNode().getPsi()?.getNextSibling() + val childBeforeParamList = oldParameterList?.getPrevSibling() + functionLiteral.deleteChildRange(childAfterBrace, childBeforeParamList) + } + + if (oldParameterList?.getParameters() != null && hasExplicitParamType(element)) { + val parameterString = oldParameterList!!.getParameters().map({ parameter -> + parameter.getNameIdentifier()!!.getText() + }).makeString(", ", "(", ")") + val newParameterList = JetPsiFactory.createParameterList(element.getProject(), parameterString) + oldParameterList.replace(newParameterList) + } + + if (!hasExplicitParamType(element)) { + val currentParamList = element.getFunctionLiteral().getValueParameterList() + val firstChild = currentParamList?.getFirstChild() + if (firstChild?.getNode()?.getElementType() == JetTokens.LPAR) firstChild!!.delete() + val lastChild = currentParamList?.getLastChild() + if (lastChild?.getNode()?.getElementType() == JetTokens.RPAR) lastChild!!.delete() + } + } + + private fun hasExplicitReturnType(element: JetFunctionLiteralExpression): Boolean { + return element.hasDeclaredReturnType() + } + + private fun hasExplicitReceiverType(element: JetFunctionLiteralExpression): Boolean { + return element.getFunctionLiteral().getReceiverTypeRef() != null + } + + private fun hasExplicitParamType(element: JetFunctionLiteralExpression): Boolean { + val parameters = element.getFunctionLiteral().getValueParameterList()?.getParameters() + if (parameters == null) return false + var hasExplicitParamType = false + for (param in parameters) { + if (param.getTypeReference() != null) hasExplicitParamType = true + if (param.getNameIdentifier()?.getText() == null) return false + } + return hasExplicitParamType + } +} \ No newline at end of file diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt b/idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt new file mode 100644 index 00000000000..77ab86a33fc --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt @@ -0,0 +1,9 @@ +public class TestingUse { + fun test5(coerced: (x: Int) -> Unit, a: Int): Unit { + return coerced(5) + } +} + +fun main() { + val coercion = TestingUse().test5({x -> x + 2}, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt.after new file mode 100644 index 00000000000..3dc869a39d6 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt.after @@ -0,0 +1,9 @@ +public class TestingUse { + fun test5(coerced: (x: Int) -> Unit, a: Int): Unit { + return coerced(5) + } +} + +fun main() { + val coercion = TestingUse().test5({(x: Int): Unit -> x + 2}, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithBrackets.kt b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithBrackets.kt new file mode 100644 index 00000000000..dd23b95a1f5 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithBrackets.kt @@ -0,0 +1,4 @@ +// IS_APPLICABLE: false +fun main() { + val x = {(): Unit -> } +} \ No newline at end of file diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt new file mode 100644 index 00000000000..a6379437116 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt @@ -0,0 +1,9 @@ +class TestingUse { + fun test3(double: (a: Int) -> Int, b: Int): Int { + return double(b) + } +} + +fun main() { + val num = TestingUse().test3({it * 2}, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt.after new file mode 100644 index 00000000000..f5580763244 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt.after @@ -0,0 +1,9 @@ +class TestingUse { + fun test3(double: (a: Int) -> Int, b: Int): Int { + return double(b) + } +} + +fun main() { + val num = TestingUse().test3({(it: Int): Int -> it * 2}, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt new file mode 100644 index 00000000000..76aefb9b44e --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt @@ -0,0 +1,5 @@ +fun main() { + val oom: (Int)->Int = { + it * 2 + } +} \ No newline at end of file diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt.after new file mode 100644 index 00000000000..d9f347f4472 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt.after @@ -0,0 +1,6 @@ +fun main() { + val oom: (Int)->Int = { + (it: Int): Int -> + it * 2 + } +} \ No newline at end of file diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt new file mode 100644 index 00000000000..e6f6b454919 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt @@ -0,0 +1,3 @@ +fun main() { + val oom = { -> 42} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt.after new file mode 100644 index 00000000000..9f6582965d4 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt.after @@ -0,0 +1,3 @@ +fun main() { + val oom = {(): Int -> 42} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/invalidCursorPosition.kt b/idea/testData/intentions/makeTypeExplicitInLambda/invalidCursorPosition.kt new file mode 100644 index 00000000000..098ae20fd93 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/invalidCursorPosition.kt @@ -0,0 +1,4 @@ +// IS_APPLICABLE: false +fun main() { + val sum : (Int, Int) -> Int = { (x, y) -> x + y } +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt b/idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt new file mode 100644 index 00000000000..f75d0ebc644 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt @@ -0,0 +1,8 @@ +public class TestingUse { + fun test6(funcLitfunc: ((x: Int) -> Int) -> Boolean, innerfunc: (y: Int) -> Int): Unit { + } +} + +fun main() { + val funcInfunc = TestingUse().test6({f -> f(5) > 20}, {x -> x + 2}) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt.after new file mode 100644 index 00000000000..217c9afeae6 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt.after @@ -0,0 +1,8 @@ +public class TestingUse { + fun test6(funcLitfunc: ((x: Int) -> Int) -> Boolean, innerfunc: (y: Int) -> Int): Unit { + } +} + +fun main() { + val funcInfunc = TestingUse().test6({(f: (Int) -> Int): Boolean -> f(5) > 20}, {x -> x + 2}) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt b/idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt new file mode 100644 index 00000000000..1d17dd27171 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt @@ -0,0 +1,8 @@ +val foo: (Long) -> String = { + + + + + + it.toString() +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt.after new file mode 100644 index 00000000000..38f3bf3f09b --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt.after @@ -0,0 +1,6 @@ +val foo: (Long) -> String = { + (it: Long): String -> + + + it.toString() +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt b/idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt new file mode 100644 index 00000000000..45880decb20 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt @@ -0,0 +1,10 @@ +class TestingUse { + fun test4(printNum: (a: Int, b: String) -> Unit, c: Int): Int { + printNum(c, "This number is") + return c + } +} + +fun main() { + val num = TestingUse().test4({(x, str) -> }, 5) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt.after new file mode 100644 index 00000000000..983d8a2ca41 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt.after @@ -0,0 +1,10 @@ +class TestingUse { + fun test4(printNum: (a: Int, b: String) -> Unit, c: Int): Int { + printNum(c, "This number is") + return c + } +} + +fun main() { + val num = TestingUse().test4({(x: Int, str: String): Unit -> }, 5) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt b/idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt new file mode 100644 index 00000000000..5e6a7954e0c --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt @@ -0,0 +1,3 @@ +fun main() { + val foo: (Int) -> String = {(x: Int) -> "This number is " + x} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt.after new file mode 100644 index 00000000000..1b3c48ff2d6 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt.after @@ -0,0 +1,3 @@ +fun main() { + val foo: (Int) -> String = {(x: Int): String -> "This number is " + x} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt b/idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt new file mode 100644 index 00000000000..7eb8aaf1983 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt @@ -0,0 +1,3 @@ +fun main() { + val bar: (Array) -> Int = {(arr): Int -> arr.size} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt.after new file mode 100644 index 00000000000..ee4ad36e41b --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt.after @@ -0,0 +1,3 @@ +fun main() { + val bar: (Array) -> Int = {(arr: Array): Int -> arr.size} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt new file mode 100644 index 00000000000..b16d8e7824a --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt @@ -0,0 +1,3 @@ +fun main() { + val randomFunction: (x: kotlin.Int, y: kotlin.String) -> kotlin.Int = {(x, str) -> x} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt.after new file mode 100644 index 00000000000..ee12c5ed77f --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt.after @@ -0,0 +1,3 @@ +fun main() { + val randomFunction: (x: kotlin.Int, y: kotlin.String) -> kotlin.Int = {(x: Int, str: String): Int -> x} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt new file mode 100644 index 00000000000..14a679ef767 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt @@ -0,0 +1,3 @@ +fun main() { + val randomFunction: kotlin.Array.(x: Int) -> Boolean = {y -> if (this[0] < y) true else false} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt.after new file mode 100644 index 00000000000..78ce2a70c15 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt.after @@ -0,0 +1,3 @@ +fun main() { + val randomFunction: kotlin.Array.(x: Int) -> Boolean = { Array.(y: Int): Boolean -> if (this[0] < y) true else false} +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt b/idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt new file mode 100644 index 00000000000..fe77c3a7615 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt @@ -0,0 +1,9 @@ +class TestingUse { + fun test3(double: (a: Int) -> Int, b: Int): Int { + return double(b) + } +} + +fun main() { + val num = TestingUse().test3({x -> 2*x}, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt.after new file mode 100644 index 00000000000..9de39b39c6b --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt.after @@ -0,0 +1,9 @@ +class TestingUse { + fun test3(double: (a: Int) -> Int, b: Int): Int { + return double(b) + } +} + +fun main() { + val num = TestingUse().test3({(x: Int): Int -> 2*x}, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt b/idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt new file mode 100644 index 00000000000..e3d74a97d33 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt @@ -0,0 +1,9 @@ +class TestingUse { + fun test(sum: Int.(a: Int) -> Int, b: Int): Int { + return b.sum(b) + } +} + +fun main() { + val num = TestingUse().test({ x -> x + 2 }, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt.after b/idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt.after new file mode 100644 index 00000000000..81cebbe7ce7 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt.after @@ -0,0 +1,9 @@ +class TestingUse { + fun test(sum: Int.(a: Int) -> Int, b: Int): Int { + return b.sum(b) + } +} + +fun main() { + val num = TestingUse().test({ Int.(x: Int): Int -> x + 2 }, 20) +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/typesAlreadyExplicit.kt b/idea/testData/intentions/makeTypeExplicitInLambda/typesAlreadyExplicit.kt new file mode 100644 index 00000000000..39895a0de09 --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/typesAlreadyExplicit.kt @@ -0,0 +1,4 @@ +// IS_APPLICABLE: false +fun main() { + val sum = { Int.(x: Int, y: Int) : Int -> x + y } +} diff --git a/idea/testData/intentions/makeTypeExplicitInLambda/typesNotInferable.kt b/idea/testData/intentions/makeTypeExplicitInLambda/typesNotInferable.kt new file mode 100644 index 00000000000..95bfc2e074e --- /dev/null +++ b/idea/testData/intentions/makeTypeExplicitInLambda/typesNotInferable.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +// ERROR: Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) -> ...} notation +// ERROR: Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) -> ...} notation +fun main() { + val sum = { (x, y) -> x + y // Type of x and y cannot be inferred, so intention can't be used +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt new file mode 100644 index 00000000000..7d143d8eb18 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt @@ -0,0 +1,9 @@ +public class TestingUse { + fun test(sum: Int.(a: Int) -> Int, b: Int): Int { + return b.sum(b) + } +} + +fun main() { + val num = TestingUse().test({ Int.(x: Int): Int -> x + 2 }, 20) +} \ No newline at end of file diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt.after b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt.after new file mode 100644 index 00000000000..a98cfa2f954 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt.after @@ -0,0 +1,9 @@ +public class TestingUse { + fun test(sum: Int.(a: Int) -> Int, b: Int): Int { + return b.sum(b) + } +} + +fun main() { + val num = TestingUse().test({ x -> x + 2 }, 20) +} \ No newline at end of file diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt new file mode 100644 index 00000000000..ebc5bb8a3f4 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt @@ -0,0 +1,3 @@ +fun main() { + val sum = { (x: Int, y: Int): Int -> x + y } +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt.after b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt.after new file mode 100644 index 00000000000..f40b050385f --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt.after @@ -0,0 +1,3 @@ +fun main() { + val sum = { x, y -> x + y } +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/invalidCursorPosition.kt b/idea/testData/intentions/makeTypeImplicitInLambda/invalidCursorPosition.kt new file mode 100644 index 00000000000..8d8ab10de0a --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/invalidCursorPosition.kt @@ -0,0 +1,4 @@ +// IS_APPLICABLE: false +fun main() { + val sum = { (x: Int, y: Int) -> x + y } +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt b/idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt new file mode 100644 index 00000000000..4eeb70c0333 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt @@ -0,0 +1,8 @@ +public class TestingUse { + fun test6(funcLitfunc: ((x: Int) -> Int) -> Boolean, innerfunc: (y: Int) -> Int): Unit { + } +} + +fun main() { + val funcInfunc = TestingUse().test6({(f: (Int) -> Int): Boolean -> f(5) > 20}, {x -> x + 2}) +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt.after b/idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt.after new file mode 100644 index 00000000000..42d2af38748 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt.after @@ -0,0 +1,8 @@ +public class TestingUse { + fun test6(funcLitfunc: ((x: Int) -> Int) -> Boolean, innerfunc: (y: Int) -> Int): Unit { + } +} + +fun main() { + val funcInfunc = TestingUse().test6({ f -> f(5) > 20}, {x -> x + 2}) +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt b/idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt new file mode 100644 index 00000000000..128bdc826ee --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt @@ -0,0 +1,3 @@ +fun main() { + val f = { (x: Int, str: String): Unit -> x } +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt.after b/idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt.after new file mode 100644 index 00000000000..9ce73c99ad8 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt.after @@ -0,0 +1,3 @@ +fun main() { + val f = { x, str -> x } +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt b/idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt new file mode 100644 index 00000000000..5e6a7954e0c --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt @@ -0,0 +1,3 @@ +fun main() { + val foo: (Int) -> String = {(x: Int) -> "This number is " + x} +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt.after b/idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt.after new file mode 100644 index 00000000000..32fdef9de82 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt.after @@ -0,0 +1,3 @@ +fun main() { + val foo: (Int) -> String = { x -> "This number is " + x} +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt b/idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt new file mode 100644 index 00000000000..7eb8aaf1983 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt @@ -0,0 +1,3 @@ +fun main() { + val bar: (Array) -> Int = {(arr): Int -> arr.size} +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt.after b/idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt.after new file mode 100644 index 00000000000..74fac9eb76e --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt.after @@ -0,0 +1,3 @@ +fun main() { + val bar: (Array) -> Int = { arr -> arr.size} +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt b/idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt new file mode 100644 index 00000000000..cfd7e850334 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt @@ -0,0 +1,3 @@ +fun main() { + val double = { (x: Int) -> x * 2 } +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt.after b/idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt.after new file mode 100644 index 00000000000..ac06bf394f1 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt.after @@ -0,0 +1,3 @@ +fun main() { + val double = { x -> x * 2 } +} diff --git a/idea/testData/intentions/makeTypeImplicitInLambda/typesAlreadyImplicit.kt b/idea/testData/intentions/makeTypeImplicitInLambda/typesAlreadyImplicit.kt new file mode 100644 index 00000000000..9a0731949b6 --- /dev/null +++ b/idea/testData/intentions/makeTypeImplicitInLambda/typesAlreadyImplicit.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false +fun testing(x: Int, y: Int, f: (a: Int, b: Int) -> Int): Int { + return f(x, y) +} + +fun main() { + val num = testing(1, 2, { x, y -> x + y }) +} diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt index 93fa7ca8565..2c275e6185b 100644 --- a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt @@ -1,6 +1,10 @@ // "Change 'foo' function return type to '([ERROR : NoSuchType]) -> Int'" "false" +// ACTION: Disable 'Make Types Implicit In Lambda (May Break Code)' +// ACTION: Edit intention settings +// ACTION: Make types implicit in lambda (may break code) // ERROR: Type mismatch.
Required:kotlin.Int
Found:([ERROR : NoSuchType]) → kotlin.Int
// ERROR: Unresolved reference: NoSuchType + fun foo(): Int { return { (x: NoSuchType) -> 42 } } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java index e70b46da936..458ddedec88 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java @@ -258,6 +258,14 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes doTestIntention(path, new SimplifyBooleanWithConstantsIntention()); } + public void doTestMakeTypeExplicitInLambda(@NotNull String path) throws Exception { + doTestIntention(path, new MakeTypeExplicitInLambdaIntention()); + } + + public void doTestMakeTypeImplicitInLambda(@NotNull String path) throws Exception { + doTestIntention(path, new MakeTypeImplicitInLambdaIntention()); + } + private void doTestIntention(@NotNull String path, @NotNull IntentionAction intentionAction) throws Exception { configureByFile(path); diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java index 305e814ef0a..32b7f8ddc86 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java @@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@InnerTestClasses({CodeTransformationTestGenerated.DoubleBangToIfThen.class, CodeTransformationTestGenerated.IfThenToDoubleBang.class, CodeTransformationTestGenerated.ElvisToIfThen.class, CodeTransformationTestGenerated.IfThenToElvis.class, CodeTransformationTestGenerated.SafeAccessToIfThen.class, CodeTransformationTestGenerated.IfThenToSafeAccess.class, CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class, CodeTransformationTestGenerated.RemoveBraces.class, CodeTransformationTestGenerated.AddBraces.class, CodeTransformationTestGenerated.ReplaceGetIntention.class, CodeTransformationTestGenerated.ReplaceContainsIntention.class, CodeTransformationTestGenerated.ReplaceBinaryInfixIntention.class, CodeTransformationTestGenerated.ReplaceUnaryPrefixIntention.class, CodeTransformationTestGenerated.ReplaceInvokeIntention.class, CodeTransformationTestGenerated.SimplifyNegatedBinaryExpressionIntention.class, CodeTransformationTestGenerated.ConvertNegatedBooleanSequence.class, CodeTransformationTestGenerated.ConvertNegatedExpressionWithDemorgansLaw.class, CodeTransformationTestGenerated.SwapBinaryExpression.class, CodeTransformationTestGenerated.SplitIf.class, CodeTransformationTestGenerated.ReplaceWithOperatorAssign.class, CodeTransformationTestGenerated.ReplaceWithTraditionalAssignment.class, CodeTransformationTestGenerated.SimplifyBooleanWithConstants.class, CodeTransformationTestGenerated.InsertExplicitTypeArguments.class, CodeTransformationTestGenerated.RemoveExplicitTypeArguments.class, CodeTransformationTestGenerated.ConvertAssertToIf.class, CodeTransformationTestGenerated.ConvertIfToAssert.class}) +@InnerTestClasses({CodeTransformationTestGenerated.DoubleBangToIfThen.class, CodeTransformationTestGenerated.IfThenToDoubleBang.class, CodeTransformationTestGenerated.ElvisToIfThen.class, CodeTransformationTestGenerated.IfThenToElvis.class, CodeTransformationTestGenerated.SafeAccessToIfThen.class, CodeTransformationTestGenerated.IfThenToSafeAccess.class, CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class, CodeTransformationTestGenerated.RemoveBraces.class, CodeTransformationTestGenerated.AddBraces.class, CodeTransformationTestGenerated.ReplaceGetIntention.class, CodeTransformationTestGenerated.ReplaceContainsIntention.class, CodeTransformationTestGenerated.ReplaceBinaryInfixIntention.class, CodeTransformationTestGenerated.ReplaceUnaryPrefixIntention.class, CodeTransformationTestGenerated.ReplaceInvokeIntention.class, CodeTransformationTestGenerated.SimplifyNegatedBinaryExpressionIntention.class, CodeTransformationTestGenerated.ConvertNegatedBooleanSequence.class, CodeTransformationTestGenerated.ConvertNegatedExpressionWithDemorgansLaw.class, CodeTransformationTestGenerated.SwapBinaryExpression.class, CodeTransformationTestGenerated.SplitIf.class, CodeTransformationTestGenerated.ReplaceWithOperatorAssign.class, CodeTransformationTestGenerated.ReplaceWithTraditionalAssignment.class, CodeTransformationTestGenerated.SimplifyBooleanWithConstants.class, CodeTransformationTestGenerated.InsertExplicitTypeArguments.class, CodeTransformationTestGenerated.RemoveExplicitTypeArguments.class, CodeTransformationTestGenerated.ConvertAssertToIf.class, CodeTransformationTestGenerated.ConvertIfToAssert.class, CodeTransformationTestGenerated.MakeTypeExplicitInLambda.class, CodeTransformationTestGenerated.MakeTypeImplicitInLambda.class}) public class CodeTransformationTestGenerated extends AbstractCodeTransformationTest { @TestMetadata("idea/testData/intentions/branched/doubleBangToIfThen") public static class DoubleBangToIfThen extends AbstractCodeTransformationTest { @@ -3957,6 +3957,152 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT } + @TestMetadata("idea/testData/intentions/makeTypeExplicitInLambda") + public static class MakeTypeExplicitInLambda extends AbstractCodeTransformationTest { + public void testAllFilesPresentInMakeTypeExplicitInLambda() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/makeTypeExplicitInLambda"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/coercionToUnit.kt"); + } + + @TestMetadata("emptyParamListWithBrackets.kt") + public void testEmptyParamListWithBrackets() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithBrackets.kt"); + } + + @TestMetadata("emptyParamListWithIt.kt") + public void testEmptyParamListWithIt() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithIt.kt"); + } + + @TestMetadata("emptyParamListWithWhiteSpace.kt") + public void testEmptyParamListWithWhiteSpace() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithWhiteSpace.kt"); + } + + @TestMetadata("emptyParamListWithoutItWithArrow.kt") + public void testEmptyParamListWithoutItWithArrow() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/emptyParamListWithoutItWithArrow.kt"); + } + + @TestMetadata("invalidCursorPosition.kt") + public void testInvalidCursorPosition() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/invalidCursorPosition.kt"); + } + + @TestMetadata("lambdaWithLambdaAsParam.kt") + public void testLambdaWithLambdaAsParam() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/lambdaWithLambdaAsParam.kt"); + } + + @TestMetadata("manyNewlines.kt") + public void testManyNewlines() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/manyNewlines.kt"); + } + + @TestMetadata("multipleParam.kt") + public void testMultipleParam() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/multipleParam.kt"); + } + + @TestMetadata("paramDeclaredReturnNotDeclared.kt") + public void testParamDeclaredReturnNotDeclared() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/paramDeclaredReturnNotDeclared.kt"); + } + + @TestMetadata("returnDeclaredParamNotDeclared.kt") + public void testReturnDeclaredParamNotDeclared() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/returnDeclaredParamNotDeclared.kt"); + } + + @TestMetadata("shortenReferencesForParams.kt") + public void testShortenReferencesForParams() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForParams.kt"); + } + + @TestMetadata("shortenReferencesForReceiver.kt") + public void testShortenReferencesForReceiver() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/shortenReferencesForReceiver.kt"); + } + + @TestMetadata("singleParam.kt") + public void testSingleParam() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/singleParam.kt"); + } + + @TestMetadata("singleParamWithReceiver.kt") + public void testSingleParamWithReceiver() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/singleParamWithReceiver.kt"); + } + + @TestMetadata("typesAlreadyExplicit.kt") + public void testTypesAlreadyExplicit() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/typesAlreadyExplicit.kt"); + } + + @TestMetadata("typesNotInferable.kt") + public void testTypesNotInferable() throws Exception { + doTestMakeTypeExplicitInLambda("idea/testData/intentions/makeTypeExplicitInLambda/typesNotInferable.kt"); + } + + } + + @TestMetadata("idea/testData/intentions/makeTypeImplicitInLambda") + public static class MakeTypeImplicitInLambda extends AbstractCodeTransformationTest { + public void testAllFilesPresentInMakeTypeImplicitInLambda() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/makeTypeImplicitInLambda"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("explicitReceiverType.kt") + public void testExplicitReceiverType() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/explicitReceiverType.kt"); + } + + @TestMetadata("explicitReturnType.kt") + public void testExplicitReturnType() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/explicitReturnType.kt"); + } + + @TestMetadata("invalidCursorPosition.kt") + public void testInvalidCursorPosition() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/invalidCursorPosition.kt"); + } + + @TestMetadata("lambdaWithLambdaAsParam.kt") + public void testLambdaWithLambdaAsParam() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/lambdaWithLambdaAsParam.kt"); + } + + @TestMetadata("multipleExplicitParams.kt") + public void testMultipleExplicitParams() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/multipleExplicitParams.kt"); + } + + @TestMetadata("paramDeclaredReturnNotDeclared.kt") + public void testParamDeclaredReturnNotDeclared() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/paramDeclaredReturnNotDeclared.kt"); + } + + @TestMetadata("returnDeclaredParamNotDeclared.kt") + public void testReturnDeclaredParamNotDeclared() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/returnDeclaredParamNotDeclared.kt"); + } + + @TestMetadata("singleExplicitParam.kt") + public void testSingleExplicitParam() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/singleExplicitParam.kt"); + } + + @TestMetadata("typesAlreadyImplicit.kt") + public void testTypesAlreadyImplicit() throws Exception { + doTestMakeTypeImplicitInLambda("idea/testData/intentions/makeTypeImplicitInLambda/typesAlreadyImplicit.kt"); + } + + } + public static Test suite() { TestSuite suite = new TestSuite("CodeTransformationTestGenerated"); suite.addTestSuite(DoubleBangToIfThen.class); @@ -4013,6 +4159,8 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT suite.addTestSuite(RemoveExplicitTypeArguments.class); suite.addTestSuite(ConvertAssertToIf.class); suite.addTestSuite(ConvertIfToAssert.class); + suite.addTestSuite(MakeTypeExplicitInLambda.class); + suite.addTestSuite(MakeTypeImplicitInLambda.class); return suite; } }