Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Update kotlinpoet to 1.5.0 (#144)
Browse files Browse the repository at this point in the history
* Update kotlinpoet to 1.5.0

* After merging arrow-kt/arrow#2154 we need to create another PR to bring this line back!

Co-authored-by: Paco <pakoito@users.noreply.github.com>
  • Loading branch information
hadilq and pakoito authored Jun 8, 2020
1 parent 75d5db3 commit 56987c9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion arrow-meta/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
compile project(':arrow-annotations')
compile "me.eugeniomarletti.kotlin.metadata:kotlin-metadata:$KOTLIN_METADATA_VERSION"
compile("com.squareup:kotlinpoet:$KOTLIN_POET_VERSION") {
compile("com.squareup:kotlinpoet:1.5.0") {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect'
}
compile "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun generateCoproducts(destination: File) {
for (size in 2 until genericsToClassNames.size + 1) {
val generics = genericsToClassNames.keys.toList().take(size)

FileSpec.builder("arrow.generic.coproduct$size", "Coproduct$size")
FileSpec.builder(coproductPackageName(size), "Coproduct$size")
.apply {
addCoproductClassDeclaration(generics)
addExtensionConstructors(generics)
Expand Down Expand Up @@ -196,7 +196,7 @@ private fun methodDocumentation(
private fun List<String>.toTypeParameters(): List<TypeVariableName> = map { TypeVariableName(it) }

private fun parameterizedCoproductNClassName(generics: List<String>): ParameterizedTypeName =
ClassName("", "Coproduct${generics.size}")
ClassName(coproductPackageName(generics.size), "Coproduct${generics.size}")
.parameterizedBy(*generics.map { TypeVariableName(it) }.toTypedArray())

private fun additionalParameterSuppressAnnotation(count: Int): List<AnnotationSpec> =
Expand All @@ -215,3 +215,5 @@ private fun additionalParameterSpecs(count: Int): List<ParameterSpec> = List(cou
.defaultValue("Unit")
.build()
}

private fun coproductPackageName(size: Int) = "arrow.generic.coproduct$size"
5 changes: 3 additions & 2 deletions arrow-meta/src/main/java/arrow/meta/decoder/Decoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ interface TypeDecoder : MetaDecoder<Type> {
).copy(suspending = modifiers.contains(Modifier.Suspend))

fun TypeName.Classy.lyrics(): ClassName =
ClassName(packageName = pckg.value, simpleName = simpleName)
ClassName(packageName = pckg.value, simpleNames = listOf(simpleName))
.copy(nullable = nullable, annotations = annotations.map { it.lyrics() }, tags = emptyMap())

fun TypeName.lyrics(): com.squareup.kotlinpoet.TypeName =
when (this) {
Expand All @@ -223,7 +224,7 @@ interface TypeDecoder : MetaDecoder<Type> {
Code(f().trimMargin())

operator fun TypeName?.unaryPlus(): Code =
if (this != null) Code(CodeBlock.of("%T", this.lyrics()).toString())
if (this != null) Code(CodeBlock.of("%T", lyrics()).toString())
else Code("")

operator fun String.unaryPlus(): Code =
Expand Down

0 comments on commit 56987c9

Please sign in to comment.