outfoxx / swiftpoet

Kotlin and Java API for generating .swift source files.
Apache License 2.0
284 stars 27 forks source link

Cannot emit backticked property #2

Closed JakeWharton closed 4 years ago

JakeWharton commented 4 years ago

When trying to create the property, the name is first checked to be valid so ones like "extension" fail.

https://github.com/outfoxx/swiftpoet/blob/9d7a1bbb90cb5eaf17d05ccf4297515d375caf19/src/main/java/io/outfoxx/swiftpoet/PropertySpec.kt#L167

If I switch to manually backticking the name I get past this check but then upon emit it's has an additional set of backticks added to it.

https://github.com/outfoxx/swiftpoet/blob/9d7a1bbb90cb5eaf17d05ccf4297515d375caf19/src/main/java/io/outfoxx/swiftpoet/PropertySpec.kt#L45

This produces something like

struct Foo {
  let ``extension``: String
}

It seems like one or the other behaviors need removed. Either a property allows all names and then escapes with backticks if necessary, or it still does validation on the way in and then does not escape when emitting.

kdubb commented 4 years ago

For Swift removing the check and adding backticks seems preferred.

Additionally, Utils.kt has a lot of Java/Kotlin assumptions that, while they "work", are probably incorrect for Swift as a whole.

JakeWharton commented 4 years ago

Cool I can send a PR for that change.

I noticed there were still some Java/Kotlin things internally but it's nice they don't seem to hamper your ability to use the library at all. Even in KotlinPoet we still find things which are holdovers from JavaPoet.