[LC] FakeFileForLightClass: drop stub access from equals/hashCode
^KT-57857 Fixed
This commit is contained in:
committed by
Space Team
parent
d0847f2519
commit
7d37bb1f78
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||||
import javax.swing.Icon
|
import javax.swing.Icon
|
||||||
|
|
||||||
abstract class KtLightClassForFacadeBase constructor(
|
abstract class KtLightClassForFacadeBase(
|
||||||
override val facadeClassFqName: FqName,
|
override val facadeClassFqName: FqName,
|
||||||
final override val files: Collection<KtFile>
|
final override val files: Collection<KtFile>
|
||||||
) : KtLightClassBase(files.first().manager), KtLightClassForFacade {
|
) : KtLightClassBase(files.first().manager), KtLightClassForFacade {
|
||||||
@@ -54,7 +54,7 @@ abstract class KtLightClassForFacadeBase constructor(
|
|||||||
private val packageClsFile by lazyPub {
|
private val packageClsFile by lazyPub {
|
||||||
FakeFileForLightClass(
|
FakeFileForLightClass(
|
||||||
firstFileInFacade,
|
firstFileInFacade,
|
||||||
lightClass = { this },
|
lightClass = this,
|
||||||
packageFqName = facadeClassFqName.parent()
|
packageFqName = facadeClassFqName.parent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ abstract class KtLightClassForScript(val script: KtScript) : KtLightClassBase(sc
|
|||||||
private val _containingFile by lazyPub {
|
private val _containingFile by lazyPub {
|
||||||
FakeFileForLightClass(
|
FakeFileForLightClass(
|
||||||
script.containingKtFile,
|
script.containingKtFile,
|
||||||
lightClass = { this },
|
lightClass = this,
|
||||||
packageFqName = fqName.parent(),
|
packageFqName = fqName.parent(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-13
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -31,9 +31,19 @@ import java.lang.ref.Reference
|
|||||||
|
|
||||||
open class FakeFileForLightClass(
|
open class FakeFileForLightClass(
|
||||||
val ktFile: KtFile,
|
val ktFile: KtFile,
|
||||||
private val lightClass: () -> KtLightClass,
|
private val lightClass: KtLightClass,
|
||||||
private val packageFqName: FqName = ktFile.packageFqName,
|
private val packageFqName: FqName = ktFile.packageFqName,
|
||||||
) : ClsFileImpl(ktFile.viewProvider) {
|
) : ClsFileImpl(ktFile.viewProvider) {
|
||||||
|
@Deprecated("A light class should be provided directly")
|
||||||
|
constructor(
|
||||||
|
ktFile: KtFile,
|
||||||
|
lightClass: () -> KtLightClass,
|
||||||
|
packageFqName: FqName = ktFile.packageFqName,
|
||||||
|
) : this(
|
||||||
|
ktFile = ktFile,
|
||||||
|
lightClass = lightClass(),
|
||||||
|
packageFqName = packageFqName,
|
||||||
|
)
|
||||||
|
|
||||||
override fun getVirtualFile(): VirtualFile =
|
override fun getVirtualFile(): VirtualFile =
|
||||||
ktFile.virtualFile ?: ktFile.originalFile.virtualFile ?: super.getVirtualFile()
|
ktFile.virtualFile ?: ktFile.originalFile.virtualFile ?: super.getVirtualFile()
|
||||||
@@ -49,7 +59,7 @@ open class FakeFileForLightClass(
|
|||||||
|
|
||||||
override fun getStub() = createFakeJavaFileStub()
|
override fun getStub() = createFakeJavaFileStub()
|
||||||
|
|
||||||
override fun getClasses() = arrayOf(lightClass())
|
override fun getClasses() = arrayOf(lightClass)
|
||||||
|
|
||||||
override fun getNavigationElement() = ktFile
|
override fun getNavigationElement() = ktFile
|
||||||
|
|
||||||
@@ -92,29 +102,24 @@ open class FakeFileForLightClass(
|
|||||||
// this should be equal to current compiler target language level
|
// this should be equal to current compiler target language level
|
||||||
override fun getLanguageLevel() = LanguageLevel.JDK_1_8
|
override fun getLanguageLevel() = LanguageLevel.JDK_1_8
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int = if (lightClass is KtLightClassForSourceDeclaration) ktFile.hashCode() else lightClass.hashCode()
|
||||||
val thisClass = lightClass()
|
|
||||||
if (thisClass is KtLightClassForSourceDeclaration) return ktFile.hashCode()
|
|
||||||
return thisClass.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is FakeFileForLightClass) return false
|
if (other !is FakeFileForLightClass) return false
|
||||||
val thisClass = lightClass()
|
|
||||||
val anotherClass = other.lightClass()
|
|
||||||
|
|
||||||
if (thisClass is KtLightClassForSourceDeclaration) {
|
val anotherClass = other.lightClass
|
||||||
|
if (lightClass is KtLightClassForSourceDeclaration) {
|
||||||
return anotherClass is KtLightClassForSourceDeclaration && ktFile == other.ktFile
|
return anotherClass is KtLightClassForSourceDeclaration && ktFile == other.ktFile
|
||||||
}
|
}
|
||||||
|
|
||||||
return thisClass == anotherClass
|
return lightClass == anotherClass
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isEquivalentTo(another: PsiElement?) = this == another
|
override fun isEquivalentTo(another: PsiElement?) = this == another
|
||||||
|
|
||||||
override fun setPackageName(packageName: String) {
|
override fun setPackageName(packageName: String) {
|
||||||
if (lightClass() is KtLightClassForFacade) {
|
if (lightClass is KtLightClassForFacade) {
|
||||||
ktFile.packageDirective?.fqName = FqName(packageName)
|
ktFile.packageDirective?.fqName = FqName(packageName)
|
||||||
} else {
|
} else {
|
||||||
super.setPackageName(packageName)
|
super.setPackageName(packageName)
|
||||||
|
|||||||
+3
-7
@@ -10,16 +10,13 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.ResolveState
|
import com.intellij.psi.ResolveState
|
||||||
import com.intellij.psi.scope.PsiScopeProcessor
|
import com.intellij.psi.scope.PsiScopeProcessor
|
||||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||||
import org.jetbrains.kotlin.asJava.classes.getOutermostClassOrObject
|
|
||||||
import org.jetbrains.kotlin.asJava.elements.FakeFileForLightClass
|
import org.jetbrains.kotlin.asJava.elements.FakeFileForLightClass
|
||||||
import org.jetbrains.kotlin.asJava.toLightClass
|
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
|
||||||
internal class SymbolFakeFile(private val classOrObject: KtClassOrObject, ktClass: KtLightClass) : FakeFileForLightClass(
|
internal class SymbolFakeFile(classOrObject: KtClassOrObject, ktClass: KtLightClass) : FakeFileForLightClass(
|
||||||
classOrObject.containingKtFile,
|
classOrObject.containingKtFile,
|
||||||
{ if (classOrObject.isTopLevel()) ktClass else getOutermostClassOrObject(classOrObject).toLightClass()!! },
|
ktClass,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun findReferenceAt(offset: Int) = ktFile.findReferenceAt(offset)
|
override fun findReferenceAt(offset: Int) = ktFile.findReferenceAt(offset)
|
||||||
|
|
||||||
override fun processDeclarations(
|
override fun processDeclarations(
|
||||||
@@ -34,8 +31,7 @@ internal class SymbolFakeFile(private val classOrObject: KtClassOrObject, ktClas
|
|||||||
// so that Java resolve can find classes located in that package
|
// so that Java resolve can find classes located in that package
|
||||||
val packageName = packageName
|
val packageName = packageName
|
||||||
if (packageName.isNotEmpty()) return true
|
if (packageName.isNotEmpty()) return true
|
||||||
|
val aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName)
|
||||||
val aPackage = JavaPsiFacade.getInstance(classOrObject.project).findPackage(packageName)
|
|
||||||
if (aPackage != null && !aPackage.processDeclarations(processor, state, null, place)) return false
|
if (aPackage != null && !aPackage.processDeclarations(processor, state, null, place)) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
+1
-1
@@ -144,7 +144,7 @@ internal class SymbolLightClassForFacade(
|
|||||||
|
|
||||||
private val packageClsFile = FakeFileForLightClass(
|
private val packageClsFile = FakeFileForLightClass(
|
||||||
firstFileInFacade,
|
firstFileInFacade,
|
||||||
lightClass = { this },
|
lightClass = this,
|
||||||
packageFqName = facadeClassFqName.parent()
|
packageFqName = facadeClassFqName.parent()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -117,10 +117,8 @@ abstract class KtLightClassImpl(
|
|||||||
abstract override fun copy(): PsiElement
|
abstract override fun copy(): PsiElement
|
||||||
|
|
||||||
private val _containingFile: PsiFile by lazyPub {
|
private val _containingFile: PsiFile by lazyPub {
|
||||||
object : FakeFileForLightClass(
|
val lightClass = if (classOrObject.isTopLevel()) this else getOutermostClassOrObject(classOrObject).toLightClass()!!
|
||||||
classOrObject.containingKtFile,
|
object : FakeFileForLightClass(classOrObject.containingKtFile, lightClass) {
|
||||||
{ if (classOrObject.isTopLevel()) this else getOutermostClassOrObject(classOrObject).toLightClass()!! },
|
|
||||||
) {
|
|
||||||
override fun findReferenceAt(offset: Int) = ktFile.findReferenceAt(offset)
|
override fun findReferenceAt(offset: Int) = ktFile.findReferenceAt(offset)
|
||||||
|
|
||||||
override fun processDeclarations(
|
override fun processDeclarations(
|
||||||
|
|||||||
Reference in New Issue
Block a user