KtLightMethod(Field): do not use clsDelegate in hashCode && equality checks

This commit is contained in:
Pavel V. Talanov
2017-02-28 17:23:18 +03:00
parent fee29c47c8
commit abf206a134
2 changed files with 19 additions and 21 deletions
@@ -102,18 +102,11 @@ sealed class KtLightFieldImpl<T: PsiField>(
override fun toString(): String = "${this::class.java.simpleName}:$name"
override fun equals(other: Any?): Boolean =
other is KtLightField &&
name == other.name &&
lightMemberOrigin == other.lightMemberOrigin &&
containingClass == other.containingClass &&
clsDelegate == other.clsDelegate
other is KtLightFieldImpl<*> &&
this.name == other.name &&
this.containingClass == other.containingClass
override fun hashCode(): Int {
var result = lightMemberOrigin?.hashCode() ?: 0
result = 31 * result + clsDelegate.hashCode()
result = 31 * result + containingClass.hashCode()
return result
}
override fun hashCode() = 31 * containingClass.hashCode() + (name?.hashCode() ?: 0)
override val kotlinOrigin: KtDeclaration? get() = lightMemberOrigin?.originalElement
@@ -27,9 +27,7 @@ import com.intellij.psi.scope.PsiScopeProcessor
import com.intellij.psi.util.*
import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.asJava.builder.ClsWrapperStubPsiFactory
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
import org.jetbrains.kotlin.asJava.builder.*
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.propertyNameByAccessor
import org.jetbrains.kotlin.asJava.unwrapped
@@ -188,14 +186,21 @@ class KtLightMethodImpl private constructor(
return super.isEquivalentTo(another)
}
override fun equals(other: Any?): Boolean =
other is KtLightMethod &&
name == other.name &&
lightMethodOrigin == other.lightMethodOrigin &&
containingClass == other.containingClass &&
clsDelegate == other.clsDelegate
private val _memberIndex: MemberIndex?
get() = (dummyDelegate ?: clsDelegate).memberIndex
override fun hashCode(): Int = ((getName().hashCode() * 31 + (lightMethodOrigin?.hashCode() ?: 0)) * 31 + containingClass.hashCode()) * 31 + clsDelegate.hashCode()
/* comparing origin and member index should be enough to determine equality:
for compiled elements origin contains delegate
for source elements index is unique to each member
*/
override fun equals(other: Any?): Boolean =
other is KtLightMethodImpl &&
this.name == other.name &&
this.containingClass == other.containingClass &&
this.lightMethodOrigin == other.lightMethodOrigin &&
this._memberIndex == other._memberIndex
override fun hashCode(): Int = ((getName().hashCode() * 31 + (lightMethodOrigin?.hashCode() ?: 0)) * 31 + containingClass.hashCode()) * 31 + (_memberIndex?.hashCode() ?: 0)
override fun toString(): String = "${this::class.java.simpleName}:$name"