Override 'equals' in SelfTargetingIntention

This prevents suggestion of duplicating intentions
This commit is contained in:
Mikhail Glukhikh
2017-05-10 15:09:52 +03:00
parent a8b2d3b4e8
commit 967c01f0ba
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.FileModificationService
import com.intellij.codeInsight.daemon.HighlightDisplayKey
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.IntentionWrapper
import com.intellij.codeInspection.LocalInspectionEP
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.project.Project
@@ -31,7 +31,6 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.psiUtil.containsInside
@@ -39,6 +38,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import java.util.*
import kotlin.reflect.KClass
@Suppress("EqualsOrHashCode")
abstract class SelfTargetingIntention<TElement : PsiElement>(
val elementType: Class<TElement>,
private var text: String,
@@ -118,6 +118,14 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
override fun toString(): String = getText()
override fun equals(other: Any?): Boolean {
// Nasty code because IntentionWrapper itself does not override equals
if (other is IntentionWrapper) return this == other.action
return other is SelfTargetingIntention<*> && javaClass == other.javaClass && text == other.text
}
// Intentionally missed hashCode (IntentionWrapper does not override it)
companion object {
private val intentionBasedInspections = HashMap<KClass<out SelfTargetingIntention<*>>, IntentionBasedInspection<*>?>()