diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-02-26 13:41:31 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-03-04 13:39:48 +0100 |
commit | 5a02fd66982b92984f76eaaca16ba6045f55ff31 (patch) | |
tree | d2e8820cf4066aef813ec74b1aeb14cbe264e7e8 /plugins/base/src/main | |
parent | bc55869d707e5abafbf8544b5f519e003a504ac6 (diff) | |
download | dokka-5a02fd66982b92984f76eaaca16ba6045f55ff31.tar.gz dokka-5a02fd66982b92984f76eaaca16ba6045f55ff31.tar.bz2 dokka-5a02fd66982b92984f76eaaca16ba6045f55ff31.zip |
Replace Visibility used in Documentables with custom classes
Diffstat (limited to 'plugins/base/src/main')
2 files changed, 25 insertions, 15 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/transformers/psi/DefaultPsiToDocumentableTranslator.kt index 1001ffb3..6146ce5f 100644 --- a/plugins/base/src/main/kotlin/transformers/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/transformers/psi/DefaultPsiToDocumentableTranslator.kt @@ -61,11 +61,12 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { private fun PsiModifierListOwner.getVisibility() = modifierList?.children?.toList()?.let { ml -> when { - ml.any { it.text == PsiKeyword.PUBLIC } -> Visibilities.PUBLIC - ml.any { it.text == PsiKeyword.PROTECTED } -> Visibilities.PROTECTED - else -> Visibilities.PRIVATE + ml.any { it.text == PsiKeyword.PUBLIC } -> JavaVisibility.Public + ml.any { it.text == PsiKeyword.PROTECTED } -> JavaVisibility.Protected + ml.any { it.text == PsiKeyword.PRIVATE } -> JavaVisibility.Private + else -> JavaVisibility.Default } - } ?: Visibilities.PRIVATE + } ?: JavaVisibility.Default private val PsiMethod.hash: Int get() = "$returnType $name$parameterList".hashCode() diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index cea408d7..83d3d178 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -16,6 +16,7 @@ import org.jetbrains.dokka.transformers.descriptors.DescriptorToDocumentableTran import org.jetbrains.kotlin.codegen.isJvmStaticInObjectOrClassOrInterface import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies import org.jetbrains.kotlin.idea.kdoc.findKDoc import org.jetbrains.kotlin.idea.refactoring.fqName.fqName @@ -103,7 +104,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = descriptor.createSources(), - visibility = PlatformDependent.from(platformData, descriptor.visibility), + visibility = PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), supertypes = PlatformDependent.from(platformData, info.supertypes), documentation = info.docs, generics = descriptor.typeConstructor.parameters.map { it.toTypeParameter() }, @@ -125,7 +126,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = descriptor.createSources(), - visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), + visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), supertypes = PlatformDependent.from(platformData, info.supertypes), documentation = info.docs, platformData = listOf(platformData), @@ -147,7 +148,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = descriptor.createSources(), - visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), + visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), supertypes = PlatformDependent.from(platformData, info.supertypes), documentation = info.docs, companion = descriptor.companion(driWithPlatform), @@ -192,7 +193,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = actual, - visibility = PlatformDependent.from(platformData, descriptor.visibility), + visibility = PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), generics = descriptor.typeConstructor.parameters.map { it.toTypeParameter() }, documentation = info.docs, modifier = descriptor.modifier(), @@ -215,12 +216,12 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private }, sources = actual, getter = descriptor.accessors.filterIsInstance<PropertyGetterDescriptor>().singleOrNull()?.let { - visitPropertyAccessorDescriptor(it, descriptor, dri) + visitPropertyAccessorDescriptor(it, descriptor, dri) }!!, setter = descriptor.accessors.filterIsInstance<PropertySetterDescriptor>().singleOrNull()?.let { - visitPropertyAccessorDescriptor(it, descriptor, dri) + visitPropertyAccessorDescriptor(it, descriptor, dri) }, - visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), + visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), documentation = descriptor.resolveDescriptorData(platformData), modifier = descriptor.modifier(), type = KotlinTypeWrapper(descriptor.returnType!!), @@ -244,7 +245,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private parameter(index, desc, DRIWithPlatformInfo(dri, actual)) }, sources = actual, - visibility = PlatformDependent.from(platformData, descriptor.visibility), + visibility = PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), generics = descriptor.typeParameters.map { it.toTypeParameter() }, documentation = descriptor.resolveDescriptorData(platformData), modifier = descriptor.modifier(), @@ -268,7 +269,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private parameter(index, desc, DRIWithPlatformInfo(dri, actual)) }, sources = actual, - visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), + visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), documentation = descriptor.resolveDescriptorData(platformData), type = KotlinTypeWrapper(descriptor.returnType), modifier = descriptor.modifier(), @@ -325,7 +326,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private name, isConstructor = false, parameters = parameters, - visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), + visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), documentation = descriptor.resolveDescriptorData(platformData), type = KotlinTypeWrapper(descriptor.returnType!!), generics = descriptor.typeParameters.map { it.toTypeParameter() }, @@ -431,7 +432,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private else -> WithAbstraction.Modifier.Empty } - private fun MemberDescriptor.createSources(): PlatformDependent<DocumentableSource> = if(isExpect()) { + private fun MemberDescriptor.createSources(): PlatformDependent<DocumentableSource> = if (isExpect()) { PlatformDependent(emptyMap(), DescriptorDocumentableSource(this)) } else { PlatformDependent(mapOf(platformData to DescriptorDocumentableSource(this))) @@ -489,4 +490,12 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private container + AdditionalModifiers(this) data class ClassInfo(val supertypes: List<DRI>, val docs: PlatformDependent<DocumentationNode>) + + private fun Visibility.toDokkaVisibility(): org.jetbrains.dokka.model.Visibility = when (this) { + Visibilities.PUBLIC -> KotlinVisibility.Public + Visibilities.PROTECTED -> KotlinVisibility.Protected + Visibilities.INTERNAL -> KotlinVisibility.Internal + Visibilities.PRIVATE -> KotlinVisibility.Private + else -> KotlinVisibility.Public + } } |