Skip to content

Support regions without comments, e.g. mocking utils region for Spring #1926

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

Merged
merged 2 commits into from
Mar 13, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class CgClassBody(
* A class representing the IntelliJ IDEA's regions.
* A region is a part of code between the special starting and ending comments.
*
* [header] The header of the region.
* @property header The header of the region,
* no ///region and ///endregion comments are generated if [header] is `null`
*/
sealed class CgRegion<out T : CgElement> : CgElement {
abstract val header: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ abstract class CgAbstractRenderer(
private fun CgRegion<*>.render(printLineAfterContentEnd: Boolean = false) {
if (content.isEmpty() || isInterrupted) return

print(regionStart)
header?.let { print(" $it") }
println()
header?.let {
print(regionStart)
println(" $it")
}

if (this is CgTestMethodCluster) description?.accept(this@CgAbstractRenderer)

Expand All @@ -208,7 +209,9 @@ abstract class CgAbstractRenderer(

if (printLineAfterContentEnd) println()

println(regionEnd)
header?.let {
println(regionEnd)
}

if (isLimitExceeded && !isInterrupted) {
visit(CgSingleLineComment("Abrupt generation termination: file size exceeds configured limit (${FileUtil.byteCountToDisplaySize(UtSettings.maxTestFileSize.toLong())})"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,6 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
println("}")
}

override fun visit(element: CgStaticsRegion) {
if (element.content.isEmpty()) return

print(regionStart)
element.header?.let { print(" $it") }
println()

for (item in element.content) {
println()
println("@JvmStatic")
item.accept(this)
}

println(regionEnd)
}


// Property access

override fun visit(element: CgFieldAccess) {
Expand Down Expand Up @@ -383,6 +366,12 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
print(")")
}

override fun visit(element: CgParameterizedTestDataProviderMethod) {
println()
println("@JvmStatic")
super.visit(element)
}

override fun renderRegularImport(regularImport: RegularImport) {
val escapedImport = getEscapedImportRendering(regularImport)
println("import $escapedImport$statementEnding")
Expand Down Expand Up @@ -654,4 +643,4 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
print(">")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ class CgSpringTestClassConstructor(context: CgContext): CgAbstractTestClassConst
)

val methodCluster = CgMethodsCluster(
"Test run utility methods",
listOf(CgSimpleRegion("Mocking utils", listOf(beforeMethod, afterMethod)))
header = null,
listOf(CgSimpleRegion(header = null, listOf(beforeMethod, afterMethod)))
)

return mockitoCloseableField to methodCluster
}
}
}