Skip to content

Commit 1bffdac

Browse files
Fix missing JavaDoc in UtUtils class and update design doc (#1354)
1 parent 2cf3025 commit 1bffdac

File tree

9 files changed

+15
-11
lines changed

9 files changed

+15
-11
lines changed

docs/UtUtilsClass.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ Previously UnitTestBot generated _utility methods_ for each test class when they
1212

1313
For now UnitTestBot provides a special `UtUtils` class containing all _utility methods_ if at least one test class needs some of them. This class is generated once and the specific methods are imported from it if necessary. No need for _utility methods_ — no `UtUtils` class is generated.
1414

15+
We create a separate `UtUtils` class for each supported codegen language (if this class is required).
16+
1517
## What does it look like
1618

17-
Here is an example of a comment inherent to every `UtUtils` class:
19+
Here is an example of documentation comment inherent to every `UtUtils` class:
1820

19-
<img width="494" alt="ututils" src="https://user-images.githubusercontent.com/64418523/196719780-2603f141-e922-40fc-9a0a-533aaacc5c49.png">
21+
![Documentation](images/utbot_ututils_2.0.png)
2022

2123
As one can see, the comment mentions two characteristics of the `UtUtils` class:
2224

@@ -39,7 +41,7 @@ rely on the proper methods from `UtUtils` class.
3941

4042
## Where to find it
4143

42-
`UtUtils` class is usually located in the chosen **Test sources root** near the generated test classes.
44+
`UtUtils` class is usually located in the chosen **Test sources root** near the generated test classes. The corresponding package name mentions the language of the generated tests: e.g. `org.utbot.runtime.utils.java`.
4345

4446
## How to test
4547

docs/images/utbot_ututils_2.0.png

14.9 KB
Loading

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/models/CgElement.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ open class CgClassFile(
124124

125125
class CgClass(
126126
val id: ClassId,
127+
val documentation: CgDocumentationComment?,
127128
val annotations: List<CgAnnotation>,
128129
val superclass: ClassId?,
129130
val interfaces: List<ClassId>,
@@ -149,7 +150,6 @@ class CgClass(
149150
*/
150151
class CgClassBody(
151152
val classId: ClassId,
152-
val documentation: CgDocumentationComment?,
153153
val methodRegions: List<CgMethodsCluster>,
154154
val staticDeclarationRegions: List<CgStaticsRegion>,
155155
val nestedClassRegions: List<CgNestedClassesRegion<*>>

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt

Whitespace-only changes.

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgJavaRenderer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ internal class CgJavaRenderer(context: CgRendererContext, printer: CgPrinter = C
6161
get() = this == context.generatedClass
6262

6363
override fun visit(element: CgClass) {
64+
element.documentation?.accept(this)
65+
6466
for (annotation in element.annotations) {
6567
annotation.accept(this)
6668
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgKotlinRenderer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
7575
get() = (this == context.generatedClass) || isKotlinFile
7676

7777
override fun visit(element: CgClass) {
78+
element.documentation?.accept(this)
79+
7880
for (annotation in element.annotations) {
7981
annotation.accept(this)
8082
}
@@ -115,8 +117,6 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
115117
}
116118

117119
override fun visit(element: CgClassBody) {
118-
element.documentation?.accept(this)
119-
120120
// render regions for test methods
121121
for ((i, region) in (element.methodRegions + element.nestedClassRegions).withIndex()) {
122122
if (i != 0) println()

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/Builders.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ fun buildClassFile(init: CgClassFileBuilder.() -> Unit) = CgClassFileBuilder().a
4949

5050
class CgClassBuilder : CgBuilder<CgClass> {
5151
lateinit var id: ClassId
52+
var documentation: CgDocumentationComment? = null
5253
val annotations: MutableList<CgAnnotation> = mutableListOf()
5354
var superclass: ClassId? = null
5455
val interfaces: MutableList<ClassId> = mutableListOf()
5556
var isStatic: Boolean = false
5657
var isNested: Boolean = false
5758
lateinit var body: CgClassBody
5859

59-
override fun build() = CgClass(id, annotations, superclass, interfaces, body, isStatic, isNested)
60+
override fun build() = CgClass(id, documentation, annotations, superclass, interfaces, body, isStatic, isNested)
6061
}
6162

6263
fun buildClass(init: CgClassBuilder.() -> Unit) = CgClassBuilder().apply(init).build()
6364

6465
class CgClassBodyBuilder(val classId: ClassId) : CgBuilder<CgClassBody> {
65-
var documentation: CgDocumentationComment? = null
6666
val methodRegions: MutableList<CgMethodsCluster> = mutableListOf()
6767
val staticDeclarationRegions: MutableList<CgStaticsRegion> = mutableListOf()
6868
val nestedClassRegions: MutableList<CgNestedClassesRegion<*>> = mutableListOf()
6969

70-
override fun build() = CgClassBody(classId, documentation, methodRegions, staticDeclarationRegions, nestedClassRegions)
70+
override fun build() = CgClassBody(classId, methodRegions, staticDeclarationRegions, nestedClassRegions)
7171
}
7272

7373
fun buildClassBody(classId: ClassId, init: CgClassBodyBuilder.() -> Unit) = CgClassBodyBuilder(classId).apply(init).build()

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/ututils/CgUtilClassConstructor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ internal object CgUtilClassConstructor {
2727
// so they will be imported once IDEA reformatting action has worked
2828
declaredClass = buildClass {
2929
id = utilsClassId
30+
documentation = utilClassKind.utilClassDocumentation(codegenLanguage)
3031
body = buildClassBody(utilsClassId) {
31-
documentation = utilClassKind.utilClassDocumentation(codegenLanguage)
3232
staticDeclarationRegions += CgStaticsRegion("Util methods", utilMethodProvider.utilMethodIds.map { CgUtilMethod(it) })
3333
nestedClassRegions += CgAuxiliaryNestedClassesRegion(
3434
nestedClasses = listOf(

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/ututils/UtilClassKind.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ sealed class UtilClassKind(
3535
fun utilClassDocumentation(codegenLanguage: CodegenLanguage): CgDocumentationComment
3636
= CgDocumentationComment(
3737
listOf(
38-
CgDocRegularStmt(utilClassKindCommentText),
38+
CgDocRegularStmt("$utilClassKindCommentText \n"),
3939
CgDocRegularStmt("$UTIL_CLASS_VERSION_COMMENT_PREFIX${utilClassVersion(codegenLanguage)}"),
4040
)
4141
)

0 commit comments

Comments
 (0)