-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support parsing javadoc
@param
for classes
- Loading branch information
Showing
6 changed files
with
168 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...lin-api/src/test/kotlin/org/jetbrains/dokka/analysis/test/jvm/java/JavadocAnalysisTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package org.jetbrains.dokka.analysis.test.jvm.java | ||
|
||
import org.jetbrains.dokka.analysis.test.api.javaTestProject | ||
import org.jetbrains.dokka.analysis.test.api.parse | ||
import org.jetbrains.dokka.model.SourceSetDependent | ||
import org.jetbrains.dokka.model.doc.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class JavadocAnalysisTest { | ||
|
||
@Test | ||
fun `should parse javadoc @param for type parameter on class`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "Foo.java") { | ||
+""" | ||
/** | ||
* class | ||
* | ||
* @param <Bar> type parameter, | ||
* long type parameter description | ||
*/ | ||
public class Foo<Bar> {} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val cls = pkg.classlikes.single() | ||
|
||
assertDocumentationNodeContains( | ||
cls.documentation, | ||
listOf( | ||
Description(customDocTag("class")), | ||
Param(customDocTag("type parameter, long type parameter description"), "<Bar>"), | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `should parse javadoc @param for type parameter on function`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "Foo.java") { | ||
+""" | ||
public class Foo { | ||
/** | ||
* function | ||
* | ||
* @param <Bar> type parameter, | ||
* long type parameter description | ||
*/ | ||
public <Bar> void something(Bar bar) {} | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val cls = pkg.classlikes.single() | ||
val function = cls.functions.single { it.name == "something" } | ||
|
||
assertDocumentationNodeContains( | ||
function.documentation, | ||
listOf( | ||
Description(customDocTag("function")), | ||
Param(customDocTag("type parameter, long type parameter description"), "<Bar>"), | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `should parse javadoc @param for parameter on function`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "Foo.java") { | ||
+""" | ||
public class Foo { | ||
/** | ||
* function | ||
* | ||
* @param bar parameter, | ||
* long parameter description | ||
*/ | ||
public void something(String bar) {} | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val cls = pkg.classlikes.single() | ||
val function = cls.functions.single { it.name == "something" } | ||
|
||
assertDocumentationNodeContains( | ||
function.documentation, | ||
listOf( | ||
Description(customDocTag("function")), | ||
Param(customDocTag("parameter, long parameter description"), "bar"), | ||
) | ||
) | ||
} | ||
|
||
private fun customDocTag(text: String): CustomDocTag { | ||
return CustomDocTag(listOf(P(listOf(Text(text)))), name = "MARKDOWN_FILE") | ||
} | ||
|
||
private fun assertDocumentationNodeContains( | ||
node: SourceSetDependent<DocumentationNode>, | ||
expected: List<TagWrapper> | ||
) { | ||
assertEquals( | ||
DocumentationNode(expected), | ||
node.values.single() | ||
) | ||
} | ||
} |