aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/model/Documentable.kt18
-rw-r--r--plugins/base/src/main/kotlin/transformers/psi/DefaultPsiToDocumentableTranslator.kt9
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt31
-rw-r--r--plugins/base/src/test/kotlin/model/ClassesTest.kt12
-rw-r--r--plugins/base/src/test/kotlin/model/PropertyTest.kt6
5 files changed, 49 insertions, 27 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index 9de06ba7..c16f8a87 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -7,7 +7,6 @@ import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
-import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.load.kotlin.toSourceElement
abstract class Documentable {
@@ -65,7 +64,7 @@ interface WithPackages {
}
interface WithVisibility {
- val visibility: PlatformDependent<Visibility> // TODO custom visibility
+ val visibility: PlatformDependent<Visibility>
}
interface WithType {
@@ -349,6 +348,21 @@ fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? =
this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
}
+sealed class Visibility
+sealed class KotlinVisibility : Visibility() {
+ object Public : KotlinVisibility()
+ object Private : KotlinVisibility()
+ object Protected : KotlinVisibility()
+ object Internal : KotlinVisibility()
+}
+
+sealed class JavaVisibility : Visibility() {
+ object Public : JavaVisibility()
+ object Private : JavaVisibility()
+ object Protected : JavaVisibility()
+ object Default : JavaVisibility()
+}
+
fun <T> PlatformDependent<T>?.orEmpty(): PlatformDependent<T> = this ?: PlatformDependent.empty()
sealed class DocumentableSource(val path: String)
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
+ }
}
diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt
index 18288442..a22bd775 100644
--- a/plugins/base/src/test/kotlin/model/ClassesTest.kt
+++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt
@@ -2,9 +2,7 @@ package model
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.Function
-import org.jetbrains.dokka.model.Object
import org.jetbrains.dokka.model.WithAbstraction.Modifier
-import org.jetbrains.kotlin.descriptors.Visibilities
import org.junit.Test
import utils.AbstractModelTest
import utils.assertNotNull
@@ -52,7 +50,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
children counts 4
with(constructors.firstOrNull().assertNotNull("Constructor")) {
- visibility.values allEquals Visibilities.PUBLIC
+ visibility.values allEquals KotlinVisibility.Public
parameters counts 1
with(parameters.firstOrNull().assertNotNull("Constructor parameter")) {
name equals "name"
@@ -80,7 +78,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
with((this / "fn").cast<Function>()) {
type.constructorFqName equals "kotlin.Unit"
parameters counts 0
- visibility.values allEquals Visibilities.PUBLIC
+ visibility.values allEquals KotlinVisibility.Public
}
}
}
@@ -150,7 +148,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
) {
with((this / "classes" / "Klass").cast<Class>()) {
name equals "Klass"
- visibility.values allEquals Visibilities.PUBLIC
+ visibility.values allEquals KotlinVisibility.Public
with(extra[AdditionalModifiers.AdditionalKey].assertNotNull("Extras")) {
content.find{it == ExtraModifiers.DATA}.assertNotNull("data modifier")
}
@@ -174,7 +172,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
) {
with((this / "classes" / "Klass").cast<Class>()) {
name equals "Klass"
- modifier equals WithAbstraction.Modifier.Sealed
+ modifier equals Modifier.Sealed
}
}
}
@@ -391,7 +389,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
with((this / "Companion").cast<Object>()) {
name equals "Companion"
- visibility.values allEquals Visibilities.PRIVATE
+ visibility.values allEquals KotlinVisibility.Private
with((this / "fn").cast<Function>()) {
name equals "fn"
diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt
index 633796e7..e4ef0aec 100644
--- a/plugins/base/src/test/kotlin/model/PropertyTest.kt
+++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt
@@ -1,8 +1,8 @@
package model
+import org.jetbrains.dokka.model.KotlinVisibility
import org.jetbrains.dokka.model.Package
import org.jetbrains.dokka.model.Property
-import org.jetbrains.kotlin.descriptors.Visibilities
import org.junit.Test
import utils.AbstractModelTest
import utils.assertNotNull
@@ -80,7 +80,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro
with(getter.assertNotNull("Getter")) {
type.constructorFqName equals "kotlin.String"
}
- visibility.values allEquals Visibilities.PUBLIC
+ visibility.values allEquals KotlinVisibility.Public
}
}
}
@@ -103,7 +103,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro
with(getter.assertNotNull("Getter")) {
type.constructorFqName equals "kotlin.Int"
}
- visibility.values allEquals Visibilities.PUBLIC
+ visibility.values allEquals KotlinVisibility.Public
}
}
}