diff --git a/idea/resources/inspectionDescriptions/RedundantWith.html b/idea/resources/inspectionDescriptions/RedundantWith.html new file mode 100644 index 00000000000..197d06f2194 --- /dev/null +++ b/idea/resources/inspectionDescriptions/RedundantWith.html @@ -0,0 +1,5 @@ + + +This inspection reports a redundant with function call that don't access anything from the receiver. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index facef8ea4c8..d7f36c053d6 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -2944,6 +2944,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. language="kotlin" /> + + diff --git a/idea/src/META-INF/plugin.xml.172 b/idea/src/META-INF/plugin.xml.172 index 06a953a13bd..48db081be0c 100644 --- a/idea/src/META-INF/plugin.xml.172 +++ b/idea/src/META-INF/plugin.xml.172 @@ -2941,6 +2941,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. language="kotlin" /> + + diff --git a/idea/src/META-INF/plugin.xml.173 b/idea/src/META-INF/plugin.xml.173 index 86b0c9052c5..f7feb282dc7 100644 --- a/idea/src/META-INF/plugin.xml.173 +++ b/idea/src/META-INF/plugin.xml.173 @@ -2944,6 +2944,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. language="kotlin" /> + + diff --git a/idea/src/META-INF/plugin.xml.182 b/idea/src/META-INF/plugin.xml.182 index 9cd3d615c78..77fdde98ce1 100644 --- a/idea/src/META-INF/plugin.xml.182 +++ b/idea/src/META-INF/plugin.xml.182 @@ -2945,6 +2945,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. language="kotlin" /> + + diff --git a/idea/src/META-INF/plugin.xml.as31 b/idea/src/META-INF/plugin.xml.as31 index ced665e82e7..49bdc914a4a 100644 --- a/idea/src/META-INF/plugin.xml.as31 +++ b/idea/src/META-INF/plugin.xml.as31 @@ -2944,6 +2944,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. language="kotlin" /> + + diff --git a/idea/src/META-INF/plugin.xml.as32 b/idea/src/META-INF/plugin.xml.as32 index 3d5482fbbcb..03e6c7f9005 100644 --- a/idea/src/META-INF/plugin.xml.as32 +++ b/idea/src/META-INF/plugin.xml.as32 @@ -2944,6 +2944,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. language="kotlin" /> + + diff --git a/idea/src/META-INF/plugin.xml.as33 b/idea/src/META-INF/plugin.xml.as33 index edda657a83a..bdae3986f3e 100644 --- a/idea/src/META-INF/plugin.xml.as33 +++ b/idea/src/META-INF/plugin.xml.as33 @@ -2941,6 +2941,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. language="kotlin" /> + + diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantWithInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantWithInspection.kt new file mode 100644 index 00000000000..7b5b3012f4e --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantWithInspection.kt @@ -0,0 +1,108 @@ +/* + * 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.LocalQuickFix +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElementVisitor +import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.core.moveCaret +import org.jetbrains.kotlin.idea.core.replaced +import org.jetbrains.kotlin.idea.util.getThisReceiverOwner +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.startOffset +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe +import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode + +class RedundantWithInspection : AbstractKotlinInspection() { + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = + callExpressionVisitor(fun(callExpression) { + val callee = callExpression.calleeExpression ?: return + if (callee.text != "with") return + + val valueArguments = callExpression.valueArguments + if (valueArguments.size != 2) return + val receiver = valueArguments[0].getArgumentExpression() ?: return + val lambda = valueArguments[1].lambdaExpression() ?: return + val lambdaBody = lambda.bodyExpression ?: return + + val context = callExpression.analyze(BodyResolveMode.PARTIAL_WITH_CFA) + if (lambdaBody.statements.size > 1 && context[BindingContext.USED_AS_EXPRESSION, callExpression] == true) return + if (callExpression.getResolvedCall(context)?.resultingDescriptor?.fqNameSafe != FqName("kotlin.with")) return + + val lambdaDescriptor = context[BindingContext.FUNCTION, lambda.functionLiteral] ?: return + val lambdaExtensionReceiver = lambdaDescriptor.extensionReceiverParameter + var used = false + lambda.functionLiteral.acceptChildren(object : KtVisitorVoid() { + override fun visitKtElement(element: KtElement) { + if (used) return + element.acceptChildren(this) + + if (element is KtReturnExpression && element.getLabelName() == "with") { + used = true + return + } + + val resolvedCall = element.getResolvedCall(context) ?: return + if (isUsageOfReceiver(resolvedCall, context)) { + used = true + } else if (resolvedCall is VariableAsFunctionResolvedCall && isUsageOfReceiver(resolvedCall.variableCall, context)) { + used = true + } + } + + private fun isUsageOfReceiver(resolvedCall: ResolvedCall<*>, bindingContext: BindingContext): Boolean { + // As receiver of call + if (resolvedCall.dispatchReceiver.getThisReceiverOwner(bindingContext) == lambdaDescriptor || + resolvedCall.extensionReceiver.getThisReceiverOwner(bindingContext) == lambdaDescriptor + ) { + return true + } + // As explicit "this" + if (resolvedCall.candidateDescriptor == lambdaExtensionReceiver) { + return true + } + return false + } + }) + if (!used) { + val quickfix = when (receiver) { + is KtSimpleNameExpression, is KtStringTemplateExpression, is KtConstantExpression -> RemoveRedundantWithFix() + else -> null + } + holder.registerProblem( + callee, + "Redundant 'with' call", + ProblemHighlightType.LIKE_UNUSED_SYMBOL, + quickfix + ) + } + }) +} + +private fun KtValueArgument.lambdaExpression(): KtLambdaExpression? = + (this as? KtLambdaArgument)?.getLambdaExpression() ?: this.getArgumentExpression() as? KtLambdaExpression + +private class RemoveRedundantWithFix : LocalQuickFix { + override fun getName() = "Remove redundant 'with' call" + + override fun getFamilyName() = name + + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + val callExpression = descriptor.psiElement.parent as? KtCallExpression ?: return + val lambdaBody = callExpression.valueArguments.getOrNull(1)?.lambdaExpression()?.bodyExpression ?: return + val replaced = callExpression.replaced(lambdaBody) + replaced.findExistingEditor()?.moveCaret(replaced.startOffset) + } +} diff --git a/idea/testData/inspections/redundantWith/callReceiver.kt b/idea/testData/inspections/redundantWith/callReceiver.kt new file mode 100644 index 00000000000..fcfac0d2a87 --- /dev/null +++ b/idea/testData/inspections/redundantWith/callReceiver.kt @@ -0,0 +1,10 @@ +fun test() { + with(foo()) { + println("test") + } +} + +fun foo(): String { + println("foo") + return "" +} diff --git a/idea/testData/inspections/redundantWith/inspectionData/expected.xml b/idea/testData/inspections/redundantWith/inspectionData/expected.xml new file mode 100644 index 00000000000..6173aa08373 --- /dev/null +++ b/idea/testData/inspections/redundantWith/inspectionData/expected.xml @@ -0,0 +1,9 @@ + + + callReceiver.kt + 2 + + Redundant 'with' call + Redundant 'with' call + + diff --git a/idea/testData/inspections/redundantWith/inspectionData/inspections.test b/idea/testData/inspections/redundantWith/inspectionData/inspections.test new file mode 100644 index 00000000000..8c3d2fee556 --- /dev/null +++ b/idea/testData/inspections/redundantWith/inspectionData/inspections.test @@ -0,0 +1,2 @@ +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.RedundantWithInspection +// WITH_RUNTIME \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/.inspection b/idea/testData/inspectionsLocal/redundantWith/.inspection new file mode 100644 index 00000000000..f0c5bd4a97d --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.RedundantWithInspection \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/emptyExpressionInReturn.kt b/idea/testData/inspectionsLocal/redundantWith/emptyExpressionInReturn.kt new file mode 100644 index 00000000000..b11e3f999e0 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/emptyExpressionInReturn.kt @@ -0,0 +1,5 @@ +// WITH_RUNTIME +fun test() { + return with (1) { + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/emptyExpressionInReturn.kt.after b/idea/testData/inspectionsLocal/redundantWith/emptyExpressionInReturn.kt.after new file mode 100644 index 00000000000..9786313b79b --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/emptyExpressionInReturn.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun test() { + return +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/nested.kt b/idea/testData/inspectionsLocal/redundantWith/nested.kt new file mode 100644 index 00000000000..500e5719dd7 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/nested.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun test() { + with ("") { + with ("a") { + this + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/nested.kt.after b/idea/testData/inspectionsLocal/redundantWith/nested.kt.after new file mode 100644 index 00000000000..5606ec0cec1 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/nested.kt.after @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun test() { + with ("a") { + this + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis.kt new file mode 100644 index 00000000000..6fbf3e009ad --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + with ("") { + this + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis2.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis2.kt new file mode 100644 index 00000000000..2178b098c4c --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis2.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + with ("") { + this.length + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_functionCall.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_functionCall.kt new file mode 100644 index 00000000000..51366cc4e08 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_functionCall.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + val c = MyClass() + with(c) { + println(f()) + } +} + +class MyClass { + fun f(): String = "" +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_implicitThis.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_implicitThis.kt new file mode 100644 index 00000000000..37a45f6833b --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_implicitThis.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + with ("") { + length + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_inBinaryExpression.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inBinaryExpression.kt new file mode 100644 index 00000000000..7d67aabc7aa --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inBinaryExpression.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + val b = 1 == with ("") { + println() + 1 + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_inFunctionBody.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inFunctionBody.kt new file mode 100644 index 00000000000..597c45615f2 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inFunctionBody.kt @@ -0,0 +1,6 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() = with("") { + println() + 1 +} diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_inProperty.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inProperty.kt new file mode 100644 index 00000000000..65cceb0b080 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inProperty.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + val i = with ("") { + println() + 1 + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_inPropertyGetter.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inPropertyGetter.kt new file mode 100644 index 00000000000..7a1043ec2e9 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inPropertyGetter.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +val a: Int + get() = with("") { + println() + 1 + } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_inReturn.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inReturn.kt new file mode 100644 index 00000000000..cd503e2d5b0 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inReturn.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test(): Int { + return with ("") { + println() + 1 + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_inValueArgument.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inValueArgument.kt new file mode 100644 index 00000000000..266600d2365 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_inValueArgument.kt @@ -0,0 +1,10 @@ +// PROBLEM: none +// WITH_RUNTIME +fun foo(i: Int) {} + +fun test() { + foo(with("") { + println() + 1 + }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn.kt new file mode 100644 index 00000000000..412a3f004fc --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + with ("") { + return@with + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn2.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn2.kt new file mode 100644 index 00000000000..eeb2db7740d --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn2.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test(): String { + with("") { + return this@with + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis.kt new file mode 100644 index 00000000000..fd764727a55 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + with ("") { + this@with + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis2.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis2.kt new file mode 100644 index 00000000000..387e268d26a --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis2.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + with ("") { + this@with.length + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/notApplicable_variableFunctionCall.kt b/idea/testData/inspectionsLocal/redundantWith/notApplicable_variableFunctionCall.kt new file mode 100644 index 00000000000..827b93f6bde --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/notApplicable_variableFunctionCall.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +// WITH_RUNTIME +fun test() { + val c = MyClass() + with(c) { + println(f()) + } +} + +class MyClass { + val f: () -> String = { "" } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/simple.kt b/idea/testData/inspectionsLocal/redundantWith/simple.kt new file mode 100644 index 00000000000..ba6e02893e6 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/simple.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +fun test() { + with ("") { + println("1") + println("2") + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/simple.kt.after b/idea/testData/inspectionsLocal/redundantWith/simple.kt.after new file mode 100644 index 00000000000..f6426056339 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/simple.kt.after @@ -0,0 +1,5 @@ +// WITH_RUNTIME +fun test() { + println("1") + println("2") +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/simple2.kt b/idea/testData/inspectionsLocal/redundantWith/simple2.kt new file mode 100644 index 00000000000..164ccf833a1 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/simple2.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +fun test(s: String) { + with (s, { + println("1") + println("2") + }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/simple2.kt.after b/idea/testData/inspectionsLocal/redundantWith/simple2.kt.after new file mode 100644 index 00000000000..5636aff48ac --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/simple2.kt.after @@ -0,0 +1,5 @@ +// WITH_RUNTIME +fun test(s: String) { + println("1") + println("2") +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/singleExpressionInReturn.kt b/idea/testData/inspectionsLocal/redundantWith/singleExpressionInReturn.kt new file mode 100644 index 00000000000..e25fcab2ecb --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/singleExpressionInReturn.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun test(): Int { + return with (1) { + 2 + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantWith/singleExpressionInReturn.kt.after b/idea/testData/inspectionsLocal/redundantWith/singleExpressionInReturn.kt.after new file mode 100644 index 00000000000..11a3633db98 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantWith/singleExpressionInReturn.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun test(): Int { + return 2 +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java index 36b86ddacfb..ba3901559e2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java @@ -304,6 +304,11 @@ public class InspectionTestGenerated extends AbstractInspectionTest { runTest("idea/testData/inspections/redundantVisibilityModifier/inspectionData/inspections.test"); } + @TestMetadata("redundantWith/inspectionData/inspections.test") + public void testRedundantWith_inspectionData_Inspections_test() throws Exception { + runTest("idea/testData/inspections/redundantWith/inspectionData/inspections.test"); + } + @TestMetadata("reformat/inspectionData/inspections.test") public void testReformat_inspectionData_Inspections_test() throws Exception { runTest("idea/testData/inspections/reformat/inspectionData/inspections.test"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 057f67b6632..a7994742ddb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -3779,6 +3779,119 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/redundantWith") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RedundantWith extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRedundantWith() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/redundantWith"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("emptyExpressionInReturn.kt") + public void testEmptyExpressionInReturn() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/emptyExpressionInReturn.kt"); + } + + @TestMetadata("nested.kt") + public void testNested() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/nested.kt"); + } + + @TestMetadata("notApplicable_explicitThis.kt") + public void testNotApplicable_explicitThis() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis.kt"); + } + + @TestMetadata("notApplicable_explicitThis2.kt") + public void testNotApplicable_explicitThis2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_explicitThis2.kt"); + } + + @TestMetadata("notApplicable_functionCall.kt") + public void testNotApplicable_functionCall() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_functionCall.kt"); + } + + @TestMetadata("notApplicable_implicitThis.kt") + public void testNotApplicable_implicitThis() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_implicitThis.kt"); + } + + @TestMetadata("notApplicable_inBinaryExpression.kt") + public void testNotApplicable_inBinaryExpression() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_inBinaryExpression.kt"); + } + + @TestMetadata("notApplicable_inFunctionBody.kt") + public void testNotApplicable_inFunctionBody() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_inFunctionBody.kt"); + } + + @TestMetadata("notApplicable_inProperty.kt") + public void testNotApplicable_inProperty() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_inProperty.kt"); + } + + @TestMetadata("notApplicable_inPropertyGetter.kt") + public void testNotApplicable_inPropertyGetter() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_inPropertyGetter.kt"); + } + + @TestMetadata("notApplicable_inReturn.kt") + public void testNotApplicable_inReturn() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_inReturn.kt"); + } + + @TestMetadata("notApplicable_inValueArgument.kt") + public void testNotApplicable_inValueArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_inValueArgument.kt"); + } + + @TestMetadata("notApplicable_labeledReturn.kt") + public void testNotApplicable_labeledReturn() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn.kt"); + } + + @TestMetadata("notApplicable_labeledReturn2.kt") + public void testNotApplicable_labeledReturn2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledReturn2.kt"); + } + + @TestMetadata("notApplicable_labeledThis.kt") + public void testNotApplicable_labeledThis() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis.kt"); + } + + @TestMetadata("notApplicable_labeledThis2.kt") + public void testNotApplicable_labeledThis2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_labeledThis2.kt"); + } + + @TestMetadata("notApplicable_variableFunctionCall.kt") + public void testNotApplicable_variableFunctionCall() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/notApplicable_variableFunctionCall.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/simple.kt"); + } + + @TestMetadata("simple2.kt") + public void testSimple2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/simple2.kt"); + } + + @TestMetadata("singleExpressionInReturn.kt") + public void testSingleExpressionInReturn() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantWith/singleExpressionInReturn.kt"); + } + } + @TestMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)