diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-02-16 21:15:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-16 21:15:02 +0100 |
commit | 1c78ecebfb6fc2b24c64c13f7e85218b01a7a69b (patch) | |
tree | cbd27431b6ac40f74ef6526861fa8b2543741b7a /plugins/base/src/test/kotlin | |
parent | 116179e26a60d1b98d842ff6decc6119062475ae (diff) | |
download | dokka-1c78ecebfb6fc2b24c64c13f7e85218b01a7a69b.tar.gz dokka-1c78ecebfb6fc2b24c64c13f7e85218b01a7a69b.tar.bz2 dokka-1c78ecebfb6fc2b24c64c13f7e85218b01a7a69b.zip |
Fix displaying default java visibility (#1738)
Diffstat (limited to 'plugins/base/src/test/kotlin')
11 files changed, 175 insertions, 106 deletions
diff --git a/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt b/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt index ccb878d0..4431d383 100644 --- a/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt +++ b/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt @@ -29,7 +29,7 @@ class DeprecationFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 1 ) @@ -59,7 +59,7 @@ class DeprecationFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 1 ) @@ -89,7 +89,7 @@ class DeprecationFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 0 ) @@ -128,7 +128,7 @@ class DeprecationFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 0 ) @@ -165,7 +165,7 @@ class DeprecationFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 1 ) diff --git a/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt b/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt index 2a5a5dd5..58a8e5f1 100644 --- a/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt +++ b/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt @@ -27,7 +27,7 @@ class EmptyPackagesFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.isNotEmpty() ) @@ -56,7 +56,7 @@ class EmptyPackagesFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { modules -> + preMergeDocumentablesTransformationStage = { modules -> modules.forEach { module -> assertEquals(listOf("example"), module.packages.map { it.name }) } diff --git a/plugins/base/src/test/kotlin/filter/JavaVisibilityFilterTest.kt b/plugins/base/src/test/kotlin/filter/JavaVisibilityFilterTest.kt new file mode 100644 index 00000000..32c00e92 --- /dev/null +++ b/plugins/base/src/test/kotlin/filter/JavaVisibilityFilterTest.kt @@ -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) + } + } +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt index b0476b6e..416db52b 100644 --- a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt +++ b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt @@ -31,7 +31,7 @@ class VisibilityFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 1 ) @@ -62,7 +62,7 @@ class VisibilityFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 0 ) @@ -93,7 +93,7 @@ class VisibilityFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 1 ) @@ -133,7 +133,7 @@ class VisibilityFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 1 ) @@ -173,7 +173,7 @@ class VisibilityFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { Assertions.assertTrue( it.first().packages.first().functions.size == 0 ) @@ -201,7 +201,7 @@ class VisibilityFilterTest : BaseAbstractTest() { """.trimMargin(), configuration ) { - documentablesFirstTransformationStep = { + preMergeDocumentablesTransformationStage = { assertEquals(0, it.first().packages.first().typealiases.size) } } diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index 2260a46f..34857ad8 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -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") { @@ -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( @@ -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")) } diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index beb7c8e4..6220cc50 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -1,5 +1,6 @@ package model +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.JavaClassReference @@ -16,6 +17,16 @@ import utils.name import org.jetbrains.dokka.links.Callable as DRICallable class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + analysisPlatform = Platform.jvm.toString() + classpath += jvmStdlibPath!! + includeNonPublic = true + } + } + } @Test fun function() { @@ -29,7 +40,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { | */ | public void fn(String name, int value) {} |} - """ + """, configuration = configuration ) { with((this / "java" / "Test").cast<DClass>()) { name equals "Test" @@ -50,7 +61,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |interface Lower extends Highest { } |class Extendable { } |class Tested extends Extendable implements Lower { } - """){ + """, configuration = configuration){ with((this / "java" / "Tested").cast<DClass>()){ extra[ImplementedInterfaces]?.interfaces?.entries?.single()?.value?.map { it.dri.sureClassNames }?.sorted() equals listOf("Highest", "Lower").sorted() } @@ -64,39 +75,19 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |interface Lower extends Highest { } |class Extendable { } |class Tested extends Extendable implements Lower { } - """){ + """, configuration = configuration){ with((this / "java" / "Tested").cast<DClass>()) { supertypes.entries.single().value.map { it.typeConstructor.dri.sureClassNames to it.kind }.sortedBy { it.first } equals listOf("Extendable" to JavaClassKindTypes.CLASS, "Lower" to JavaClassKindTypes.INTERFACE) } } } - @Test // todo - fun memberWithModifiers() { - inlineModelTest( - """ - |class Test { - | /** - | * Summary for Function - | * @param name is String parameter - | * @param value is int parameter - | */ - | public void fn(String name, int value) {} - |} - """ - ) { - with((this / "java" / "Test" / "fn").cast<DFunction>()) { - this - } - } - } - @Test fun superClass() { inlineModelTest( """ |public class Foo extends Exception implements Cloneable {} - """ + """, configuration = configuration ) { with((this / "java" / "Foo").cast<DClass>()) { val sups = listOf("Exception", "Cloneable") @@ -116,7 +107,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { | return null; | } |} - """ + """, configuration = configuration ) { with((this / "java" / "Test").cast<DClass>()) { name equals "Test" @@ -141,7 +132,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |class Foo<T extends Comparable<T>> { | public <E> E foo(); |} - """ + """, configuration = configuration ) { with((this / "java" / "Foo").cast<DClass>()) { generics counts 1 @@ -158,7 +149,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { | | public Test(String s) {} |} - """ + """, configuration = configuration ) { with((this / "java" / "Test").cast<DClass>()) { name equals "Test" @@ -181,7 +172,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |class InnerClass { | public class D {} |} - """ + """, configuration = configuration ) { with((this / "java" / "InnerClass").cast<DClass>()) { children counts 1 @@ -200,7 +191,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |class Foo { | public void bar(String... x); |} - """ + """, configuration = configuration ) { with((this / "java" / "Foo").cast<DClass>()) { name equals "Foo" @@ -217,7 +208,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { } } - @Test // todo + @Test fun fields() { inlineModelTest( """ @@ -225,7 +216,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { | public int i; | public static final String s; |} - """ + """, configuration = configuration ) { with((this / "java" / "Test").cast<DClass>()) { children counts 2 @@ -250,7 +241,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |class C { | public static void foo() {} |} - """ + """, configuration = configuration ) { with((this / "java" / "C" / "foo").cast<DFunction>()) { with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("AdditionalModifiers")) { @@ -271,7 +262,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |public @interface Attribute { | String value() default ""; |} - """ + """, configuration = configuration ) { with((this / "java" / "Attribute").cast<DAnnotation>()) { with(extra[Annotations]!!.directAnnotations.entries.single().value.assertNotNull("Annotations")) { @@ -295,7 +286,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |class Test { | public Object fn() { return null; } |} - """ + """, configuration = configuration ) { with((this / "java" / "Test" / "fn").cast<DFunction>()) { assertTrue(type is JavaObject) @@ -310,7 +301,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |enum E { | Foo |} - """ + """, configuration = configuration ) { with((this / "java" / "E").cast<DEnum>()) { name equals "E" @@ -336,7 +327,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { | | public static class Bar extends Foo {} |} - """ + """, configuration = configuration ) { with((this / "java" / "InheritorLinks").cast<DClass>()) { val dri = (this / "Bar").assertNotNull("Foo dri").dri diff --git a/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt index 9e00fafd..3e5c8176 100644 --- a/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt +++ b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt @@ -13,7 +13,7 @@ class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/jav fun `function with deprecated parameter`() { inlineModelTest( """ - |class Test { + |public class Test { | public void fn(@Deprecated String name) {} |} """.trimIndent() @@ -37,7 +37,7 @@ class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/jav |public @interface Hello { | public String bar() default ""; |} - |class Test { + |public class Test { | public void foo(@Hello(bar = "baz") String arg){ } |} """.trimIndent() @@ -65,7 +65,7 @@ class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/jav |@interface Hello { | public String bar() default ""; |} - |class Test { + |public class Test { | public <@Hello(bar = "baz") T> List<T> foo() { | return null; | } @@ -94,7 +94,7 @@ class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/jav |@interface Hello { | public String bar() default ""; |} - |class Test { + |public class Test { | public <T extends @Hello(bar = "baz") String> List<T> foo() { | return null; | } diff --git a/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt b/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt index 131c7b77..ba00cf15 100644 --- a/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt +++ b/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt @@ -105,7 +105,7 @@ class IsExceptionJavaTest: AbstractModelTest("/src/main/kotlin/java/Test.java", fun `isException should work for java exceptions`(){ inlineModelTest( """ - |class ExampleException extends java.lang.Exception { }""" + |public class ExampleException extends java.lang.Exception { }""" ) { with((this / "java" / "ExampleException").cast<DClass>()) { name equals "ExampleException" @@ -118,7 +118,7 @@ class IsExceptionJavaTest: AbstractModelTest("/src/main/kotlin/java/Test.java", fun `isException should work for RuntimeException`(){ inlineModelTest( """ - |class ExampleException extends java.lang.RuntimeException""" + |public class ExampleException extends java.lang.RuntimeException""" ) { with((this / "java" / "ExampleException").cast<DClass>()) { name equals "ExampleException" @@ -131,7 +131,7 @@ class IsExceptionJavaTest: AbstractModelTest("/src/main/kotlin/java/Test.java", fun `isException should return false for a basic class`(){ inlineModelTest( """ - |class NotAnException extends Serializable""" + |public class NotAnException extends Serializable""" ) { with((this / "java" / "NotAnException").cast<DClass>()) { name equals "NotAnException" diff --git a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt index 5e0eb484..5cbd4416 100644 --- a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt +++ b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt @@ -8,17 +8,17 @@ import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { - - @Test - fun `method overriding two documented classes picks closest class documentation`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/main/java") - } + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/main/java") + includeNonPublic = true } } + } + @Test + fun `method overriding two documented classes picks closest class documentation`() { testInline( """ |/src/main/java/sample/BaseClass1.java @@ -56,14 +56,6 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { @Test fun `method overriding class and interface picks class documentation`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/main/java") - } - } - } - testInline( """ |/src/main/java/sample/BaseClass1.java @@ -101,14 +93,6 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { @Test fun `method overriding two classes picks closest documented class documentation`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/main/java") - } - } - } - testInline( """ |/src/main/java/sample/BaseClass1.java @@ -144,14 +128,6 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { @Test fun `java package-info package description`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/main/java") - } - } - } - testInline( """ |/src/main/java/sample/BaseClass1.java diff --git a/plugins/base/src/test/kotlin/translators/JavadocInheritDocsTest.kt b/plugins/base/src/test/kotlin/translators/JavadocInheritDocsTest.kt index 4e2cf70f..d5d25dc7 100644 --- a/plugins/base/src/test/kotlin/translators/JavadocInheritDocsTest.kt +++ b/plugins/base/src/test/kotlin/translators/JavadocInheritDocsTest.kt @@ -277,7 +277,7 @@ class JavadocInheritDocsTest : BaseAbstractTest() { |} |/src/main/java/sample/Subclass.java |package sample; - |class Subclass extends Superclass { + |public class Subclass extends Superclass { | /** | * Sample sub method. {@inheritDoc} | */ diff --git a/plugins/base/src/test/kotlin/translators/JavadocInheritedDocTagsTest.kt b/plugins/base/src/test/kotlin/translators/JavadocInheritedDocTagsTest.kt index c29c4e96..ecde2c77 100644 --- a/plugins/base/src/test/kotlin/translators/JavadocInheritedDocTagsTest.kt +++ b/plugins/base/src/test/kotlin/translators/JavadocInheritedDocTagsTest.kt @@ -16,6 +16,7 @@ class JavadocInheritedDocTagsTest : BaseAbstractTest() { sourceSets { sourceSet { sourceRoots = listOf("src/main/java") + includeNonPublic = true } } } |