From 2a940f5b0a7979d8d0a02a61fc7e620e4a9d9cd8 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 1 Mar 2019 17:43:56 +0300 Subject: [PATCH] Fix KT-26965 --- idea/resources/META-INF/plugin-common.xml | 1 + .../ReplaceCollectionCountWithSize.html | 2 +- .../ReplaceCollectionCountWithSizeInspection.kt | 10 +++------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 8f0a714d190..aac87b22b2b 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -1753,6 +1753,7 @@ level="WEAK WARNING" language="kotlin" /> + -This intention replaces count() function calls with size. +This inspection reports usages of collection count(). These function calls can be replaced with size. diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceCollectionCountWithSizeInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceCollectionCountWithSizeInspection.kt index 0621dcac275..d3025c5d3ba 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceCollectionCountWithSizeInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceCollectionCountWithSizeInspection.kt @@ -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"))