Fix KT-26965
This commit is contained in:
@@ -1753,6 +1753,7 @@
|
|||||||
level="WEAK WARNING"
|
level="WEAK WARNING"
|
||||||
language="kotlin"
|
language="kotlin"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.ReplaceCollectionCountWithSizeInspection"
|
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.ReplaceCollectionCountWithSizeInspection"
|
||||||
displayName="Collection count can be converted to size"
|
displayName="Collection count can be converted to size"
|
||||||
groupPath="Kotlin"
|
groupPath="Kotlin"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
This intention replaces <code>count()</code> function calls with <code>size</code>.
|
This inspection reports usages of collection <code>count()</code>. These function calls can be replaced with <code>size</code>.
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+3
-7
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2019 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.
|
* that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.idea.inspections
|
|||||||
|
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
import com.intellij.codeInspection.ProblemHighlightType
|
|
||||||
import com.intellij.codeInspection.ProblemsHolder
|
import com.intellij.codeInspection.ProblemsHolder
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
@@ -23,8 +22,7 @@ class ReplaceCollectionCountWithSizeInspection : AbstractKotlinInspection() {
|
|||||||
if (callExpression.isCount()) {
|
if (callExpression.isCount()) {
|
||||||
holder.registerProblem(
|
holder.registerProblem(
|
||||||
callExpression,
|
callExpression,
|
||||||
"Replace 'count' with 'size'",
|
"Could be replaced with `size`",
|
||||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
|
||||||
ReplaceCollectionCountWithSizeQuickFix()
|
ReplaceCollectionCountWithSizeQuickFix()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -43,6 +41,4 @@ class ReplaceCollectionCountWithSizeQuickFix : LocalQuickFix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtCallExpression.isCount(): Boolean {
|
private fun KtCallExpression.isCount(): Boolean = valueArguments.isEmpty() && isCalling(FqName("kotlin.collections.count"))
|
||||||
return isCalling(FqName("kotlin.collections.count")) && (this.valueArguments.size == 0)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user