[resolution] KotlinJavaPsiFacade: do not return classes with wrong ClassId

We shouldn't return from `findClass`/`findClasses` Java classes with
`ClassId` different from the requested one

^KT-62892
This commit is contained in:
Dmitrii Gridin
2024-01-03 20:08:43 +01:00
committed by Space Team
parent c6004874c1
commit 37ccf5d4f3
4 changed files with 29 additions and 32 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 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.
*/
@@ -81,8 +81,7 @@ abstract class FirJavaFacade(
private val statusExtensions = session.extensionService.statusTransformerExtensions
fun findClass(classId: ClassId, knownContent: ByteArray? = null): JavaClass? =
classFinder.findClass(JavaClassFinder.Request(classId, knownContent))
?.takeIf { it.classId == classId && !it.hasMetadataAnnotation() }
classFinder.findClass(JavaClassFinder.Request(classId, knownContent))?.takeUnless(JavaClass::hasMetadataAnnotation)
fun getPackage(fqName: FqName): FqName? =
packageCache.getValue(fqName)?.fqName