[AA] Fix KDoc reference resolution of companion object members
- The nested scope construction in `getSymbolsFromMemberScope` was missing the companion object member scope. ^KTIJ-25995 fixed
This commit is contained in:
committed by
Space Team
parent
71792f9ad6
commit
0add17d9da
+18
-7
@@ -138,6 +138,13 @@ internal object KDocReferenceResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the [KtSymbol]s called [fqName] found in the member scope and companion object's member scope of the [KtDeclaration]s that
|
||||||
|
* contain the [contextElement].
|
||||||
|
*
|
||||||
|
* If [fqName] has two or more segments, e.g. `Foo.bar`, the member and companion object scope of the containing [KtDeclaration] will be
|
||||||
|
* queried for a class `Foo` first, and then that class `Foo` will be queried for the member `bar` by short name.
|
||||||
|
*/
|
||||||
context(KtAnalysisSession)
|
context(KtAnalysisSession)
|
||||||
private fun getSymbolsFromParentMemberScopes(fqName: FqName, contextElement: KtElement): Collection<KtSymbol> {
|
private fun getSymbolsFromParentMemberScopes(fqName: FqName, contextElement: KtElement): Collection<KtSymbol> {
|
||||||
for (ktDeclaration in contextElement.parentsOfType<KtDeclaration>(withSelf = true)) {
|
for (ktDeclaration in contextElement.parentsOfType<KtDeclaration>(withSelf = true)) {
|
||||||
@@ -147,10 +154,7 @@ internal object KDocReferenceResolver {
|
|||||||
if (ktDeclaration is KtClassOrObject) {
|
if (ktDeclaration is KtClassOrObject) {
|
||||||
val symbol = ktDeclaration.getClassOrObjectSymbol() ?: continue
|
val symbol = ktDeclaration.getClassOrObjectSymbol() ?: continue
|
||||||
|
|
||||||
val scope = listOfNotNull(
|
val scope = symbol.getCompositeCombinedMemberAndCompanionObjectScope()
|
||||||
symbol.getMemberScope(),
|
|
||||||
getCompanionObjectMemberScope(symbol),
|
|
||||||
).asCompositeScope()
|
|
||||||
|
|
||||||
val symbolsFromScope = getSymbolsFromMemberScope(fqName, scope)
|
val symbolsFromScope = getSymbolsFromMemberScope(fqName, scope)
|
||||||
if (symbolsFromScope.isNotEmpty()) return symbolsFromScope
|
if (symbolsFromScope.isNotEmpty()) return symbolsFromScope
|
||||||
@@ -160,8 +164,15 @@ internal object KDocReferenceResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context(KtAnalysisSession)
|
context(KtAnalysisSession)
|
||||||
private fun getCompanionObjectMemberScope(classSymbol: KtClassOrObjectSymbol): KtScope? {
|
private fun KtSymbolWithMembers.getCompositeCombinedMemberAndCompanionObjectScope(): KtScope =
|
||||||
val namedClassSymbol = classSymbol as? KtNamedClassOrObjectSymbol ?: return null
|
listOfNotNull(
|
||||||
|
getCombinedMemberScope(),
|
||||||
|
getCompanionObjectMemberScope(),
|
||||||
|
).asCompositeScope()
|
||||||
|
|
||||||
|
context(KtAnalysisSession)
|
||||||
|
private fun KtSymbolWithMembers.getCompanionObjectMemberScope(): KtScope? {
|
||||||
|
val namedClassSymbol = this as? KtNamedClassOrObjectSymbol ?: return null
|
||||||
val companionSymbol = namedClassSymbol.companionObject ?: return null
|
val companionSymbol = namedClassSymbol.companionObject ?: return null
|
||||||
return companionSymbol.getMemberScope()
|
return companionSymbol.getMemberScope()
|
||||||
}
|
}
|
||||||
@@ -192,7 +203,7 @@ internal object KDocReferenceResolver {
|
|||||||
currentScope
|
currentScope
|
||||||
.getClassifierSymbols(fqNamePart)
|
.getClassifierSymbols(fqNamePart)
|
||||||
.filterIsInstance<KtSymbolWithMembers>()
|
.filterIsInstance<KtSymbolWithMembers>()
|
||||||
.map { it.getCombinedMemberScope() }
|
.map { it.getCompositeCombinedMemberAndCompanionObjectScope() }
|
||||||
.toList()
|
.toList()
|
||||||
.asCompositeScope()
|
.asCompositeScope()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user