Skip to content

Commit

Permalink
Fix displaying default java visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinAman committed Feb 16, 2021
1 parent fb016fb commit 77db620
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class BaseTestBuilder : TestBuilder<BaseTestMethods>() {
var pluginsSetupStage: (DokkaContext) -> Unit = {}
var verificationStage: (() -> Unit) -> Unit = {}
var documentablesCreationStage: (List<DModule>) -> Unit = {}
var documentablesFirstTransformationStep: (List<DModule>) -> Unit = {}
var preMergeDocumentablesTransformationStage: (List<DModule>) -> Unit = {}
var documentablesMergingStage: (DModule) -> Unit = {}
var documentablesTransformationStage: (DModule) -> Unit = {}
var pagesGenerationStage: (RootPageNode) -> Unit = {}
Expand All @@ -92,7 +92,7 @@ class BaseTestBuilder : TestBuilder<BaseTestMethods>() {
pluginsSetupStage,
verificationStage,
documentablesCreationStage,
documentablesFirstTransformationStep,
preMergeDocumentablesTransformationStage,
documentablesMergingStage,
documentablesTransformationStage,
pagesGenerationStage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
) {
fun Visibility.isAllowedInPackage(packageName: String?) = when (this) {
is JavaVisibility.Public,
is JavaVisibility.Default,
is KotlinVisibility.Public -> true
else -> packageName != null
&& packageOptions.firstOrNull { Regex(it.matchingRegex).matches(packageName) }?.includeNonPublic
Expand Down
10 changes: 5 additions & 5 deletions plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeprecationFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 1
)
Expand Down Expand Up @@ -59,7 +59,7 @@ class DeprecationFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 1
)
Expand Down Expand Up @@ -89,7 +89,7 @@ class DeprecationFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 0
)
Expand Down Expand Up @@ -128,7 +128,7 @@ class DeprecationFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 0
)
Expand Down Expand Up @@ -165,7 +165,7 @@ class DeprecationFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EmptyPackagesFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.isNotEmpty()
)
Expand Down Expand Up @@ -56,7 +56,7 @@ class EmptyPackagesFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = { modules ->
preMergeDocumentablesTransformationStage = { modules ->
modules.forEach { module ->
assertEquals(listOf("example"), module.packages.map { it.name })
}
Expand Down
110 changes: 110 additions & 0 deletions plugins/base/src/test/kotlin/filter/JavaVisibilityFilterTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package filter

import org.jetbrains.dokka.DokkaConfigurationImpl
import org.jetbrains.dokka.PackageOptionsImpl
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import testApi.testRunner.dokkaConfiguration
import kotlin.test.assertEquals

class JavaVisibilityFilterTest : BaseAbstractTest() {
@ParameterizedTest
@MethodSource(value = ["nonPublicPermutations", "publicPermutations"])
fun `should include package private java class`(configuration: ConfigurationWithVisibility) {
testInline(
"""
|/src/main/java/basic/VisibilityTest.java
|package basic;
|
|${configuration.visibilityKeyword} class VisibilityTest {
| static void test() {
|
| }
|}
""".trimMargin(),
configuration.configuration
) {
preMergeDocumentablesTransformationStage = {
assertEquals(configuration.expectedClasslikes, it.first().packages.first().classlikes.size)
}
}
}

data class ConfigurationWithVisibility(
val visibilityKeyword: String,
val configuration: DokkaConfigurationImpl,
val expectedClasslikes: Int
)

companion object TestDataSources {
val globalExcludes = dokkaConfiguration {
sourceSets {
sourceSet {
includeNonPublic = false
sourceRoots = listOf("src/")
}
}
}

val globalIncludes = dokkaConfiguration {
sourceSets {
sourceSet {
includeNonPublic = true
sourceRoots = listOf("src/")
}
}
}

val globalIncludesPackageExcludes = dokkaConfiguration {
sourceSets {
sourceSet {
includeNonPublic = true
sourceRoots = listOf("src/")
perPackageOptions = mutableListOf(
PackageOptionsImpl(
"basic",
false,
false,
false,
false
)
)
}
}
}

val globalExcludesPackageIncludes = dokkaConfiguration {
sourceSets {
sourceSet {
includeNonPublic = false
sourceRoots = listOf("src/")
perPackageOptions = mutableListOf(
PackageOptionsImpl(
"basic",
true,
false,
false,
false
)
)
}
}
}

@JvmStatic
fun nonPublicPermutations() = listOf("protected", "", "private").flatMap { keyword ->
listOf(globalIncludes, globalExcludesPackageIncludes).map { configuration ->
ConfigurationWithVisibility(keyword, configuration, expectedClasslikes = 1)
} + listOf(globalExcludes, globalExcludes).map { configuration ->
ConfigurationWithVisibility(keyword, configuration, expectedClasslikes = 0)
}
}

@JvmStatic
fun publicPermutations() =
listOf(globalIncludes, globalExcludesPackageIncludes, globalExcludes, globalExcludes).map { configuration ->
ConfigurationWithVisibility("public", configuration, expectedClasslikes = 1)
}
}
}
12 changes: 6 additions & 6 deletions plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VisibilityFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 1
)
Expand Down Expand Up @@ -62,7 +62,7 @@ class VisibilityFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 0
)
Expand Down Expand Up @@ -93,7 +93,7 @@ class VisibilityFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 1
)
Expand Down Expand Up @@ -133,7 +133,7 @@ class VisibilityFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 1
)
Expand Down Expand Up @@ -173,7 +173,7 @@ class VisibilityFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
Assertions.assertTrue(
it.first().packages.first().functions.size == 0
)
Expand Down Expand Up @@ -201,7 +201,7 @@ class VisibilityFilterTest : BaseAbstractTest() {
""".trimMargin(),
configuration
) {
documentablesFirstTransformationStep = {
preMergeDocumentablesTransformationStage = {
assertEquals(0, it.first().packages.first().typealiases.size)
}
}
Expand Down
25 changes: 8 additions & 17 deletions plugins/base/src/test/kotlin/model/ClassesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import utils.AbstractModelTest
import utils.assertNotNull
import utils.name
import utils.supers
import org.jetbrains.dokka.links.TypeConstructor


class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "classes") {
Expand Down Expand Up @@ -298,26 +299,13 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
|val Klass.Default.x: Int get() = 1
"""
) {
with((this / "classes" / "Klass").cast<DClass>()) {
name equals "Klass"

with((this / "Default").cast<DObject>()) {
name equals "Default"
// TODO extensions
}
with((this / "classes").cast<DPackage>()) {
properties.single().name equals "x"
(properties.single().receiver?.dri?.callable?.receiver as? TypeConstructor)?.fullyQualifiedName equals "classes.Klass.Default"
}
}
}

// @Test fun companionObjectExtension() {
// checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model ->
// val pkg = model.members.single()
// val cls = pkg.members.single { it.name == "Foo" }
// val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty }
// assertEquals(1, extensions.size)
// }
// }

@Test
fun secondaryConstructor() {
inlineModelTest(
Expand Down Expand Up @@ -426,7 +414,10 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
"""@Suppress("abc") class Foo() {}"""
) {
with((this / "classes" / "Foo").cast<DClass>()) {
with(extra[Annotations]?.directAnnotations?.values?.firstOrNull()?.firstOrNull().assertNotNull("annotations")) {
with(
extra[Annotations]?.directAnnotations?.values?.firstOrNull()?.firstOrNull()
.assertNotNull("annotations")
) {
dri.toString() equals "kotlin/Suppress///PointingToDeclaration/"
(params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("abc"))
}
Expand Down
Loading

0 comments on commit 77db620

Please sign in to comment.