Skip to content

Commit

Permalink
Improves after review;
Browse files Browse the repository at this point in the history
  • Loading branch information
ivk1800 committed Mar 4, 2024
1 parent 103b000 commit 32326ed
Showing 1 changed file with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,41 +323,21 @@ class MemberNameTest {
}

@Test fun importedMemberClassFunctionNameDontClashForParameterValue() {
fun createSimpleParameterCodeBlock(): CodeBlock {
val member = ClassName(
packageName = "com.squareup",
simpleNames = listOf("Fridge"),
).member("meat")
val block = CodeBlock.builder()
.add("%M", member)
.add(" { }")
.build()
return CodeBlock
.builder()
.add("%L", block)
.build()
}

fun createFuncParameter(name: String) =
CodeBlock
.builder()
.add(name).add(" = ")
.add(createSimpleParameterCodeBlock())
.build()

fun createFuncParameters(names: List<String>): List<CodeBlock> =
names.map { name -> createFuncParameter(name) }

fun createBuildFunc(params: List<String>): FunSpec {
val tacoClassname = ClassName.bestGuess("com.squareup.tacos.Taco")
val paramsCodeBlock = CodeBlock.builder()
.add("return %T", tacoClassname)
.apply {
add(
params.let(::createFuncParameters)
.map { block -> CodeBlock.of("%L", block) }
.joinToCode(prefix = "(", suffix = ")"),
)
val paramsBlock = params.map { paramName ->
val paramValue = ClassName(
packageName = "com.squareup",
simpleNames = listOf("Fridge"),
).member("meat")
CodeBlock.of("$paramName = %L", CodeBlock.of("%M { }", paramValue))
}
.map { block -> CodeBlock.of("%L", block) }
.joinToCode(prefix = "(", suffix = ")")
add(paramsBlock)
}
.build()
return FunSpec.builder("build")
Expand Down

0 comments on commit 32326ed

Please sign in to comment.