Repository navigation
feat(scala3): WIP working on scala 3 cross compilation. #390. #461
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
88688a8
Add Scala 3 to cross build
tototoshi 8f82bc2
Add a testcase for call-by-name parameters
tototoshi 6bcb772
Use scalameta in TemplateAsFunctionCompiler
tototoshi 88eb6da
Make CompilerSpec compatible with Scala3
tototoshi 47259b7
Make @if expression work in Scala3
tototoshi f10f3da
Fix error reporting
tototoshi a10afc4
Merge remote-tracking branch 'playframework/main' into scalameta
tototoshi 7747deb
Add a test case for if with brackets
tototoshi f6e583a
Merge remote-tracking branch 'playframework/main' into scalameta
tototoshi c95e169
Add fix for By-name parameter
tototoshi bce69ea
Change scalacOptions for each version
tototoshi 3d6185f
sbt-scalajs, scalajs-compiler, ... 1.8.0 (was 1.7.1)
scala-steward 1efefac
feat(scala3): WIP working on scala 3 cross compilation. #390.
brbrown25 5071500
Add Scala 3 to cross build
tototoshi df091ff
Use scalameta in TemplateAsFunctionCompiler
tototoshi 47ebbc8
WIP tweaking after merging tototoshi branch
brbrown25 096b082
Merge remote-tracking branch 'tototoshi/scalameta' into ISSUE-390
brbrown25 de50d09
feat(scala3): Formating and cleanup after integrating tototoshi branc…
brbrown25 e8b6ceb
Refactored `ifExpression`
tototoshi 05b73c5
Add comment for ifExpression
tototoshi e141ce1
Merge remote-tracking branch 'tototoshi/scalameta' into ISSUE-390
brbrown25 e02f4e1
chore(TwirlParser): fixing format check failure.
brbrown25 cb862d5
chore(build.sbt, TwirlParser): Adding Mima filters and tweaking to re…
brbrown25 d432c66
Removed onChangeBuildSource setting to align with other Play reposito…
tototoshi 909f11e
Remove unused code
tototoshi 63be771
Replace TRAVIS_SCALA_VERSION with SCALA_VERSION
tototoshi 4174fe4
chore(build.sbt): removing the scripted change as it is not needed. #…
brbrown25 e892f83
Suppress compile errors log during running CompilerSpec
tototoshi 2a3898f
chore(travis.yml): updating the scala version from 3.1.0 to 3.1.1 in …
brbrown25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions
43
api/shared/src/main/scala-2.13/play/twirl/api/BaseScalaTemplate.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
| package play.twirl.api | ||
|
|
||
| import java.util.Optional | ||
| import scala.collection.immutable | ||
| import scala.jdk.CollectionConverters._ | ||
| import scala.reflect.ClassTag | ||
|
|
||
| case class BaseScalaTemplate[T <: Appendable[T], F <: Format[T]](format: F) { | ||
| // The overloaded methods are here for speed. The compiled templates | ||
| // can take advantage of them for a 12% performance boost | ||
| def _display_(x: AnyVal): T = format.escape(x.toString) | ||
| def _display_(x: String): T = if (x eq null) format.empty else format.escape(x) | ||
| def _display_(x: Unit): T = format.empty | ||
| def _display_(x: scala.xml.NodeSeq): T = if (x eq null) format.empty else format.raw(x.toString()) | ||
| def _display_(x: T): T = if (x eq null) format.empty else x | ||
|
|
||
| def _display_(o: Any)(implicit m: ClassTag[T]): T = { | ||
| o match { | ||
| case escaped if escaped != null && escaped.getClass == m.runtimeClass => escaped.asInstanceOf[T] | ||
| case () => format.empty | ||
| case None => format.empty | ||
| case Some(v) => _display_(v) | ||
| case key: Optional[_] => | ||
| (if (key.isPresent) Some(key.get) else None) match { | ||
| case None => format.empty | ||
| case Some(v) => _display_(v) | ||
| case _ => format.empty | ||
| } | ||
| case xml: scala.xml.NodeSeq => format.raw(xml.toString()) | ||
| case escapeds: immutable.Seq[_] => format.fill(escapeds.map(_display_)) | ||
| case escapeds: IterableOnce[_] => format.fill(escapeds.iterator.map(_display_).toList) | ||
| case escapeds: Array[_] => format.fill(escapeds.view.map(_display_).toList) | ||
| case escapeds: java.util.List[_] => | ||
| format.fill(escapeds.asScala.map(_display_).toList) | ||
| case string: String => format.escape(string) | ||
| case v if v != null => format.escape(v.toString) | ||
| case _ => format.empty | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
api/shared/src/main/scala-2.13/play/twirl/api/TwirlHelperImports.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
| package play.twirl.api | ||
|
|
||
| import scala.language.implicitConversions | ||
|
|
||
| /** | ||
| * Imports for useful Twirl helpers. | ||
| */ | ||
| object TwirlHelperImports { | ||
|
|
||
| /** Allows Java collections to be used as if they were Scala collections. */ | ||
| implicit def twirlJavaCollectionToScala[T](x: java.lang.Iterable[T]): Iterable[T] = { | ||
| import scala.jdk.CollectionConverters._ | ||
| x.asScala | ||
| } | ||
|
|
||
| /** Allows inline formatting of java.util.Date */ | ||
| implicit class TwirlRichDate(date: java.util.Date) { | ||
| def format(pattern: String): String = { | ||
| new java.text.SimpleDateFormat(pattern).format(date) | ||
| } | ||
| } | ||
|
|
||
| /** Adds a when method to Strings to control when they are rendered. */ | ||
| implicit class TwirlRichString(string: String) { | ||
| def when(predicate: => Boolean): String = { | ||
| predicate match { | ||
| case true => string | ||
| case false => "" | ||
| } | ||
| } | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
api/shared/src/main/scala-2.13/play/twirl/api/package.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
| package play.twirl | ||
|
|
||
| import scala.reflect.ClassTag | ||
|
|
||
| package object api { | ||
|
|
||
| /** | ||
| * Brings the template engine as a | ||
| * [[http://docs.scala-lang.org/overviews/core/string-interpolation.html string interpolator]]. | ||
| * | ||
| * Basic usage: | ||
| * | ||
| * {{{ | ||
| * import play.twirl.api.StringInterpolation | ||
| * | ||
| * val name = "Martin" | ||
| * val htmlFragment: Html = html"<div>Hello \$name</div>" | ||
| * }}} | ||
| * | ||
| * Three interpolators are available: `html`, `xml` and `js`. | ||
| */ | ||
| implicit class StringInterpolation(val sc: StringContext) extends AnyVal { | ||
| def html(args: Any*): Html = interpolate(args, HtmlFormat) | ||
|
|
||
| def xml(args: Any*): Xml = interpolate(args, XmlFormat) | ||
|
|
||
| def js(args: Any*): JavaScript = interpolate(args, JavaScriptFormat) | ||
|
|
||
| def interpolate[A <: Appendable[A]: ClassTag](args: Seq[Any], format: Format[A]): A = { | ||
| StringContext.checkLengths(args, sc.parts) | ||
| val array = Array.ofDim[Any](args.size + sc.parts.size) | ||
| val strings = sc.parts.iterator | ||
| val expressions = args.iterator | ||
| array(0) = format.raw(strings.next()) | ||
| var i = 1 | ||
| while (strings.hasNext) { | ||
| array(i) = expressions.next() | ||
| array(i + 1) = format.raw(strings.next()) | ||
| i += 2 | ||
| } | ||
| new BaseScalaTemplate[A, Format[A]](format)._display_(array) | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
api/shared/src/main/scala-3/play/twirl/api/BaseScalaTemplate.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
| package play.twirl.api | ||
|
|
||
| import java.util.Optional | ||
| import scala.collection.immutable | ||
| import scala.jdk.CollectionConverters._ | ||
| import scala.reflect.ClassTag | ||
|
|
||
| case class BaseScalaTemplate[T <: Appendable[T], F <: Format[T]](format: F) { | ||
| // The overloaded methods are here for speed. The compiled templates | ||
| // can take advantage of them for a 12% performance boost | ||
| def _display_(x: AnyVal): T = format.escape(x.toString) | ||
| def _display_(x: String): T = if (x eq null) format.empty else format.escape(x) | ||
| def _display_(x: Unit): T = format.empty | ||
| def _display_(x: scala.xml.NodeSeq): T = if (x eq null) format.empty else format.raw(x.toString()) | ||
| def _display_(x: T): T = if (x eq null) format.empty else x | ||
|
|
||
| def _display_(o: Any)(implicit m: ClassTag[T]): T = { | ||
| o match { | ||
| case escaped if escaped != null && escaped.getClass == m.runtimeClass => escaped.asInstanceOf[T] | ||
| case () => format.empty | ||
| case None => format.empty | ||
| case Some(v) => _display_(v) | ||
| case key: Optional[_] => | ||
| (if (key.isPresent) Some(key.get) else None) match { | ||
| case None => format.empty | ||
| case Some(v) => _display_(v) | ||
| case null => format.empty | ||
| } | ||
| case xml: scala.xml.NodeSeq => format.raw(xml.toString()) | ||
| case escapeds: immutable.Seq[_] => format.fill(escapeds.map(_display_)) | ||
| case escapeds: IterableOnce[_] => format.fill(escapeds.iterator.map(_display_).toList) | ||
| case escapeds: Array[_] => format.fill(escapeds.view.map(_display_).toList) | ||
| case escapeds: java.util.List[_] => | ||
| format.fill(escapeds.asScala.map(_display_).toList) | ||
| case string: String => format.escape(string) | ||
| case v if v != null => format.escape(v.toString) | ||
| case null => format.empty | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
api/shared/src/main/scala-3/play/twirl/api/TwirlHelperImports.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
| package play.twirl.api | ||
|
|
||
| import scala.language.implicitConversions | ||
|
|
||
| /** | ||
| * Imports for useful Twirl helpers. | ||
| */ | ||
| object TwirlHelperImports { | ||
|
|
||
| /** Allows Java collections to be used as if they were Scala collections. */ | ||
| implicit def twirlJavaCollectionToScala[T](x: java.lang.Iterable[T]): Iterable[T] = { | ||
| import scala.jdk.CollectionConverters._ | ||
| x.asScala | ||
| } | ||
|
|
||
| /** Allows inline formatting of java.util.Date */ | ||
| implicit class TwirlRichDate(date: java.util.Date) { | ||
| def format(pattern: String): String = { | ||
| new java.text.SimpleDateFormat(pattern).format(date) | ||
| } | ||
| } | ||
|
|
||
| /** Adds a when method to Strings to control when they are rendered. */ | ||
| implicit class TwirlRichString(string: String) { | ||
| def when(predicate: => Boolean): String = { | ||
| predicate match { | ||
| case true => string | ||
| case false => "" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
| package play.twirl | ||
|
|
||
| import scala.reflect.ClassTag | ||
|
|
||
| package object api { | ||
|
|
||
| /** | ||
| * Brings the template engine as a | ||
| * [[http://docs.scala-lang.org/overviews/core/string-interpolation.html string interpolator]]. | ||
| * | ||
| * Basic usage: | ||
| * | ||
| * {{{ | ||
| * import play.twirl.api.StringInterpolation | ||
| * | ||
| * val name = "Martin" | ||
| * val htmlFragment: Html = html"<div>Hello \$name</div>" | ||
| * }}} | ||
| * | ||
| * Three interpolators are available: `html`, `xml` and `js`. | ||
| */ | ||
| implicit class StringInterpolation(val sc: StringContext) extends AnyVal { | ||
| def html(args: Any*): Html = interpolate(args, HtmlFormat) | ||
|
|
||
| def xml(args: Any*): Xml = interpolate(args, XmlFormat) | ||
|
|
||
| def js(args: Any*): JavaScript = interpolate(args, JavaScriptFormat) | ||
|
|
||
| def interpolate[A <: Appendable[A]: ClassTag](args: Seq[Any], format: Format[A]): A = { | ||
| StringContext.checkLengths(args, sc.parts) | ||
| val array = Array.ofDim[Any](args.size + sc.parts.size) | ||
| val strings = sc.parts.iterator | ||
| val expressions = args.iterator | ||
| array(0) = format.raw(strings.next()) | ||
| var i = 1 | ||
| while (strings.hasNext) { | ||
| array(i) = expressions.next() | ||
| array(i + 1) = format.raw(strings.next()) | ||
| i += 2 | ||
| } | ||
| new BaseScalaTemplate[A, Format[A]](format)._display_(array) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.