diff --git a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/KotlinApplicableToolBase.kt b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/KotlinApplicableToolBase.kt index 5d06551d021f..ef71b84f7b61 100644 --- a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/KotlinApplicableToolBase.kt +++ b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/KotlinApplicableToolBase.kt @@ -1,28 +1,19 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.codeinsight.api.applicable -import com.intellij.codeInspection.util.IntentionFamilyName import org.jetbrains.kotlin.idea.codeinsight.api.applicators.KotlinApplicabilityRange -import org.jetbrains.kotlin.idea.codeinsight.api.applicators.applicabilityTarget import org.jetbrains.kotlin.psi.KtElement /** * A common base interface for [KotlinApplicableIntentionBase] and [KotlinApplicableInspectionBase]. */ interface KotlinApplicableToolBase { - /** - * @see com.intellij.codeInsight.intention.IntentionAction.getFamilyName - * @see com.intellij.codeInspection.QuickFix.getFamilyName - */ - fun getFamilyName(): @IntentionFamilyName String - /** * The [KotlinApplicabilityRange] determines whether the tool is available in a range *after* [isApplicableByPsi] has been checked. * - * The default applicability range is equivalent to `ApplicabilityRanges.SELF`. Configuration of the applicability range might be as - * simple as choosing an existing one from `ApplicabilityRanges`. + * Configuration of the applicability range might be as simple as choosing an existing one from `ApplicabilityRanges`. */ - fun getApplicabilityRange(): KotlinApplicabilityRange = applicabilityTarget { it } + fun getApplicabilityRange(): KotlinApplicabilityRange /** * Whether this tool is applicable to [element] by PSI only. May not use the Analysis API due to performance concerns. diff --git a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspection.kt b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspection.kt index 15f1c5aca1d4..4f77743a95df 100644 --- a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspection.kt +++ b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspection.kt @@ -28,7 +28,7 @@ abstract class AbstractKotlinApplicableInspection( * * @see com.intellij.codeInspection.CommonProblemDescriptor.getDescriptionTemplate */ - open fun getProblemDescription(element: ELEMENT): @InspectionMessage String = getFamilyName() + open fun getProblemDescription(element: ELEMENT): @InspectionMessage String = getActionFamilyName() /** * Returns the [ProblemHighlightType] for the inspection's registered problem. @@ -45,7 +45,7 @@ abstract class AbstractKotlinApplicableInspection( apply(element, element.project, element.findExistingEditor()) } - override fun getFamilyName(): String = this@KotlinApplicableInspection.getFamilyName() + override fun getFamilyName(): String = this@AbstractKotlinApplicableInspection.getActionFamilyName() override fun getName(): String = elementPointer.element?.let { getActionName(element) } ?: familyName } diff --git a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt index 023d35a06f01..6a9f8bb06919 100644 --- a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt +++ b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt @@ -3,7 +3,9 @@ package org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections import com.intellij.codeInspection.* import com.intellij.codeInspection.util.InspectionMessage +import com.intellij.codeInspection.util.IntentionFamilyName import com.intellij.openapi.project.Project +import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiFile import org.jetbrains.kotlin.idea.codeinsight.api.applicable.KotlinApplicableToolBase import org.jetbrains.kotlin.idea.codeinsight.api.applicators.* @@ -19,6 +21,17 @@ import kotlin.reflect.KClass sealed class KotlinApplicableInspectionBase( elementType: KClass, ) : KotlinSingleElementInspection(elementType), KotlinApplicableToolBase { + /** + * @see com.intellij.codeInspection.QuickFix.getFamilyName + */ + abstract fun getActionFamilyName(): @IntentionFamilyName String + + /** + * By default, a problem is registered for every [TextRange] produced by [getApplicabilityRange]. [getProblemRanges] can be overridden + * to customize this behavior, e.g. to register a problem only for the first [TextRange]. + */ + open fun getProblemRanges(ranges: List): List = ranges + internal class ProblemInfo( val description: @InspectionMessage String, val highlightType: ProblemHighlightType, @@ -37,19 +50,14 @@ sealed class KotlinApplicableInspectionBase( if (ranges.isEmpty()) return val problemInfo = buildProblemInfo(element) ?: return - ranges.forEach { range -> - with(holder) { - registerProblem( - manager.createProblemDescriptor( - element, - range, - problemInfo.description, - problemInfo.highlightType, - isOnTheFly, - problemInfo.quickFix - ) - ) - } + getProblemRanges(ranges).forEach { range -> + holder.registerProblem( + element, + problemInfo.description, + problemInfo.highlightType, + range, + problemInfo.quickFix, + ) } } } diff --git a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionWithContext.kt b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionWithContext.kt index b5e044ae6d72..ccea5f620c09 100644 --- a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionWithContext.kt +++ b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionWithContext.kt @@ -28,7 +28,7 @@ abstract class AbstractKotlinApplicableInspectionWithContext( elementType: KClass, ) : SelfTargetingIntention(elementType.java, { "" }), KotlinApplicableToolBase { + /** + * @see com.intellij.codeInsight.intention.IntentionAction.getFamilyName + */ abstract override fun getFamilyName(): @IntentionFamilyName String /** diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ImplicitThisInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ImplicitThisInspection.kt index 9667a288034a..106e8e756486 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ImplicitThisInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ImplicitThisInspection.kt @@ -24,10 +24,12 @@ internal class ImplicitThisInspection : val isUnambiguousLabel: Boolean ) - override fun getFamilyName(): String = KotlinBundle.message("inspection.implicit.this.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.implicit.this.display.name") override fun getActionName(element: KtExpression, context: ImplicitReceiverInfo): String = KotlinBundle.message("inspection.implicit.this.action.name") + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtExpression): Boolean { return when (element) { is KtSimpleNameExpression -> { @@ -62,7 +64,8 @@ internal class ImplicitThisInspection : } } -private fun KtAnalysisSession.getAssociatedClass(symbol: KtSymbol): KtClassOrObjectSymbol? { +context(KtAnalysisSession) +private fun getAssociatedClass(symbol: KtSymbol): KtClassOrObjectSymbol? { // both variables and functions are callable and only they can be referenced by "this" if (symbol !is KtCallableSymbol) return null return when (symbol) { @@ -76,7 +79,8 @@ private fun KtAnalysisSession.getAssociatedClass(symbol: KtSymbol): KtClassOrObj } } -private fun KtAnalysisSession.getImplicitReceiverInfoOfClass( +context(KtAnalysisSession) +private fun getImplicitReceiverInfoOfClass( implicitReceivers: List, associatedClass: KtClassOrObjectSymbol ): ImplicitThisInspection.ImplicitReceiverInfo? { // We can't use "this" with label if the label is already taken @@ -100,7 +104,8 @@ private fun KtAnalysisSession.getImplicitReceiverInfoOfClass( return null } -private fun KtAnalysisSession.getImplicitReceiverClassAndTag(receiver: KtImplicitReceiver): Pair? { +context(KtAnalysisSession) +private fun getImplicitReceiverClassAndTag(receiver: KtImplicitReceiver): Pair? { val associatedClass = receiver.type.expandedClassSymbol ?: return null val associatedTag: Name? = when (val receiverSymbol = receiver.ownerSymbol) { is KtClassOrObjectSymbol -> receiverSymbol.name diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/NullableBooleanElvisInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/NullableBooleanElvisInspection.kt index 9bac0d007f35..7e2e81b4bf60 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/NullableBooleanElvisInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/NullableBooleanElvisInspection.kt @@ -21,10 +21,12 @@ import org.jetbrains.kotlin.psi.* * See plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/NullableBooleanElvis.html for details. */ class NullableBooleanElvisInspection : AbstractKotlinApplicableInspection(KtBinaryExpression::class) { - override fun getFamilyName(): String = KotlinBundle.message("inspection.nullable.boolean.elvis.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.nullable.boolean.elvis.display.name") override fun getActionName(element: KtBinaryExpression): String = KotlinBundle.message("inspection.nullable.boolean.elvis.action.name") + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtBinaryExpression): Boolean = element.isTargetOfNullableBooleanElvisInspection() context(KtAnalysisSession) diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RedundantElvisReturnNullInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RedundantElvisReturnNullInspection.kt index 328e57f1083a..28f310b19fd4 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RedundantElvisReturnNullInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RedundantElvisReturnNullInspection.kt @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes internal class RedundantElvisReturnNullInspection : AbstractKotlinApplicableInspection(KtBinaryExpression::class) { - override fun getFamilyName(): String = KotlinBundle.message("inspection.redundant.elvis.return.null.descriptor") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.redundant.elvis.return.null.descriptor") override fun getActionName(element: KtBinaryExpression): String = KotlinBundle.message("remove.redundant.elvis.return.null.text") override fun getApplicabilityRange() = applicabilityRanges { binaryExpression: KtBinaryExpression -> diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveSingleExpressionStringTemplateInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveSingleExpressionStringTemplateInspection.kt index 5c83a4e1d6de..046e900dd916 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveSingleExpressionStringTemplateInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveSingleExpressionStringTemplateInspection.kt @@ -20,8 +20,10 @@ internal class RemoveSingleExpressionStringTemplateInspection : class Context(val isString: Boolean) - override fun getFamilyName(): String = KotlinBundle.message("remove.single.expression.string.template") - override fun getActionName(element: KtStringTemplateExpression, context: Context): String = getFamilyName() + override fun getActionFamilyName(): String = KotlinBundle.message("remove.single.expression.string.template") + override fun getActionName(element: KtStringTemplateExpression, context: Context): String = getActionFamilyName() + + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF override fun isApplicableByPsi(element: KtStringTemplateExpression): Boolean = element.singleExpressionOrNull() != null diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveToStringInStringTemplateInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveToStringInStringTemplateInspection.kt index 2a3aa97b4ecc..eaa19007279b 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveToStringInStringTemplateInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/RemoveToStringInStringTemplateInspection.kt @@ -22,8 +22,8 @@ internal class RemoveToStringInStringTemplateInspection : AbstractKotlinApplicableInspection(KtDotQualifiedExpression::class), CleanupLocalInspectionTool { - override fun getFamilyName(): String = KotlinBundle.message("remove.to.string.fix.text") - override fun getActionName(element: KtDotQualifiedExpression): String = getFamilyName() + override fun getActionFamilyName(): String = KotlinBundle.message("remove.to.string.fix.text") + override fun getActionName(element: KtDotQualifiedExpression): String = getActionFamilyName() override fun getApplicabilityRange(): KotlinApplicabilityRange = applicabilityRanges { dotQualifiedExpression: KtDotQualifiedExpression -> diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ReplaceGetOrSetInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ReplaceGetOrSetInspection.kt index bcb212e1b9b7..38332ae5901c 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ReplaceGetOrSetInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/ReplaceGetOrSetInspection.kt @@ -26,7 +26,7 @@ internal class ReplaceGetOrSetInspection : class Context(val calleeName: Name) - override fun getFamilyName(): String = KotlinBundle.message("inspection.replace.get.or.set.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.replace.get.or.set.display.name") override fun getProblemDescription(element: KtDotQualifiedExpression, context: Context): String = KotlinBundle.message("explicit.0.call", context.calleeName) override fun getActionName(element: KtDotQualifiedExpression, context: Context): String = diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/declarations/RedundantUnitReturnTypeInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/declarations/RedundantUnitReturnTypeInspection.kt index 40710ff5f4cf..d18010b20096 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/declarations/RedundantUnitReturnTypeInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/declarations/RedundantUnitReturnTypeInspection.kt @@ -17,7 +17,7 @@ internal class RedundantUnitReturnTypeInspection : AbstractKotlinApplicableInspectionWithContext(KtNamedFunction::class), CleanupLocalInspectionTool { - override fun getFamilyName(): String = KotlinBundle.message("inspection.redundant.unit.return.type.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.redundant.unit.return.type.display.name") override fun getActionName(element: KtNamedFunction, context: TypeInfo): String = KotlinBundle.message("inspection.redundant.unit.return.type.action.name") diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantModalityModifierInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantModalityModifierInspection.kt index dafe7d4f45f7..c7ec2a448e38 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantModalityModifierInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantModalityModifierInspection.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.psiUtil.modalityModifierType class RedundantModalityModifierInspection : RedundantModifierInspectionBase(KtTokens.MODALITY_MODIFIERS) { - override fun getFamilyName(): String = KotlinBundle.message("redundant.modality.modifier") + override fun getActionFamilyName(): String = KotlinBundle.message("redundant.modality.modifier") override fun getDiagnosticType() = KtFirDiagnostic.RedundantModalityModifier::class diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantVisibilityModifierInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantVisibilityModifierInspection.kt index 29f5772a29cb..d930047012a7 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantVisibilityModifierInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RedundantVisibilityModifierInspection.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType internal class RedundantVisibilityModifierInspection : RedundantModifierInspectionBase(KtTokens.VISIBILITY_MODIFIERS) { - override fun getFamilyName(): String = KotlinBundle.message("redundant.visibility.modifier") + override fun getActionFamilyName(): String = KotlinBundle.message("redundant.visibility.modifier") override fun getDiagnosticType() = KtFirDiagnostic.RedundantVisibilityModifier::class diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/UnusedVariableInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/UnusedVariableInspection.kt index 4b11959c2ff5..d8f637dce942 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/UnusedVariableInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/UnusedVariableInspection.kt @@ -19,7 +19,7 @@ internal class UnusedVariableInspection : KtNamedDeclaration::class, ) { - override fun getFamilyName(): String = KotlinBundle.message("inspection.kotlin.unused.variable.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.kotlin.unused.variable.display.name") override fun getActionName(element: KtNamedDeclaration): String = KotlinBundle.message("remove.variable.0", element.name.toString()) diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/KotlinDoubleNegationInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/KotlinDoubleNegationInspection.kt index c3327870e9f9..aac6a98e1bb3 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/KotlinDoubleNegationInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/KotlinDoubleNegationInspection.kt @@ -14,10 +14,12 @@ import org.jetbrains.kotlin.psi.KtParenthesizedExpression import org.jetbrains.kotlin.psi.KtPrefixExpression internal class KotlinDoubleNegationInspection : AbstractKotlinApplicableInspection(KtPrefixExpression::class) { - override fun getFamilyName(): String = KotlinBundle.message("inspection.kotlin.double.negation.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.kotlin.double.negation.display.name") override fun getActionName(element: KtPrefixExpression): String = KotlinBundle.message("inspection.kotlin.double.negation.action.name") + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtPrefixExpression): Boolean = element.operationToken == KtTokens.EXCL && (element.parentThroughParenthesis as? KtPrefixExpression)?.operationToken == KtTokens.EXCL diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/ReplaceCollectionCountWithSizeInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/ReplaceCollectionCountWithSizeInspection.kt index 62f027d7a1c7..17e2d2476bd1 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/ReplaceCollectionCountWithSizeInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/expressions/ReplaceCollectionCountWithSizeInspection.kt @@ -23,10 +23,12 @@ private val COLLECTION_CLASS_IDS = setOf(StandardClassIds.Collection, StandardCl StandardClassIds.elementTypeByPrimitiveArrayType.keys + StandardClassIds.unsignedArrayTypeByElementType.keys internal class ReplaceCollectionCountWithSizeInspection : AbstractKotlinApplicableInspection(KtCallExpression::class) { - override fun getFamilyName(): String = KotlinBundle.message("inspection.replace.collection.count.with.size.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.replace.collection.count.with.size.display.name") override fun getActionName(element: KtCallExpression): String = KotlinBundle.message("replace.collection.count.with.size.quick.fix.text") + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtCallExpression): Boolean = element.calleeExpression?.text == "count" && element.valueArguments.isEmpty() diff --git a/plugins/kotlin/code-insight/inspections-shared/src/org/jetbrains/kotlin/idea/codeInsight/inspections/shared/RemoveEmptyParenthesesFromLambdaCallInspection.kt b/plugins/kotlin/code-insight/inspections-shared/src/org/jetbrains/kotlin/idea/codeInsight/inspections/shared/RemoveEmptyParenthesesFromLambdaCallInspection.kt index d230ad3ed0cb..22a30494a32b 100644 --- a/plugins/kotlin/code-insight/inspections-shared/src/org/jetbrains/kotlin/idea/codeInsight/inspections/shared/RemoveEmptyParenthesesFromLambdaCallInspection.kt +++ b/plugins/kotlin/code-insight/inspections-shared/src/org/jetbrains/kotlin/idea/codeInsight/inspections/shared/RemoveEmptyParenthesesFromLambdaCallInspection.kt @@ -8,13 +8,16 @@ import org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections.Abstract import org.jetbrains.kotlin.idea.codeinsight.api.applicators.KotlinApplicabilityRange import org.jetbrains.kotlin.idea.codeinsights.impl.base.RemoveEmptyParenthesesFromLambdaCallUtils.canRemoveByPsi import org.jetbrains.kotlin.idea.codeinsights.impl.base.RemoveEmptyParenthesesFromLambdaCallUtils.removeArgumentList +import org.jetbrains.kotlin.idea.codeinsights.impl.base.applicators.ApplicabilityRanges import org.jetbrains.kotlin.psi.KtValueArgumentList class RemoveEmptyParenthesesFromLambdaCallInspection : AbstractKotlinApplicableInspection(KtValueArgumentList::class) { - override fun getFamilyName(): String = KotlinBundle.message("inspection.remove.empty.parentheses.from.lambda.call.display.name") + override fun getActionFamilyName(): String = KotlinBundle.message("inspection.remove.empty.parentheses.from.lambda.call.display.name") override fun getActionName(element: KtValueArgumentList): String = KotlinBundle.message("inspection.remove.empty.parentheses.from.lambda.call.action.name") + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtValueArgumentList): Boolean = canRemoveByPsi(element) override fun apply(element: KtValueArgumentList, project: Project, editor: Editor?) { diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddOpenModifierIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddOpenModifierIntention.kt index b8296279fe62..0a8e86e11dc2 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddOpenModifierIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddOpenModifierIntention.kt @@ -24,6 +24,8 @@ internal class AddOpenModifierIntention : override fun getFamilyName(): String = KotlinBundle.message("make.open") override fun getActionName(element: KtCallableDeclaration): String = familyName + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtCallableDeclaration): Boolean = (element is KtProperty || element is KtNamedFunction) && !element.hasModifier(KtTokens.OPEN_KEYWORD) diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddWhenRemainingBranchesIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddWhenRemainingBranchesIntention.kt index 81810e17c87b..d70907413ee3 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddWhenRemainingBranchesIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/AddWhenRemainingBranchesIntention.kt @@ -19,6 +19,8 @@ internal class AddWhenRemainingBranchesIntention override fun getFamilyName(): String = AddRemainingWhenBranchesUtils.familyAndActionName(false) override fun getActionName(element: KtWhenExpression, context: AddRemainingWhenBranchesUtils.Context): String = familyName + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtWhenExpression): Boolean = true context(KtAnalysisSession) diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertConcatenationToBuildStringIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertConcatenationToBuildStringIntention.kt index 8daa3d88d345..d1fae0a751f9 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertConcatenationToBuildStringIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertConcatenationToBuildStringIntention.kt @@ -18,6 +18,8 @@ internal class ConvertConcatenationToBuildStringIntention : AbstractKotlinApplic override fun getFamilyName(): String = KotlinBundle.message("convert.concatenation.to.build.string") override fun getActionName(element: KtBinaryExpression): String = familyName + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtBinaryExpression): Boolean = element.operationToken == KtTokens.PLUS && !element.isAnnotationArgument() diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertStringTemplateToBuildStringIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertStringTemplateToBuildStringIntention.kt index cdaad3e57040..467a3867f5e8 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertStringTemplateToBuildStringIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertStringTemplateToBuildStringIntention.kt @@ -19,6 +19,8 @@ internal class ConvertStringTemplateToBuildStringIntention : AbstractKotlinAppli override fun getFamilyName(): String = KotlinBundle.message("convert.string.template.to.build.string") override fun getActionName(element: KtStringTemplateExpression): String = familyName + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtStringTemplateExpression): Boolean = !element.text.startsWith("\"\"\"") && !element.isAnnotationArgument() diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertToBlockBodyIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertToBlockBodyIntention.kt index f2fb256be3d8..936471a795ed 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertToBlockBodyIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ConvertToBlockBodyIntention.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.idea.base.resources.KotlinBundle import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.AbstractKotlinApplicableIntentionWithContext import org.jetbrains.kotlin.idea.codeinsight.api.applicators.KotlinApplicabilityRange import org.jetbrains.kotlin.idea.codeinsight.utils.adjustLineIndent +import org.jetbrains.kotlin.idea.codeinsights.impl.base.applicators.ApplicabilityRanges import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset @@ -33,6 +34,8 @@ internal class ConvertToBlockBodyIntention : override fun getFamilyName(): String = KotlinBundle.message("convert.to.block.body") override fun getActionName(element: KtDeclarationWithBody, context: Context): String = familyName + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtDeclarationWithBody): Boolean = (element is KtNamedFunction || element is KtPropertyAccessor) && !element.hasBlockBody() && element.hasBody() diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportAllMembersIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportAllMembersIntention.kt index c21233069697..9a113788954d 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportAllMembersIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportAllMembersIntention.kt @@ -39,6 +39,8 @@ internal class ImportAllMembersIntention : override fun getActionName(element: KtExpression, context: Context): String = KotlinBundle.message("import.members.from.0", context.fqName.asString()) + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtExpression): Boolean = element.isOnTheLeftOfQualificationDot && !element.isInImportDirective() diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportMemberIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportMemberIntention.kt index df9034f1a707..87afef2a0c19 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportMemberIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/ImportMemberIntention.kt @@ -35,6 +35,8 @@ internal class ImportMemberIntention : override fun getActionName(element: KtNameReferenceExpression, context: Context): String = KotlinBundle.message("add.import.for.0", context.fqName.asString()) + override fun getApplicabilityRange(): KotlinApplicabilityRange = ApplicabilityRanges.SELF + override fun isApplicableByPsi(element: KtNameReferenceExpression): Boolean = // Ignore simple name expressions or already imported names. element.getQualifiedElement() != element && !element.isInImportDirective()