diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-06-05 09:07:20 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-06-10 10:52:43 +0200 |
commit | e9fd8b7bc00491b50e4822acc82e5615ab0bde3b (patch) | |
tree | 27648e766764df986a154e6c3353d634d219c0bc /core | |
parent | 77c8777b7f66bddd374d68decd507547d356d602 (diff) | |
download | dokka-e9fd8b7bc00491b50e4822acc82e5615ab0bde3b.tar.gz dokka-e9fd8b7bc00491b50e4822acc82e5615ab0bde3b.tar.bz2 dokka-e9fd8b7bc00491b50e4822acc82e5615ab0bde3b.zip |
Implement `reportUndocumented` option to report undocumented code
Diffstat (limited to 'core')
-rw-r--r-- | core/build.gradle.kts | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/DokkaBootstrapImpl.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/DokkaGenerator.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/configuration.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/defaultConfiguration.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/links/DRI.kt | 35 | ||||
-rw-r--r-- | core/src/main/kotlin/model/Documentable.kt | 11 | ||||
-rw-r--r-- | core/src/test/kotlin/model/DocumentableTest.kt | 108 |
8 files changed, 145 insertions, 19 deletions
diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 14718cfe..1d61e410 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -16,7 +16,7 @@ dependencies { implementation("org.jsoup:jsoup:1.12.1") testImplementation(project(":testApi")) - testImplementation("junit:junit:4.13") + testImplementation(kotlin("test-junit")) } val sourceJar by tasks.registering(Jar::class) { diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index 56e837fc..d39ee1d5 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -17,7 +17,7 @@ fun parsePerPackageOptions(arg: String): List<PackageOptions> { throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead") val args = it.subList(1, it.size) val deprecated = args.find { it.endsWith("deprecated") }?.startsWith("+") ?: true - val reportUndocumented = args.find { it.endsWith("warnUndocumented") }?.startsWith("+") ?: true + val reportUndocumented = args.find { it.endsWith("reportUndocumented") }?.startsWith("+") ?: true val privateApi = args.find { it.endsWith("privateApi") }?.startsWith("+") ?: false val suppress = args.find { it.endsWith("suppress") }?.startsWith("+") ?: false PackageOptionsImpl( diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 7f90fe9a..61fb7324 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -146,7 +146,7 @@ class DokkaGenerator( } pass.classpath.forEach { addClasspath(File(it)) } - addSources((pass.sourceRoots + pass.dependentSourceRoots).map { it.path }) + addSources((pass.sourceRoots + pass.dependentSourceRoots).map { it.path }) loadLanguageVersionSettings(pass.languageVersion, pass.apiVersion) diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index c38d0234..0b59f301 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -83,7 +83,7 @@ interface DokkaConfiguration { interface PackageOptions { val prefix: String val includeNonPublic: Boolean - val reportUndocumented: Boolean + val reportUndocumented: Boolean? val skipDeprecated: Boolean val suppress: Boolean } diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index acfa55d4..7aaa1c89 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -73,7 +73,7 @@ data class SourceLinkDefinitionImpl( data class PackageOptionsImpl( override val prefix: String, override val includeNonPublic: Boolean, - override val reportUndocumented: Boolean, + override val reportUndocumented: Boolean?, override val skipDeprecated: Boolean, override val suppress: Boolean ): DokkaConfiguration.PackageOptions diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt index 1c823d92..9cc51fb7 100644 --- a/core/src/main/kotlin/links/DRI.kt +++ b/core/src/main/kotlin/links/DRI.kt @@ -38,12 +38,13 @@ data class DRI( } fun from(psi: PsiElement) = psi.parentsWithSelf.run { - val callable = firstIsInstanceOrNull<PsiMethod>() + val psiMethod = firstIsInstanceOrNull<PsiMethod>() + val psiField = firstIsInstanceOrNull<PsiField>() val classes = filterIsInstance<PsiClass>().toList() DRI( classes.lastOrNull()?.qualifiedName?.substringBeforeLast('.', ""), classes.toList().takeIf { it.isNotEmpty() }?.asReversed()?.mapNotNull { it.name }?.joinToString("."), - callable?.let { Callable.from(it) }, + psiMethod?.let { Callable.from(it) } ?: psiField?.let { Callable.from(it) } , DriTarget.from(psi) ) } @@ -85,12 +86,21 @@ data class Callable( valueParameters.mapNotNull { TypeReference.from(it) } ) } + fun from(psi: PsiMethod) = with(psi) { Callable( name, null, parameterList.parameters.map { param -> JavaClassReference(param.type.canonicalText) }) } + + fun from(psi: PsiField): Callable { + return Callable( + name = psi.name, + receiver = null, + params = emptyList() + ) + } } } @@ -169,11 +179,12 @@ sealed class DriTarget { companion object { fun from(descriptor: DeclarationDescriptor): DriTarget = descriptor.parentsWithSelf.run { - return when(descriptor){ + return when (descriptor) { is TypeParameterDescriptor -> PointingToGenericParameters(descriptor.index) else -> { val callable = firstIsInstanceOrNull<CallableDescriptor>() - val params = callable?.let { listOfNotNull(it.extensionReceiverParameter) + it.valueParameters }.orEmpty() + val params = + callable?.let { listOfNotNull(it.extensionReceiverParameter) + it.valueParameters }.orEmpty() val parameterDescriptor = firstIsInstanceOrNull<ParameterDescriptor>() parameterDescriptor?.let { PointingToCallableParameters(params.indexOf(it)) } @@ -183,7 +194,7 @@ sealed class DriTarget { } fun from(psi: PsiElement): DriTarget = psi.parentsWithSelf.run { - return when(psi) { + return when (psi) { is PsiTypeParameter -> PointingToGenericParameters(psi.index) else -> firstIsInstanceOrNull<PsiParameter>()?.let { val callable = firstIsInstanceOrNull<PsiMethod>() @@ -199,15 +210,15 @@ data class PointingToGenericParameters(val parameterIndex: Int) : DriTarget() { override fun toString(): String = "PointingToGenericParameters($parameterIndex)" } -object PointingToDeclaration: DriTarget() +object PointingToDeclaration : DriTarget() -data class PointingToCallableParameters(val parameterIndex: Int): DriTarget(){ +data class PointingToCallableParameters(val parameterIndex: Int) : DriTarget() { override fun toString(): String = "PointingToCallableParameters($parameterIndex)" } -fun DriTarget.nextTarget(): DriTarget = when(this){ - is PointingToGenericParameters -> PointingToGenericParameters(this.parameterIndex+1) - is PointingToCallableParameters -> PointingToCallableParameters(this.parameterIndex+1) - else -> this - } +fun DriTarget.nextTarget(): DriTarget = when (this) { + is PointingToGenericParameters -> PointingToGenericParameters(this.parameterIndex + 1) + is PointingToCallableParameters -> PointingToCallableParameters(this.parameterIndex + 1) + else -> this +} diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index a7dd0919..c4dabb3b 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -1,8 +1,6 @@ package org.jetbrains.dokka.model import com.intellij.psi.PsiNamedElement -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.Platform import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.properties.PropertyContainer @@ -378,6 +376,15 @@ fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() } +fun Documentable.withDescendants(): Sequence<Documentable> { + return sequence { + yield(this@withDescendants) + children.forEach { child -> + yieldAll(child.withDescendants()) + } + } +} + sealed class Visibility(val name: String) sealed class KotlinVisibility(name: String) : Visibility(name) { object Public : KotlinVisibility("public") diff --git a/core/src/test/kotlin/model/DocumentableTest.kt b/core/src/test/kotlin/model/DocumentableTest.kt new file mode 100644 index 00000000..e3031a50 --- /dev/null +++ b/core/src/test/kotlin/model/DocumentableTest.kt @@ -0,0 +1,108 @@ +package model + +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.properties.PropertyContainer +import kotlin.test.Test +import kotlin.test.assertEquals + +class DocumentableTest { + + @Test + fun withDescendents() { + val dClass = DClass( + dri = DRI(), + name = "TestClass", + constructors = emptyList(), + classlikes = emptyList(), + companion = null, + documentation = emptyMap(), + expectPresentInSet = null, + extra = PropertyContainer.empty(), + visibility = emptyMap(), + generics = emptyList(), + modifier = emptyMap(), + properties = emptyList(), + sources = emptyMap(), + sourceSets = emptyList(), + supertypes = emptyMap(), + functions = listOf( + DFunction( + dri = DRI(), + name = "function0", + documentation = emptyMap(), + expectPresentInSet = null, + extra = PropertyContainer.empty(), + visibility = emptyMap(), + generics = emptyList(), + modifier = emptyMap(), + sources = emptyMap(), + sourceSets = emptyList(), + type = Void, + receiver = null, + isConstructor = false, + parameters = listOf( + DParameter( + dri = DRI(), + name = "f0p0", + documentation = emptyMap(), + expectPresentInSet = null, + extra = PropertyContainer.empty(), + sourceSets = emptyList(), + type = Void + ), + DParameter( + dri = DRI(), + name = "f0p1", + documentation = emptyMap(), + expectPresentInSet = null, + extra = PropertyContainer.empty(), + sourceSets = emptyList(), + type = Void + ) + ) + ), + DFunction( + dri = DRI(), + name = "function1", + documentation = emptyMap(), + expectPresentInSet = null, + extra = PropertyContainer.empty(), + visibility = emptyMap(), + generics = emptyList(), + modifier = emptyMap(), + sources = emptyMap(), + sourceSets = emptyList(), + type = Void, + receiver = null, + isConstructor = false, + parameters = listOf( + DParameter( + dri = DRI(), + name = "f1p0", + documentation = emptyMap(), + expectPresentInSet = null, + extra = PropertyContainer.empty(), + sourceSets = emptyList(), + type = Void + ), + DParameter( + dri = DRI(), + name = "f1p1", + documentation = emptyMap(), + expectPresentInSet = null, + extra = PropertyContainer.empty(), + sourceSets = emptyList(), + type = Void + ) + ) + ) + ) + ) + + assertEquals( + listOf("TestClass", "function0", "f0p0", "f0p1", "function1", "f1p0", "f1p1"), + dClass.withDescendants().map { it.name }.toList() + ) + } +}
\ No newline at end of file |