diff options
author | Vadim Mishenev <vad-mishenev@yandex.ru> | 2023-10-10 12:36:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-10 12:36:34 +0300 |
commit | 562a5951ca942c0bd26d839f2ebf509b43ca3c59 (patch) | |
tree | ba9dc75e93dc7d95c9114072946389e86f35f220 /subprojects/analysis-kotlin-symbols/src/main | |
parent | 7503402e8b9c885ecaf27a927b66d327aea5bb14 (diff) | |
download | dokka-562a5951ca942c0bd26d839f2ebf509b43ca3c59.tar.gz dokka-562a5951ca942c0bd26d839f2ebf509b43ca3c59.tar.bz2 dokka-562a5951ca942c0bd26d839f2ebf509b43ca3c59.zip |
[K2] Display enum entry members (#3180)
Diffstat (limited to 'subprojects/analysis-kotlin-symbols/src/main')
-rw-r--r-- | subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt index 4e741d09..f217c88f 100644 --- a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt +++ b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt @@ -343,7 +343,30 @@ internal class DokkaSymbolVisitor( KtClassKind.ANONYMOUS_OBJECT -> throw NotImplementedError("ANONYMOUS_OBJECT does not support") KtClassKind.ENUM_CLASS -> { - val entries = namedClassOrObjectSymbol.getEnumEntries().map { visitEnumEntrySymbol(it) } + /** + * See https://github.com/Kotlin/dokka/issues/3129 + * + * e.g. the `A` enum entry in the `enum E` is + * ``` + * static val A: E = object : E() { + * val x: Int = 5 + * } + * ``` + * it needs to exclude all static members like `values` and `valueOf` from the enum class's scope + */ + val enumEntryScope = lazy { + getDokkaScopeFrom(namedClassOrObjectSymbol, dri, includeStaticScope = false).let { + it.copy( + functions = it.functions.map { it.withNewExtras( it.extra + InheritedMember(dri.copy(callable = null).toSourceSetDependent())) }, + properties = it.properties.map { it.withNewExtras( it.extra + InheritedMember(dri.copy(callable = null).toSourceSetDependent())) } + ) + } + } + + val entries = + namedClassOrObjectSymbol.getEnumEntries().map { + visitEnumEntrySymbol(it, enumEntryScope.value) + } DEnum( dri = dri, @@ -383,12 +406,17 @@ internal class DokkaSymbolVisitor( val properties: List<DProperty>, val classlikes: List<DClasslike> ) + + /** + * @param includeStaticScope flag to add static members, e.g. `valueOf`, `values` and `entries` members for Enum + */ private fun KtAnalysisSession.getDokkaScopeFrom( namedClassOrObjectSymbol: KtNamedClassOrObjectSymbol, - dri: DRI + dri: DRI, + includeStaticScope: Boolean = true ): DokkaScope { // e.g. getStaticMemberScope contains `valueOf`, `values` and `entries` members for Enum - val scope = listOf(namedClassOrObjectSymbol.getMemberScope(), namedClassOrObjectSymbol.getStaticMemberScope()).asCompositeScope() + val scope = if(includeStaticScope) listOf(namedClassOrObjectSymbol.getMemberScope(), namedClassOrObjectSymbol.getStaticMemberScope()).asCompositeScope() else namedClassOrObjectSymbol.getMemberScope() val constructors = scope.getConstructors().map { visitConstructorSymbol(it) }.toList() val callables = scope.getCallableSymbols().toList() @@ -453,28 +481,18 @@ internal class DokkaSymbolVisitor( } private fun KtAnalysisSession.visitEnumEntrySymbol( - enumEntrySymbol: KtEnumEntrySymbol + enumEntrySymbol: KtEnumEntrySymbol, scope: DokkaScope ): DEnumEntry = withExceptionCatcher(enumEntrySymbol) { val dri = getDRIFromEnumEntry(enumEntrySymbol) val isExpect = false - val scope = enumEntrySymbol.getMemberScope() - val callables = scope.getCallableSymbols().toList() - val classifiers = scope.getClassifierSymbols().toList() - - val functions = callables.filterIsInstance<KtFunctionSymbol>().map { visitFunctionSymbol(it, dri) } - val properties = callables.filterIsInstance<KtPropertySymbol>().map { visitPropertySymbol(it, dri) } - val classlikes = - classifiers.filterIsInstance<KtNamedClassOrObjectSymbol>() - .map { visitNamedClassOrObjectSymbol(it, dri) } - return DEnumEntry( dri = dri, name = enumEntrySymbol.name.asString(), documentation = getDocumentation(enumEntrySymbol)?.toSourceSetDependent() ?: emptyMap(), - functions = functions, - properties = properties, - classlikes = classlikes, + functions = scope.functions, + properties = scope.properties, + classlikes = emptyList(), // always empty, see https://github.com/Kotlin/dokka/issues/3129 sourceSets = setOf(sourceSet), expectPresentInSet = sourceSet.takeIf { isExpect }, extra = PropertyContainer.withAll( |