Closed marcospereira closed 1 year ago
Looks good to me. Just one question: since Kotlin can interoperate with Java classes, what is the benefit of generating Kotlin versions of the classes? (I'm not much of a Kotlin user)
Looks good to me. Just one question: since Kotlin can interoperate with Java classes, what is the benefit of generating Kotlin versions of the classes? (I'm not much of a Kotlin user)
Interoperability is quite good, but there are places where it fails. For example, if you have a Kte template such as:
@param messages: List<String>
<html lang="pt">
<head>
<title>First Page</title>
</head>
<body>
<h1>message</h1>
</body>
</html>
List
is a kotlin.collections.List
, and users don't need to import manually. The generated (Java) interface misses the import and is then broken:
package br.ufpe.liber;
import gg.jte.models.runtime.*;
public interface Templates {
@JteView("index.kte")
JteModel index(List<String> messages);
}
Compilation error:
Templates.java:8: error: cannot find symbol
JteModel index(List<String> messages);
^
symbol: class List
location: interface Templates
There are workarounds, but then the user needs to use them constantly, which impacts the developer experience.
Thanks for reviewing, @edward3h. I pushed a couple of commits after your feedback. :-)
Looks good. Thank you for your contribution.
Attention: 1 lines
in your changes are missing coverage. Please review.
Comparison is base (
9230876
) 91.09% compared to head (1888f90
) 91.13%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Thanks for the contribution @marcospereira and thanks for the review @edward3h.
I know it is against the Java conventions, but so far enum constants in the jte project have been camel case. Could we rename the Language enum values to Java
and Kotlin
?
I think it is also okay to be case sensitive here when we parse the setting and do a Language.valueOf(configuredLanguage);
as you had it initially. This will always be an error message at build time, never at runtime. We probably do not want to support users entering jAvA
and the like :-)
Other than that, this looks fantastic!
Thanks, @casid.
I know it is against the Java conventions, but so far enum constants in the jte project have been camel case. Could we rename the Language enum values to
Java
andKotlin
?
Done in a059cd3.
I think it is also okay to be case sensitive here when we parse the setting and do a
Language.valueOf(configuredLanguage);
as you had it initially. This will always be an error message at build time, never at runtime. We probably do not want to support users enteringjAvA
and the like :-)
Done in 1888f90.
This should be good to go now. :-)
Wow, that was quick! I'll merge this as soon as the CI build is done.
Wow, that was quick! I'll merge this as soon as the CI build is done.
Thanks! Also, when can we have a release with those changes?
There haven't been any changes since the last release, so there's nothing blocking us from releasing this asap. Will have a look at it this weekend.
There haven't been any changes since the last release, so there's nothing blocking us from releasing this asap. Will have a look at it this weekend.
Thank you. No rush here, though. :-)
By the way, I just submitted a follow-up pr to update the docs. See #283. :-)
@marcospereira I published version 3.1.2 which contains this feature!
What?
This adds support to generate Kotlin code (instead of Java) when using the
jte-models
extension. There are a few inconveniences when mixing both languages (clashing names such asList
, which are different for both, not having to import standard-lib classes in Kotlin that would break the Java generate code), and having this will solve that.How
Simply by providing a
language
configuration to the extension. The default is Java, so people upgrading won't have to change anything in their build files. An example:Generate code
The generated code looks like this: