Fix #1169: Handle long import with aliased name.
diff --git a/kotlinpoet/src/main/java/com/squareup/kotlinpoet/Import.kt b/kotlinpoet/src/main/java/com/squareup/kotlinpoet/Import.kt
index c0c06e8..28f65ab 100644
--- a/kotlinpoet/src/main/java/com/squareup/kotlinpoet/Import.kt
+++ b/kotlinpoet/src/main/java/com/squareup/kotlinpoet/Import.kt
@@ -23,7 +23,7 @@
private val importString = buildString {
append(qualifiedName.escapeSegmentsIfNecessary())
if (alias != null) {
- append(" as ${alias.escapeIfNecessary()}")
+ append("·as·${alias.escapeIfNecessary()}")
}
}
diff --git a/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FileSpecTest.kt b/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FileSpecTest.kt
index 61a69bd..2ac486b 100644
--- a/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FileSpecTest.kt
+++ b/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FileSpecTest.kt
@@ -1026,6 +1026,20 @@
)
}
+ @Test fun importAliasedLongPackageName() {
+ val spec = FileSpec.builder("testsrc", "Test")
+ .addAliasedImport(ClassName("a.really.veryveryveryveryveryveryvery.long.pkgname.that.will.definitely.cause.a.wrap.duetoitslength", "MyClass"), "MyClassAlias")
+ .build()
+ assertThat(spec.toString()).isEqualTo(
+ """
+ |package testsrc
+ |
+ |import a.really.veryveryveryveryveryveryvery.long.pkgname.that.will.definitely.cause.a.wrap.duetoitslength.MyClass as MyClassAlias
+ |
+ |""".trimMargin()
+ )
+ }
+
@Test fun longComment() {
val file = FileSpec.builder("com.squareup.tacos", "Taco")
.addComment(