Skip to content

Commit

Permalink
Make the kotlin-as-java plugin include information about access mod…
Browse files Browse the repository at this point in the history
…ifiers for functions (#2510)

* Include access modifiers for Java functions

* Test that access modifiers are present

* Modify existing tests due to including access modifier in output
  • Loading branch information
tripolkaandrey committed May 27, 2022
1 parent 01eb31a commit ad5f857
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
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

0 comments on commit ad5f857

Please sign in to comment.