Boolean literal arguments: do not report for varargs parameters
#KT-29469 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8672d2adc0
commit
3649e61c2f
@@ -16,7 +16,6 @@ import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
||||
import org.jetbrains.kotlin.idea.intentions.AddNameToArgumentIntention
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtConstantExpression
|
||||
@@ -38,7 +37,7 @@ class BooleanLiteralArgumentInspection(
|
||||
if (valueArguments.takeLastWhile { it != argument }.any { !it.isNamed() }) return
|
||||
|
||||
if (argumentExpression.analyze().diagnostics.forElement(argumentExpression).any { it.severity == Severity.ERROR }) return
|
||||
if (call.resolveToCall()?.resultingDescriptor?.hasStableParameterNames() != true) return
|
||||
if (AddNameToArgumentIntention.detectNameToAdd(argument) == null) return
|
||||
|
||||
val hasPreviousUnnamedBoolean = valueArguments.asSequence().windowed(size = 2, step = 1).any { (prev, next) ->
|
||||
next == argument && !prev.isNamed() &&
|
||||
|
||||
@@ -68,7 +68,7 @@ class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
|
||||
return true
|
||||
}
|
||||
|
||||
private fun detectNameToAdd(argument: KtValueArgument): Name? {
|
||||
fun detectNameToAdd(argument: KtValueArgument): Name? {
|
||||
if (argument.isNamed()) return null
|
||||
if (argument is KtLambdaArgument) return null
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
fun foo(vararg b: Boolean) {}
|
||||
|
||||
fun test() {
|
||||
foo(true, true, true<caret>)
|
||||
}
|
||||
+5
@@ -113,6 +113,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
public void testJavaMethod() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/booleanLiteralArgument/javaMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/booleanLiteralArgument/vararg.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/branched")
|
||||
|
||||
Reference in New Issue
Block a user