casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
737 stars 54 forks source link

Fix imports in Kotlin model generation #309

Closed MariusVolkhart closed 6 months ago

MariusVolkhart commented 6 months ago

The models project generated Kotlin code that didn't have the correct imports. This happened because the imports were not being tracked as imports in the KotlinCodeGenerator, only as code.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (0c83398) 91.20% compared to head (af3b52f) 91.14%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #309 +/- ## ============================================ - Coverage 91.20% 91.14% -0.07% + Complexity 1204 1203 -1 ============================================ Files 76 76 Lines 3139 3140 +1 Branches 489 489 ============================================ - Hits 2863 2862 -1 - Misses 167 168 +1 - Partials 109 110 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

casid commented 6 months ago

Sorry, I just merged a bit too fast. But the change itself is solid!

@edward3h is there a test for the Java way we could adopt for Kotlin?

MariusVolkhart commented 6 months ago

I'd probably go the route of writing a test that parses a template, produces generated files, and then compares the generated files against golden versions. Thoughts on that?

The challenge is that the jte-models project is the only place where the imports are actually read. The KotlinCodeGenerator doesn't care about the list of imports as it generates code directly.

casid commented 6 months ago

Indeed, I think writing a test from the jte-models perspective would be ideal, since that's the project that needs the imports as you said.