FIR: Check relativeClassName of found class in JavaSymbolProvider
`ClassId` denotes how class is nested; however, you can find `foo/bar/Outer.Nested` class by `ClassId(foo/bar/Outer/Nested)`. This will lead to inconsistencies when working with class symbol later This is also important to `FirQualifierResolverImpl::resolveSymbol` which detects correct `ClassId` by traversing all symbol qualifiers We check only `relativeClassName`, because we want to be able to find classes without package specified Also, fix test data of resolve tests that have been passing because of check absence
This commit is contained in:
@@ -134,9 +134,9 @@ class JavaSymbolProvider(
|
||||
classId,
|
||||
{
|
||||
val foundClass = findClass(classId, content)
|
||||
if (foundClass == null || foundClass.annotations.any {
|
||||
it.classId?.asSingleFqName() == JvmAnnotationNames.METADATA_FQ_NAME
|
||||
}
|
||||
if (foundClass == null ||
|
||||
foundClass.hasDifferentRelativeClassName(classId) ||
|
||||
foundClass.hasMetadataAnnotation()
|
||||
) {
|
||||
null to null
|
||||
} else {
|
||||
@@ -148,6 +148,16 @@ 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.hasMetadataAnnotation(): Boolean =
|
||||
annotations.any { it.classId?.asSingleFqName() == JvmAnnotationNames.METADATA_FQ_NAME }
|
||||
|
||||
private class ValueParametersForAnnotationConstructor {
|
||||
val valueParameters: MutableList<FirJavaValueParameter> = mutableListOf()
|
||||
var valueParameterForValue: FirJavaValueParameter? = null
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// RUNTIME
|
||||
|
||||
class: java.lang.String
|
||||
class: java/lang/String
|
||||
|
||||
// SYMBOLS:
|
||||
KtFirClassOrObjectSymbol:
|
||||
annotations: []
|
||||
classIdIfNonLocal: java.lang.String
|
||||
classIdIfNonLocal: java/lang/String
|
||||
classKind: CLASS
|
||||
companionObject: null
|
||||
isInner: true
|
||||
isInner: false
|
||||
modality: FINAL
|
||||
name: String
|
||||
origin: JAVA
|
||||
primaryConstructor: null
|
||||
superTypes: [[] kotlin/Any, [] java/io/Serializable, [] kotlin/Comparable<ft<@FlexibleNullability kotlin/String, kotlin/String?>!>, [] kotlin/CharSequence]
|
||||
symbolKind: MEMBER
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
visibility: PUBLIC
|
||||
|
||||
Reference in New Issue
Block a user