casid / jte

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

Support classes that are in no package #258

Closed lsoares closed 1 year ago

lsoares commented 1 year ago

If I have a class (in my case a Kotlin data class) in the root package, it can't be referenced in the templates. It's simply not found by jte generating a 500 error. Does it make sense to support it or do we assume that everyone uses a package? I bumped into this while creating a minimalistic tutorial for jte.

casid commented 1 year ago

In jte the same rules apply as in a regular Kotlin program, so I think this is not possible.

lsoares commented 1 year ago

but you can have a regular Kotlin program without package. here, WebApp (with main) is in the root and it works fine.

image
casid commented 1 year ago

Yes, but you cannot import WebApp.kt from any other Kotlin package (at least if this works in Kotlin the same as in Java).

And jte template classes are generated by default in a package.

lsoares commented 1 year ago

do you mean this?

image
casid commented 1 year ago

Yes, in Java I get this compile error Class 'X' is in the default package. So this is working in Kotlin?

Did you try this in your kte template then? @import X

lsoares commented 1 year ago

yeah it has no compilation errors. I believe Kotlin is less restrictive in that regard.

There's no error in the jte plugin. only when I run the app

image

If I do @import Car as you said then there's an error in jte plugin which could have helped me but since it doesn't complain I was puzzled for a while.

casid commented 1 year ago

Closed this as not planned, because we can't do anything about it in jte itself.

I opened a ticket in the intellij plugin, to see if we can provide a better error message: https://github.com/casid/jte-intellij/issues/30