Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork4.1k
Java support for routes compiler#13213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
6c60e32
toef7f4d0
Compare@@ -84,6 +85,7 @@ private void compile() { | |||
generateReverseRouter, | |||
generateJsReverseRouter, | |||
namespaceReverseRouter, | |||
Language.SCALA, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I will implement adoption to this feature for Gradle Plugin in the separated PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OK. So in your next PR you will just make use of the new generated java routes for the gradle plugin or did you plan to also enable it for the sbt java plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you want you can also already submit the next PR (including the commit of this PR). Just so I can take a look.
I can still review them separate and merge them separate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
So in your next PR you will just make use of the new generated java routes for the gradle plugin or did you plan to also enable it for the sbt java plugin?
Only for Gradle plugin. Yes, I thought about enable a java routes by default for PlayJava sbt plugin, but decided don't do that before we'll get a feedback from someone who enable it manually. If you think we are ready do that right now, I will be happy do that.
@@ -67,6 +67,25 @@ package object templates { | |||
methodPart + paramPart | |||
} | |||
def javaInjectedControllerMethodCall(r: Route, ident: String): String = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
A lot of changes in this file can be combine and optimise for both languages. But I decided keep it to the future yet and avoid touching an exists functions for Scala and wrote a "duplicate" for Java.
@mkurz if you want, I can try to do this unification in this PR.
ef7f4d0
to1cd6053
CompareWill take a look in the next 24 hours |
(packageName.map(_.replace(".", "/") + "/").getOrElse("") + JavaWrapperFile) -> { | ||
lang match { | ||
case Language.JAVA => | ||
static.twirl.javaJavaWrappers(sourceInfo, namespace, packageName, controllers, jsReverseRouter).body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
javaJava
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yep. It looks not good, but It's just ajava
prefix for all existed templates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hmm.. yes it's a bit confusing to read.
Just thinking out loud, maybe we should also rename existing template files:
jJavascriptReverseRouter.scala.twirljJavaWrappers.scala.twirljReverseRouter.scala.twirljRoutesPrefix.scala.twirl
sJavascriptReverseRouter.scala.twirlsJavaWrappers.scala.twirlsReverseRouter.scala.twirlsRoutesPrefix.scala.twirl
and
sForwardsRouter.scala.twirljForwardsRouter.scala.twirl
But not sure, I think prefixing existing templates withs
will break compatibility. So maybe just prefix the new templates just withj
instead of writing outjava
. We do use this approach with some methods and variables in the code, maybe also here? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think the names of templates are internal part and we are free to choice any pattern for them.
I like an idea with one letters/j
prefix. 👍
Adding another 24 hours ;) |
"\n )," | ||
) | ||
} | ||
.filterNot(_ == ",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Without this filternot the simple example
GET / controllers.HomeController.index(r: Request)
publicResultindex(Http.Requestr) { ... }
fails. Becauseps.mkString("", ",\n ", ",")
above will add the trailing,
even if the list is empty, so we end up withcall(, ...)
which of course does not compile (This is more or less the equivalent of the.filterNot(_ == "()")
in the scala method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OMG, it's so stupid checked a lot of cases with any type of params and forgot about case with only oneRequest
param 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Test for this case was added in this commit99aad10
public static final @{packageName.map(_ + ".").getOrElse("")}javascript.JavaScriptReverseRoutes.Reverse@controller @controller = new @{packageName.map(_ + ".").getOrElse("")}javascript.JavaScriptReverseRoutes.Reverse@(controller)(RoutesPrefix.byNamePrefix);} | ||
@cb | ||
} | ||
@cb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think we can unify[java]JavaWrapper.scala.twirl
(specially because even in play scala it will be generated as java file).
I think we can just stupidly wrap the scala reverse routes in aReverseRoutes
class/object and also pass the prefix lamba as lambda and not lazy string.
With that two changes we should be able to just use one file.
Feels a bit cleaner IMHO as the differences between[java]JavaWrapper.scala.twirl
is not really big.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not sure that I understood your idea for 100%, but I unifiedroutes.java
for both compilers. Can you check that (separated commit)?
I think we can just stupidly wrap the scala reverse routes in a
ReverseRoutes
class/object
Looks like If someone uses a reverse routes classes directly then these changes will break a source compatibility in new version. Is it ok to you?
998e365
to36ecdb6
CompareI will try to get this merged early this week, just want to do a bit more local testing and playing around. |
Uh oh!
There was an error while loading.Please reload this page.
As main part of#13212