findKDoc¶
context(session: KaSession)
fun KtDeclaration.findKDoc(): KDocCommentDescriptor?
Resolves KDoc for this KtDeclaration.
This is part of a non-public API intended for use only by IDE and Dokka. Current implementation is based on the original findKDoc logic from Kotlin IDE Plugin.
KDocCommentDescriptor for the given KtDeclaration is resolved using the following algorithm:
-
KtDeclarationhas its own KDoc, i.e.KtDeclaration.getDocCommentreturns non-null value. In this case,KDocCommentDescriptor.primaryTagis the KDoc's default section andKDocCommentDescriptor.additionalSectionscontain all sections of that KDoc (including the default one). -
KtDeclarationdoes not have its own KDoc, but its documentation can be derived from its parent's KDoc. This rule is applied in four different cases: -
KtDeclarationis a primary constructor and the enclosing class KDoc has a@constructorsection. That section is used as KaKDocComment.primaryTag, and KaKDocComment.additionalSections contains the sections that include@paramtags from the class's KDoc.
-
KtDeclarationis a KtParameter of the primary constructor. KaKDocComment.primaryTag is resolved from the@propertyor@paramtags of the class's KDoc. KaKDocComment.additionalSections is empty. -
KtDeclarationis a KtParameter or KtTypeParameter. KaKDocComment.primaryTag is resolved from the@paramtags of the parent's KDoc. KaKDocComment.additionalSections is empty. -
KtDeclarationis a KtProperty that is declared inside a class/object with a KDoc, but referenced with a@propertytag in the class/object KDoc. KaKDocComment.primaryTag is the@propertytag, and KaKDocComment.additionalSections is empty. -
In all other cases this method returns
null
Notes:
-
KDoc for an element can be resolved whenever we have sources for it. Including external libraries.
-
This method only resolves KDoc for Kotlin elements. Java elements and Javadoc are not supported.
context(session: KaSession)
fun KaDeclarationSymbol.findKDoc(): KDocCommentDescriptor?
Resolves KDoc for this KaDeclarationSymbol.
This is part of a non-public API intended for use only by IDE and Dokka. Current implementation is based on the original findKDoc logic from Kotlin IDE Plugin.
KDocCommentDescriptor for the given KaDeclarationSymbol is resolved using the following algorithm:
-
Try resolving the KDoc of the symbol's PSI navigation element via
findKDoc. -
If the symbol is a callable, walk its overridden symbols (
KaCallableSymbol'sallOverriddenSymbols) in order and recursively callfindKDocon each of them. Return the first non-null result. -
Resolve the symbol's
expectdeclarations viagetExpectsForActual. Recursively callfindKDocon the first (non-null) element of the list. Return the first non-null result. -
In all other cases this method returns
null.
Notes:
-
In case of ambiguity, the first match is returned; if nothing is found,
nullis returned; -
KDoc for a
KaDeclarationSymbolcan only be resolved when it has a corresponding PSI element.
See also¶
findKDoc: for the implementation details.