[light classes] simplify hashCode functions
^KTIJ-21151
This commit is contained in:
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="dimonchik0036">
|
||||
<words>
|
||||
<w>ktij</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
+12
-36
@@ -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-2022 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.classes
|
||||
@@ -63,24 +52,20 @@ open class KtLightClassForFacadeImpl constructor(
|
||||
|
||||
private val firstFileInFacade by lazyPub { files.iterator().next() }
|
||||
|
||||
private val hashCode: Int =
|
||||
computeHashCode()
|
||||
|
||||
private val packageFqName: FqName =
|
||||
facadeClassFqName.parent()
|
||||
|
||||
private val modifierList: PsiModifierList =
|
||||
LightModifierList(manager, KotlinLanguage.INSTANCE, PsiModifier.PUBLIC, PsiModifier.FINAL)
|
||||
|
||||
private val implementsList: LightEmptyImplementsList =
|
||||
LightEmptyImplementsList(manager)
|
||||
|
||||
private val packageClsFile = FakeFileForLightClass(
|
||||
firstFileInFacade,
|
||||
lightClass = { this },
|
||||
stub = { javaFileStub },
|
||||
packageFqName = packageFqName
|
||||
)
|
||||
private val packageClsFile by lazyPub {
|
||||
FakeFileForLightClass(
|
||||
firstFileInFacade,
|
||||
lightClass = { this },
|
||||
stub = { javaFileStub },
|
||||
packageFqName = facadeClassFqName.parent()
|
||||
)
|
||||
}
|
||||
|
||||
override fun getParent(): PsiElement = containingFile
|
||||
|
||||
@@ -210,14 +195,7 @@ open class KtLightClassForFacadeImpl constructor(
|
||||
return arrayOf(PsiType.getJavaLangObject(manager, resolveScope))
|
||||
}
|
||||
|
||||
override fun hashCode() = hashCode
|
||||
|
||||
private fun computeHashCode(): Int {
|
||||
var result = manager.hashCode()
|
||||
result = 31 * result + files.hashCode()
|
||||
result = 31 * result + facadeClassFqName.hashCode()
|
||||
return result
|
||||
}
|
||||
override fun hashCode() = facadeClassFqName.hashCode()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other == null || this::class.java != other::class.java) {
|
||||
@@ -227,10 +205,8 @@ open class KtLightClassForFacadeImpl constructor(
|
||||
val lightClass = other as KtLightClassForFacadeImpl
|
||||
if (this === other) return true
|
||||
|
||||
if (this.hashCode != lightClass.hashCode) return false
|
||||
if (manager != lightClass.manager) return false
|
||||
if (files != lightClass.files) return false
|
||||
if (facadeClassFqName != lightClass.facadeClassFqName) return false
|
||||
if (files != lightClass.files) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
+4
-17
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.classes
|
||||
|
||||
import com.intellij.openapi.util.Comparing
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.PsiSuperMethodImplUtil
|
||||
@@ -43,10 +42,6 @@ open class KtLightClassForScript(val script: KtScript) : KtLazyLightClass(script
|
||||
protected open val javaFileStub: PsiJavaFileStub?
|
||||
get() = getLightClassDataHolder().javaFileStub
|
||||
|
||||
private val hashCode: Int = computeHashCode()
|
||||
|
||||
private val packageFqName: FqName = script.fqName.parent()
|
||||
|
||||
private val modifierList: PsiModifierList = LightModifierList(manager, KotlinLanguage.INSTANCE, PsiModifier.PUBLIC)
|
||||
|
||||
private val scriptImplementsList: LightEmptyImplementsList = LightEmptyImplementsList(manager)
|
||||
@@ -62,13 +57,13 @@ open class KtLightClassForScript(val script: KtScript) : KtLazyLightClass(script
|
||||
script.containingKtFile,
|
||||
lightClass = { this },
|
||||
stub = { javaFileStub },
|
||||
packageFqName = packageFqName,
|
||||
packageFqName = fqName.parent(),
|
||||
)
|
||||
}
|
||||
|
||||
override val kotlinOrigin: KtClassOrObject? get() = null
|
||||
|
||||
val fqName: FqName = script.fqName
|
||||
val fqName: FqName get() = script.fqName
|
||||
|
||||
override fun getModifierList() = modifierList
|
||||
|
||||
@@ -164,13 +159,7 @@ open class KtLightClassForScript(val script: KtScript) : KtLazyLightClass(script
|
||||
|
||||
override fun getScope(): PsiElement = parent
|
||||
|
||||
override fun hashCode() = hashCode
|
||||
|
||||
private fun computeHashCode(): Int {
|
||||
var result = manager.hashCode()
|
||||
result = 31 * result + script.hashCode()
|
||||
return result
|
||||
}
|
||||
override fun hashCode() = script.hashCode()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other == null || this::class.java != other::class.java) {
|
||||
@@ -180,8 +169,6 @@ open class KtLightClassForScript(val script: KtScript) : KtLazyLightClass(script
|
||||
val lightClass = other as? KtLightClassForScript ?: return false
|
||||
if (this === other) return true
|
||||
|
||||
if (this.hashCode != lightClass.hashCode) return false
|
||||
if (manager != lightClass.manager) return false
|
||||
if (script != lightClass.script) return false
|
||||
|
||||
return true
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@@ -168,8 +168,8 @@ abstract class KtLightClassForSourceDeclaration(
|
||||
|
||||
val aClass = other as KtLightClassForSourceDeclaration
|
||||
|
||||
if (classOrObject != aClass.classOrObject) return false
|
||||
if (jvmDefaultMode != aClass.jvmDefaultMode) return false
|
||||
if (classOrObject != aClass.classOrObject) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isPublishedApi
|
||||
import org.jetbrains.kotlin.resolve.inline.isInlineOnly
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmSyntheticAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||
|
||||
internal class UltraLightMembersCreator(
|
||||
@@ -160,7 +160,7 @@ internal class UltraLightMembersCreator(
|
||||
other.psiMethod == psiMethod &&
|
||||
other.expression == expression
|
||||
|
||||
override fun hashCode(): Int = psiMethod.hashCode() * 31 + expression.hashCode()
|
||||
override fun hashCode(): Int = psiMethod.hashCode()
|
||||
|
||||
override fun toString(): String = "KtUltraLightAnnotationMethod(method=$psiMethod, expression=$expression"
|
||||
|
||||
|
||||
+8
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@@ -137,12 +137,10 @@ internal abstract class KtUltraLightMethod(
|
||||
override fun equals(other: Any?): Boolean = other === this ||
|
||||
other is KtUltraLightMethod &&
|
||||
other.methodIndex == methodIndex &&
|
||||
other.delegate == delegate &&
|
||||
super.equals(other)
|
||||
super.equals(other) &&
|
||||
other.delegate == delegate
|
||||
|
||||
override fun hashCode(): Int = super.hashCode()
|
||||
.times(31).plus(delegate.hashCode())
|
||||
.times(31).plus(methodIndex.hashCode())
|
||||
override fun hashCode(): Int = super.hashCode().times(31).plus(methodIndex.hashCode())
|
||||
|
||||
override fun isDeprecated(): Boolean = _deprecated
|
||||
}
|
||||
@@ -196,10 +194,10 @@ internal class KtUltraLightMethodForSourceDeclaration(
|
||||
|
||||
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 equals(other: Any?): Boolean = other === this ||
|
||||
other is KtUltraLightMethodForSourceDeclaration &&
|
||||
other.forceToSkipNullabilityAnnotation == forceToSkipNullabilityAnnotation &&
|
||||
super.equals(other)
|
||||
|
||||
override fun hashCode(): Int = super.hashCode() * 31 + forceToSkipNullabilityAnnotation.hashCode()
|
||||
}
|
||||
|
||||
+14
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@@ -17,15 +17,15 @@ import org.jetbrains.kotlin.asJava.elements.*
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_FUNCTION_COMPLETION_PARAMETER_NAME
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.LABELED_THIS_PARAMETER
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.RECEIVER_PARAMETER_NAME
|
||||
import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_FUNCTION_COMPLETION_PARAMETER_NAME
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isPrivate
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
internal class KtUltraLightSuspendContinuationParameter(
|
||||
private val ktFunction: KtFunction,
|
||||
@@ -57,8 +57,9 @@ internal class KtUltraLightSuspendContinuationParameter(
|
||||
|
||||
override fun getType(): PsiType = psiType
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is KtUltraLightSuspendContinuationParameter && other.ktFunction === this.ktFunction
|
||||
override fun equals(other: Any?): Boolean = other === this ||
|
||||
other is KtUltraLightSuspendContinuationParameter &&
|
||||
other.ktFunction === this.ktFunction
|
||||
|
||||
override fun isVarArgs(): Boolean = false
|
||||
override fun hashCode(): Int = name.hashCode()
|
||||
@@ -80,7 +81,7 @@ internal abstract class KtUltraLightParameter(
|
||||
override val kotlinOrigin: KtParameter?,
|
||||
protected val support: KtUltraLightSupport,
|
||||
private val ultraLightMethod: KtUltraLightMethod
|
||||
) : org.jetbrains.kotlin.asJava.elements.LightParameter(
|
||||
) : LightParameter(
|
||||
name,
|
||||
PsiType.NULL,
|
||||
ultraLightMethod,
|
||||
@@ -129,10 +130,12 @@ internal abstract class KtUltraLightParameter(
|
||||
override fun getContainingFile(): PsiFile = method.containingFile
|
||||
override fun getParent(): PsiElement = method.parameterList
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is KtUltraLightParameter && other.kotlinOrigin == this.kotlinOrigin
|
||||
override fun equals(other: Any?): Boolean = other === this ||
|
||||
other is KtUltraLightParameter &&
|
||||
other.javaClass == this.javaClass &&
|
||||
other.ultraLightMethod == this.ultraLightMethod
|
||||
|
||||
override fun hashCode(): Int = kotlinOrigin.hashCode()
|
||||
override fun hashCode(): Int = name.hashCode()
|
||||
|
||||
abstract override fun isVarArgs(): Boolean
|
||||
}
|
||||
|
||||
+6
-18
@@ -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-2022 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
|
||||
@@ -58,11 +47,10 @@ sealed class KtLightFieldImpl<D : PsiField>(
|
||||
return this
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
this === other ||
|
||||
(other is KtLightFieldImpl<*> &&
|
||||
this.name == other.name &&
|
||||
this.containingClass == other.containingClass)
|
||||
override fun equals(other: Any?): Boolean = this === other ||
|
||||
other is KtLightFieldImpl<*> &&
|
||||
this.name == other.name &&
|
||||
this.containingClass == other.containingClass
|
||||
|
||||
override fun hashCode() = 31 * containingClass.hashCode() + name.hashCode()
|
||||
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@@ -153,13 +153,12 @@ open class KtLightMethodImpl protected constructor(
|
||||
override fun equals(other: Any?): Boolean = other === this ||
|
||||
other is KtLightMethodImpl &&
|
||||
other.javaClass == javaClass &&
|
||||
other.memberIndex == memberIndex &&
|
||||
other.containingClass == containingClass &&
|
||||
other.lightMemberOrigin == lightMemberOrigin &&
|
||||
other.dummyDelegate == dummyDelegate &&
|
||||
other.memberIndex == memberIndex
|
||||
other.dummyDelegate == dummyDelegate
|
||||
|
||||
override fun hashCode(): Int = name.hashCode()
|
||||
.times(31).plus(lightMemberOrigin.hashCode())
|
||||
.times(31).plus(containingClass.hashCode())
|
||||
.times(31).plus(memberIndex.hashCode())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user