FIR: do not provide symbols with different ClassId in JavaSymbolProvider

JavaSymbolProvider uses KotlinPsiElementFinderWrapper for finding classes.
CliFinder looks for Java classing assuming that class with ClassId=a/b/C
lives in directory a/b and do not look into real package name of Java class.
This causes that we may find some classes which we should not see from current scope.

Also, the IDE implementation works correctly here (it also checks file package)
which cause different behaviour of FIR IDE and FIR

This change also requires to fix testdata and make Java classes live
in directory consistent with file package
This commit is contained in:
Ilya Kirillov
2021-04-12 15:54:20 +02:00
committed by TeamCityServer
parent 82cadba80b
commit 39b2cd1027
7 changed files with 14 additions and 18 deletions
@@ -156,7 +156,7 @@ class JavaSymbolProvider(
): Pair<FirRegularClassSymbol?, JavaClass?> {
val foundClass = findClass(classId, content)
return if (foundClass == null ||
foundClass.hasDifferentRelativeClassName(classId) ||
foundClass.hasDifferentClassId(classId) ||
foundClass.hasMetadataAnnotation()
) {
null to null
@@ -166,13 +166,8 @@ class JavaSymbolProvider(
}
}
/**
* We do not check the package because we can look for the class in the same package by class name without package specified.
* In this case, found [JavaClass] may have different `packageFqName`, but not `relativeClassName`.
*/
private fun JavaClass.hasDifferentRelativeClassName(lookupClassId: ClassId): Boolean =
classId?.relativeClassName != lookupClassId.relativeClassName
private fun JavaClass.hasDifferentClassId(lookupClassId: ClassId): Boolean =
classId != lookupClassId
private fun JavaClass.hasMetadataAnnotation(): Boolean =
annotations.any { it.classId?.asSingleFqName() == JvmAnnotationNames.METADATA_FQ_NAME }