Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the kotlin-as-java plugin include information about access modifiers for functions #2510

Merged
merged 3 commits into from May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -131,6 +131,7 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte
sourceSets = setOf(sourceSet)
) {
annotationsBlock(f)
f.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
f.modifier[sourceSet]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ")?.let { keyword(it) }
f.modifiers()[sourceSet]?.toSignatureString()?.let { keyword(it) }
val returnType = f.type
Expand Down
54 changes: 50 additions & 4 deletions plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt
Expand Up @@ -176,7 +176,7 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
divergentInstance {
divergent {
group {
+"final "
+"public final "
group {
link {
+"String"
Expand Down Expand Up @@ -331,7 +331,7 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").firstSignature().match(
"final ", A("Integer"), A("someFun"), "(", Parameters(
"public final ", A("Integer"), A("someFun"), "(", Parameters(
Parameter(A("Integer"), "xd")
), ")", Span(), ignoreSpanWithTokenStyle = true
)
Expand Down Expand Up @@ -370,7 +370,7 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").firstSignature().match(
"final ", A("Integer"), A("someFun"), "(", Parameters(
"public final ", A("Integer"), A("someFun"), "(", Parameters(
Parameter(A("Map"), "<", A("String"), ", ", A("Integer"), "> xd"),
), ")", Span(), ignoreSpanWithTokenStyle = true
)
Expand Down Expand Up @@ -436,7 +436,7 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-test-kt/sample.html").firstSignature().match(
"final static ", A("String"), A("sample"), "(", Parameters(
"public final static ", A("String"), A("sample"), "(", Parameters(
Parameter(A("Integer"), "a"),
), ")", Span(), ignoreSpanWithTokenStyle = true
)
Expand Down Expand Up @@ -583,6 +583,52 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
}
}
}

@Test
fun `Java function should keep its access modifier`(){
val className = "Test"
val accessModifier = "public"
val methodName = "method"

val testClassQuery = """
|/src/main/kotlin/kotlinAsJavaPlugin/${className}.java
|package kotlinAsJavaPlugin;
|
|public class $className {
| $accessModifier void ${methodName}() {
|
| }
|}
""".trimMargin()

val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}

val writerPlugin = TestOutputWriterPlugin()

testInline(
testClassQuery,
configuration,
pluginOverrides = listOf(writerPlugin),
cleanupOutput = true
) {
renderingStage = { _, _ ->
val methodDocumentation = "root/kotlinAsJavaPlugin/-${className.toLowerCase()}/${methodName}.html"

writerPlugin.writer.renderedContent(methodDocumentation)
.firstSignature()
.match(
"$accessModifier void ", A(methodName), "()", Span(),
ignoreSpanWithTokenStyle = true
)
}
}
}
}

private val ContentNode.mainContents: List<ContentNode>
Expand Down