diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 87708b65580..cf8b6e8726b 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -3187,6 +3187,15 @@ language="kotlin" /> + + diff --git a/idea/resources/inspectionDescriptions/FunctionWithLambdaExpressionBody.html b/idea/resources/inspectionDescriptions/FunctionWithLambdaExpressionBody.html new file mode 100644 index 00000000000..2452c76e334 --- /dev/null +++ b/idea/resources/inspectionDescriptions/FunctionWithLambdaExpressionBody.html @@ -0,0 +1,10 @@ + + +This inspection reports function with `= { ... }` and inferred return type. + +
+fun sum(a: Int, b: Int) = { a + b } // The return type of this function is '() -> Int'.
+
+ + + \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/FunctionWithLambdaExpressionBodyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/FunctionWithLambdaExpressionBodyInspection.kt new file mode 100644 index 00000000000..eb419b0241a --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/FunctionWithLambdaExpressionBodyInspection.kt @@ -0,0 +1,99 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.inspections + +import com.intellij.codeInspection.* +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiComment +import com.intellij.psi.PsiElement +import com.intellij.psi.search.searches.ReferencesSearch +import com.intellij.psi.util.parentOfType +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny +import org.jetbrains.kotlin.idea.core.replaced +import org.jetbrains.kotlin.idea.core.setType +import org.jetbrains.kotlin.idea.intentions.SpecifyExplicitLambdaSignatureIntention +import org.jetbrains.kotlin.idea.quickfix.SpecifyTypeExplicitlyFix +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.allChildren +import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType +import org.jetbrains.kotlin.types.typeUtil.isNothing + +class FunctionWithLambdaExpressionBodyInspection : AbstractKotlinInspection() { + + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = object : KtVisitorVoid() { + override fun visitNamedFunction(function: KtNamedFunction) { + check(function) + } + + override fun visitPropertyAccessor(accessor: KtPropertyAccessor) { + if (accessor.isSetter) return + if (accessor.returnTypeReference != null) return + check(accessor) + } + + private fun check(element: KtDeclarationWithBody) { + val callableDeclaration = element.getNonStrictParentOfType() ?: return + if (callableDeclaration.typeReference != null) return + val lambda = element.bodyExpression as? KtLambdaExpression ?: return + val functionLiteral = lambda.functionLiteral + if (functionLiteral.arrow != null || functionLiteral.valueParameterList != null) return + val lambdaBody = functionLiteral.bodyBlockExpression ?: return + + val file = element.containingKtFile + val used = ReferencesSearch.search(callableDeclaration).any() + val fixes = listOfNotNull( + IntentionWrapper(SpecifyTypeExplicitlyFix(), file), + IntentionWrapper(AddArrowIntention(), file), + if (!used && lambdaBody.statements.size == 1 && lambdaBody.allChildren.none { it is PsiComment }) RemoveBracesFix() else null, + if (!used) WrapRunFix() else null + ) + holder.registerProblem( + lambda, + "Function with `= { ... }` and inferred return type", + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, + *fixes.toTypedArray() + ) + } + } + + private class AddArrowIntention : SpecifyExplicitLambdaSignatureIntention() { + override fun allowCaretInsideElement(element: PsiElement) = true + } + + private class RemoveBracesFix : LocalQuickFix { + override fun getName() = "Remove braces" + + override fun getFamilyName() = name + + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + val lambda = descriptor.psiElement as? KtLambdaExpression ?: return + val body = lambda.functionLiteral.bodyExpression ?: return + val replaced = lambda.replaced(body) + replaced.parentOfType()?.setTypeIfNeed() + } + } + + private class WrapRunFix : LocalQuickFix { + override fun getName() = "Convert to run { ... }" + + override fun getFamilyName() = name + + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + val lambda = descriptor.psiElement as? KtLambdaExpression ?: return + val body = lambda.functionLiteral.bodyExpression ?: return + val replaced = lambda.replaced(KtPsiFactory(lambda).createExpressionByPattern("run { $0 }", body)) + replaced.parentOfType()?.setTypeIfNeed() + } + } +} + +private fun KtCallableDeclaration.setTypeIfNeed() { + val type = (resolveToDescriptorIfAny() as? CallableDescriptor)?.returnType + if (type?.isNothing() == true) { + this.setType(type) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt index 776ec330407..1f58db68b12 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.isError -class SpecifyExplicitLambdaSignatureIntention : SelfTargetingOffsetIndependentIntention( +open class SpecifyExplicitLambdaSignatureIntention : SelfTargetingOffsetIndependentIntention( KtLambdaExpression::class.java, "Specify explicit lambda signature" ), LowPriorityAction { diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/.inspection b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/.inspection new file mode 100644 index 00000000000..5a7c6dbd731 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/function.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/function.kt new file mode 100644 index 00000000000..f0d0d8b8fc1 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/function.kt @@ -0,0 +1,2 @@ +// FIX: Specify explicit lambda signature +fun test(a: Int, b: Int) = { a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/function.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/function.kt.after new file mode 100644 index 00000000000..5b94cceb4a2 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/function.kt.after @@ -0,0 +1,2 @@ +// FIX: Specify explicit lambda signature +fun test(a: Int, b: Int) = { -> a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/getter.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/getter.kt new file mode 100644 index 00000000000..dca400de52a --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/getter.kt @@ -0,0 +1,2 @@ +// FIX: Specify explicit lambda signature +val test get() = { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/getter.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/getter.kt.after new file mode 100644 index 00000000000..74f51fca443 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/getter.kt.after @@ -0,0 +1,2 @@ +// FIX: Specify explicit lambda signature +val test get() = { -> "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasArrow.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasArrow.kt new file mode 100644 index 00000000000..6e39667e67e --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasArrow.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +fun test(a: Int, b: Int) = { -> a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasLabel.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasLabel.kt new file mode 100644 index 00000000000..c2d05a7d2d9 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasLabel.kt @@ -0,0 +1,4 @@ +// PROBLEM: none +fun test(a: Int, b: Int) = label@{ + return@label +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoExpressionBody.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoExpressionBody.kt new file mode 100644 index 00000000000..17e43a56268 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoExpressionBody.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +fun test(a: Int, b: Int) { { a + b } } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoLambda.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoLambda.kt new file mode 100644 index 00000000000..d1dfc3c3b6d --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoLambda.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +fun test(a: Int, b: Int) = a + b \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasType.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasType.kt new file mode 100644 index 00000000000..34fe3ff55a1 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasType.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +fun test(a: Int, b: Int): () -> Int = { a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasArrow.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasArrow.kt new file mode 100644 index 00000000000..52b77e752ba --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasArrow.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +val test get() = { -> "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasLabel.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasLabel.kt new file mode 100644 index 00000000000..ebedb9f48c3 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasLabel.kt @@ -0,0 +1,5 @@ +// PROBLEM: none +val test + get() = label@{ + return@label + } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasNoLambda.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasNoLambda.kt new file mode 100644 index 00000000000..6bd35f9825f --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasNoLambda.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +val test get() = "" \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType.kt new file mode 100644 index 00000000000..9e7c9ab3194 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +val test: () -> String get() = { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType2.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType2.kt new file mode 100644 index 00000000000..f2321fd3b69 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType2.kt @@ -0,0 +1,2 @@ +// PROBLEM: none +val test get(): () -> String = { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/function.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/function.kt new file mode 100644 index 00000000000..6a97efb8be5 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/function.kt @@ -0,0 +1,2 @@ +// FIX: Remove braces +fun test(a: Int, b: Int) = { a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/function.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/function.kt.after new file mode 100644 index 00000000000..15a37063484 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/function.kt.after @@ -0,0 +1,2 @@ +// FIX: Remove braces +fun test(a: Int, b: Int) = a + b \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/functionReturnsNothing.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/functionReturnsNothing.kt new file mode 100644 index 00000000000..20c34be2446 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/functionReturnsNothing.kt @@ -0,0 +1,3 @@ +// FIX: Remove braces +// WITH_RUNTIME +fun test() = { error("") } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/functionReturnsNothing.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/functionReturnsNothing.kt.after new file mode 100644 index 00000000000..53a9163d638 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/functionReturnsNothing.kt.after @@ -0,0 +1,3 @@ +// FIX: Remove braces +// WITH_RUNTIME +fun test(): Nothing = error("") \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getter.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getter.kt new file mode 100644 index 00000000000..886d0265a3c --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getter.kt @@ -0,0 +1,2 @@ +// FIX: Remove braces +val test get() = { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getter.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getter.kt.after new file mode 100644 index 00000000000..b74d53f1044 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getter.kt.after @@ -0,0 +1,2 @@ +// FIX: Remove braces +val test get() = "" \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getterReturnsNothing.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getterReturnsNothing.kt new file mode 100644 index 00000000000..5f549836006 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getterReturnsNothing.kt @@ -0,0 +1,3 @@ +// FIX: Remove braces +// WITH_RUNTIME +val test get() = { error("") } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getterReturnsNothing.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getterReturnsNothing.kt.after new file mode 100644 index 00000000000..f2ff2be1358 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getterReturnsNothing.kt.after @@ -0,0 +1,3 @@ +// FIX: Remove braces +// WITH_RUNTIME +val test: Nothing get() = error("") \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/function.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/function.kt new file mode 100644 index 00000000000..3f3a7541e93 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/function.kt @@ -0,0 +1,2 @@ +// FIX: Specify return type explicitly +fun test(a: Int, b: Int) = { a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/function.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/function.kt.after new file mode 100644 index 00000000000..ebbbcd59ba1 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/function.kt.after @@ -0,0 +1,2 @@ +// FIX: Specify return type explicitly +fun test(a: Int, b: Int): () -> Int = { a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/getter.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/getter.kt new file mode 100644 index 00000000000..780066a62f8 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/getter.kt @@ -0,0 +1,2 @@ +// FIX: Specify type explicitly +val test get() = { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/getter.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/getter.kt.after new file mode 100644 index 00000000000..b34fa461c23 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/getter.kt.after @@ -0,0 +1,2 @@ +// FIX: Specify type explicitly +val test: () -> String get() = { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/function.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/function.kt new file mode 100644 index 00000000000..ce328ebc6fa --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/function.kt @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +fun test(a: Int, b: Int) = { a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/function.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/function.kt.after new file mode 100644 index 00000000000..299086a5ab3 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/function.kt.after @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +fun test(a: Int, b: Int) = run { a + b } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/functionReturnsNothing.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/functionReturnsNothing.kt new file mode 100644 index 00000000000..ad620badc9f --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/functionReturnsNothing.kt @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +fun test() = { error("") } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/functionReturnsNothing.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/functionReturnsNothing.kt.after new file mode 100644 index 00000000000..69b5b6ed18f --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/functionReturnsNothing.kt.after @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +fun test(): Nothing = run { error("") } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getter.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getter.kt new file mode 100644 index 00000000000..a246f39cb26 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getter.kt @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +val test get() = { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getter.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getter.kt.after new file mode 100644 index 00000000000..39cf5c4f2e7 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getter.kt.after @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +val test get() = run { "" } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getterReturnsNothing.kt b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getterReturnsNothing.kt new file mode 100644 index 00000000000..793613dba23 --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getterReturnsNothing.kt @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +val test get() = { error("") } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getterReturnsNothing.kt.after b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getterReturnsNothing.kt.after new file mode 100644 index 00000000000..4af22d6bded --- /dev/null +++ b/idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getterReturnsNothing.kt.after @@ -0,0 +1,3 @@ +// FIX: Convert to run { ... } +// WITH_RUNTIME +val test: Nothing get() = run { error("") } \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt new file mode 100644 index 00000000000..a8d319106ae --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt @@ -0,0 +1,11 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert to block body +// ACTION: Convert to run { ... } +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify return type explicitly +fun test(a: Int, b: Int) = { + // comment + "" +} \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt new file mode 100644 index 00000000000..7bab8afb6ec --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt @@ -0,0 +1,13 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert to block body +// ACTION: Convert to run { ... } +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify return type explicitly +fun test(a: Int, b: Int) = { + foo() + foo() +} + +fun foo() {} \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt new file mode 100644 index 00000000000..8e158f8dfe2 --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt @@ -0,0 +1,8 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert to block body +// ACTION: Convert to run { ... } +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify return type explicitly +fun test(a: Int, b: Int) = {} \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt new file mode 100644 index 00000000000..a40112995dd --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt @@ -0,0 +1,9 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert to block body +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify return type explicitly +fun test(a: Int, b: Int) = { a + b } + +val foo = test(1, 2)() \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt new file mode 100644 index 00000000000..145160599b7 --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt @@ -0,0 +1,13 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert property getter to initializer +// ACTION: Convert to block body +// ACTION: Convert to run { ... } +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify type explicitly +// ACTION: Specify type explicitly +val test get() = { + // comment + "" +} \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt new file mode 100644 index 00000000000..c84705689f3 --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt @@ -0,0 +1,15 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert property getter to initializer +// ACTION: Convert to block body +// ACTION: Convert to run { ... } +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify type explicitly +// ACTION: Specify type explicitly +val test get() = { + foo() + foo() +} + +fun foo() {} \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt new file mode 100644 index 00000000000..b1c92bea6ac --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt @@ -0,0 +1,10 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert property getter to initializer +// ACTION: Convert to block body +// ACTION: Convert to run { ... } +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify type explicitly +// ACTION: Specify type explicitly +val test get() = {} \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt new file mode 100644 index 00000000000..3c0ae2c5f78 --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt @@ -0,0 +1,13 @@ +// "Remove braces" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert property getter to initializer +// ACTION: Convert to block body +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify type explicitly +// ACTION: Specify type explicitly +val test get() = { "" } + +fun foo() { + test() +} \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt new file mode 100644 index 00000000000..d394cb96182 --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt @@ -0,0 +1,9 @@ +// "Convert to run { ... }" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert to block body +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify return type explicitly +fun test(a: Int, b: Int) = { a + b } + +val foo = test(1, 2)() \ No newline at end of file diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt new file mode 100644 index 00000000000..d37008faa46 --- /dev/null +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt @@ -0,0 +1,13 @@ +// "Convert to run { ... }" "false" +// TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection +// ACTION: Convert property getter to initializer +// ACTION: Convert to block body +// ACTION: Specify explicit lambda signature +// ACTION: Specify explicit lambda signature +// ACTION: Specify type explicitly +// ACTION: Specify type explicitly +val test get() = { "" } + +fun foo() { + test() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 2615d9b50c8..dba90af24c9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -2810,6 +2810,181 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FunctionWithLambdaExpressionBody extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInFunctionWithLambdaExpressionBody() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("functionHasArrow.kt") + public void testFunctionHasArrow() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasArrow.kt"); + } + + @TestMetadata("functionHasLabel.kt") + public void testFunctionHasLabel() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasLabel.kt"); + } + + @TestMetadata("functionHasNoExpressionBody.kt") + public void testFunctionHasNoExpressionBody() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoExpressionBody.kt"); + } + + @TestMetadata("functionHasNoLambda.kt") + public void testFunctionHasNoLambda() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasNoLambda.kt"); + } + + @TestMetadata("functionHasType.kt") + public void testFunctionHasType() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/functionHasType.kt"); + } + + @TestMetadata("getterHasArrow.kt") + public void testGetterHasArrow() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasArrow.kt"); + } + + @TestMetadata("getterHasLabel.kt") + public void testGetterHasLabel() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasLabel.kt"); + } + + @TestMetadata("getterHasNoLambda.kt") + public void testGetterHasNoLambda() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasNoLambda.kt"); + } + + @TestMetadata("getterHasType.kt") + public void testGetterHasType() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType.kt"); + } + + @TestMetadata("getterHasType2.kt") + public void testGetterHasType2() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/getterHasType2.kt"); + } + + @TestMetadata("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AddArrow extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAddArrow() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("function.kt") + public void testFunction() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/function.kt"); + } + + @TestMetadata("getter.kt") + public void testGetter() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/addArrow/getter.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveBraces extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRemoveBraces() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("function.kt") + public void testFunction() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/function.kt"); + } + + @TestMetadata("functionReturnsNothing.kt") + public void testFunctionReturnsNothing() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/functionReturnsNothing.kt"); + } + + @TestMetadata("getter.kt") + public void testGetter() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getter.kt"); + } + + @TestMetadata("getterReturnsNothing.kt") + public void testGetterReturnsNothing() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/removeBraces/getterReturnsNothing.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SpecifyType extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInSpecifyType() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("function.kt") + public void testFunction() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/function.kt"); + } + + @TestMetadata("getter.kt") + public void testGetter() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/specifyType/getter.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WrapRun extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWrapRun() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("function.kt") + public void testFunction() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/function.kt"); + } + + @TestMetadata("functionReturnsNothing.kt") + public void testFunctionReturnsNothing() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/functionReturnsNothing.kt"); + } + + @TestMetadata("getter.kt") + public void testGetter() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getter.kt"); + } + + @TestMetadata("getterReturnsNothing.kt") + public void testGetterReturnsNothing() throws Exception { + runTest("idea/testData/inspectionsLocal/functionWithLambdaExpressionBody/wrapRun/getterReturnsNothing.kt"); + } + } + } + @TestMetadata("idea/testData/inspectionsLocal/ImplicitNullableNothingType") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index 91de120b155..1498f1e8943 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -2685,6 +2685,45 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes } } + @TestMetadata("idea/testData/quickfix/functionWithLambdaExpressionBody") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FunctionWithLambdaExpressionBody extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInFunctionWithLambdaExpressionBody() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/functionWithLambdaExpressionBody"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + + @TestMetadata("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveBraces extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRemoveBraces() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + } + + @TestMetadata("idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WrapRun extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWrapRun() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + } + } + @TestMetadata("idea/testData/quickfix/implement") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 4ffb9e61f6d..2d41b135199 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -6775,6 +6775,95 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/functionWithLambdaExpressionBody") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FunctionWithLambdaExpressionBody extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInFunctionWithLambdaExpressionBody() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/functionWithLambdaExpressionBody"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveBraces extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRemoveBraces() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("functionHasComment.kt") + public void testFunctionHasComment() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt"); + } + + @TestMetadata("functionHasMultiStatements.kt") + public void testFunctionHasMultiStatements() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt"); + } + + @TestMetadata("functionHasNoStatement.kt") + public void testFunctionHasNoStatement() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt"); + } + + @TestMetadata("funtionIsUsed.kt") + public void testFuntionIsUsed() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt"); + } + + @TestMetadata("getterHasComment.kt") + public void testGetterHasComment() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt"); + } + + @TestMetadata("getterHasMultiStatements.kt") + public void testGetterHasMultiStatements() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt"); + } + + @TestMetadata("getterHasNoStatement.kt") + public void testGetterHasNoStatement() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt"); + } + + @TestMetadata("getterIsUsed.kt") + public void testGetterIsUsed() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt"); + } + } + + @TestMetadata("idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WrapRun extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInWrapRun() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("funtionIsUsed.kt") + public void testFuntionIsUsed() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt"); + } + + @TestMetadata("getterIsUsed.kt") + public void testGetterIsUsed() throws Exception { + runTest("idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt"); + } + } + } + @TestMetadata("idea/testData/quickfix/implement") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)