[light classes] methods: fix PluginException: Incorrect CachedValue use

^KTIJ-6085 Fixed
This commit is contained in:
Dmitry Gridin
2021-09-15 11:41:55 +07:00
committed by Space
parent 495cd2db94
commit 5d56bd545e
3 changed files with 42 additions and 45 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -146,21 +146,22 @@ internal class UltraLightMembersCreator(
internal class KtUltraLightAnnotationMethod(
private val psiMethod: KtLightMethod,
expression: KtExpression
) : KtLightMethod by psiMethod,
PsiAnnotationMethod {
private val expression: KtExpression
) : KtLightMethod by psiMethod, PsiAnnotationMethod {
private val value by lazyPub {
convertToLightAnnotationMemberValue(psiMethod, expression)
}
override fun equals(other: Any?): Boolean = psiMethod == (other as? KtUltraLightAnnotationMethod)?.psiMethod
override fun equals(other: Any?): Boolean = other === this ||
other is KtUltraLightAnnotationMethod &&
other.psiMethod == psiMethod &&
other.expression == expression
override fun hashCode(): Int = psiMethod.hashCode()
override fun hashCode(): Int = psiMethod.hashCode() * 31 + expression.hashCode()
override fun toString(): String = psiMethod.toString()
override fun toString(): String = "KtUltraLightAnnotationMethod(method=$psiMethod, expression=$expression"
override fun getDefaultValue(): PsiAnnotationMemberValue? = value
override fun getDefaultValue(): PsiAnnotationMemberValue = value
override fun getSourceElement(): PsiElement? = psiMethod.sourceElement
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -134,17 +134,15 @@ internal abstract class KtUltraLightMethod(
override fun getSignature(substitutor: PsiSubstitutor): MethodSignature =
MethodSignatureBackedByPsiMethod.create(this, substitutor)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is KtUltraLightMethod) return false
if (methodIndex != other.methodIndex) return false
if (this.javaClass != other.javaClass) return false
if (containingClass != other.containingClass) return false
if (kotlinOrigin === null || other.kotlinOrigin === null) return false
return kotlinOrigin == other.kotlinOrigin
}
override fun equals(other: Any?): Boolean = other === this ||
other is KtUltraLightMethod &&
other.methodIndex == methodIndex &&
other.delegate == delegate &&
super.equals(other)
override fun hashCode(): Int = name.hashCode()
override fun hashCode(): Int = super.hashCode()
.times(31).plus(delegate.hashCode())
.times(31).plus(methodIndex.hashCode())
override fun isDeprecated(): Boolean = _deprecated
}
@@ -197,6 +195,13 @@ internal class KtUltraLightMethodForSourceDeclaration(
override fun getThrowsList(): PsiReferenceList = _throwsList
override val checkNeedToErasureParametersTypes: Boolean by lazyPub { computeCheckNeedToErasureParametersTypes(methodDescriptor) }
override fun equals(other: Any?): Boolean =
other is KtUltraLightMethodForSourceDeclaration &&
other.forceToSkipNullabilityAnnotation == forceToSkipNullabilityAnnotation &&
super.equals(other)
override fun hashCode(): Int = super.hashCode() * 31 + forceToSkipNullabilityAnnotation.hashCode()
}
internal class KtUltraLightMethodForDescriptor(
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.asJava.elements
@@ -158,19 +147,21 @@ open class KtLightMethodImpl protected constructor(
get() = (dummyDelegate ?: clsDelegate).memberIndex
/* 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 =
this === other ||
(other is KtLightMethodImpl &&
this.name == other.name &&
this.containingClass == other.containingClass &&
this.lightMemberOrigin == other.lightMemberOrigin &&
this.memberIndex == other.memberIndex)
for compiled elements origin contains delegate
for source elements index is unique to each member
*/
override fun equals(other: Any?): Boolean = other === this ||
other is KtLightMethodImpl &&
other.javaClass == javaClass &&
other.containingClass == containingClass &&
other.lightMemberOrigin == lightMemberOrigin &&
other.dummyDelegate == dummyDelegate &&
other.memberIndex == memberIndex
override fun hashCode(): Int = ((name.hashCode() * 31 + (lightMemberOrigin?.hashCode()
?: 0)) * 31 + containingClass.hashCode()) * 31 + (memberIndex?.hashCode() ?: 0)
override fun hashCode(): Int = name.hashCode()
.times(31).plus(lightMemberOrigin.hashCode())
.times(31).plus(containingClass.hashCode())
.times(31).plus(memberIndex.hashCode())
override fun getDefaultValue() = (clsDelegate as? PsiAnnotationMethod)?.defaultValue