Fix KT-26965
This commit is contained in:
@@ -1753,6 +1753,7 @@
|
||||
level="WEAK WARNING"
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.ReplaceCollectionCountWithSizeInspection"
|
||||
displayName="Collection count can be converted to size"
|
||||
groupPath="Kotlin"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<html>
|
||||
<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>
|
||||
</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.
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,6 @@ 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
|
||||
@@ -23,8 +22,7 @@ class ReplaceCollectionCountWithSizeInspection : AbstractKotlinInspection() {
|
||||
if (callExpression.isCount()) {
|
||||
holder.registerProblem(
|
||||
callExpression,
|
||||
"Replace 'count' with 'size'",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
"Could be replaced with `size`",
|
||||
ReplaceCollectionCountWithSizeQuickFix()
|
||||
)
|
||||
}
|
||||
@@ -43,6 +41,4 @@ class ReplaceCollectionCountWithSizeQuickFix : LocalQuickFix {
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtCallExpression.isCount(): Boolean {
|
||||
return isCalling(FqName("kotlin.collections.count")) && (this.valueArguments.size == 0)
|
||||
}
|
||||
private fun KtCallExpression.isCount(): Boolean = valueArguments.isEmpty() && isCalling(FqName("kotlin.collections.count"))
|
||||
|
||||
Reference in New Issue
Block a user