Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
ihostage wants to merge4 commits intoplayframework:main
base:main
Choose a base branch
Loading
fromihostage:java-routes-compiler

Conversation

ihostage
Copy link
Member

@ihostageihostage commentedMar 20, 2025
edited
Loading

As main part of#13212

mkurz reacted with eyes emoji
@ihostageihostage requested a review frommkurzMarch 20, 2025 13:53
@@ -84,6 +85,7 @@ private void compile() {
generateReverseRouter,
generateJsReverseRouter,
namespaceReverseRouter,
Language.SCALA,
Copy link
MemberAuthor

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

mkurz reacted with thumbs up emoji
Copy link
Member

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?

Copy link
Member

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.

Copy link
MemberAuthor

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 = {
Copy link
MemberAuthor

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.

mkurz reacted with eyes emoji
@mkurzmkurz moved this from🆕 New to🏗 In Progress inPlay 4.0 (due 30st June 2025)Mar 20, 2025
@ihostageihostage marked this pull request as ready for reviewMarch 20, 2025 16:11
@ihostageihostage moved this from🏗 In Progress to👀 In review inPlay 4.0 (due 30st June 2025)Mar 20, 2025
@mkurz
Copy link
Member

Will take a look in the next 24 hours

ihostage reacted with heart emoji

(packageName.map(_.replace(".", "/") + "/").getOrElse("") + JavaWrapperFile) -> {
lang match {
case Language.JAVA =>
static.twirl.javaJavaWrappers(sourceInfo, namespace, packageName, controllers, jsReverseRouter).body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

javaJava?

Copy link
MemberAuthor

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.

Copy link
Member

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?

Copy link
MemberAuthor

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. 👍

@mkurz
Copy link
Member

Will take a look in the next 24 hours

Adding another 24 hours ;)

ihostage reacted with heart emoji

"\n ),"
)
}
.filterNot(_ == ",")
Copy link
Member

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).

Copy link
MemberAuthor

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 🤦‍♂️

Copy link
MemberAuthor

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
Copy link
Member

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.

Copy link
MemberAuthor

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 aReverseRoutes 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?

@ihostageihostage requested a review frommkurzMarch 28, 2025 15:31
@mkurz
Copy link
Member

I will try to get this merged early this week, just want to do a bit more local testing and playing around.

ihostage reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@PromanSEWPromanSEWPromanSEW left review comments

@mkurzmkurzAwaiting requested review from mkurz

At least 1 approving review is required to merge this pull request.

Assignees

@mkurzmkurz

Labels
None yet
Projects
Status: 👀 In review
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@ihostage@mkurz@PromanSEW

[8]ページ先頭

©2009-2025 Movatter.jp