@@ -5,16 +5,13 @@ import scala.language.implicitConversions
5
5
6
6
case class Xml (parts : String , args : List [Any ])
7
7
8
- // Ideally should be an implicit class but the implicit conversion
9
- // has to be a inline method
10
- class XmlQuote (val ctx : StringContext ) {
11
- inline def xml (args : => Any * ): Xml = ~ XmlQuote .impl('(this), ' (args))
12
- }
13
-
14
8
object XmlQuote {
15
- implicit inline def XmlQuote (ctx : StringContext ): XmlQuote = new XmlQuote (ctx)
16
9
17
- def impl (receiver : Expr [XmlQuote ], args : Expr [Seq [Any ]])
10
+ implicit class SCOps (ctx : StringContext ) {
11
+ inline def xml (args : => Any * ): Xml = ~ XmlQuote .impl('(this), ' (args))
12
+ }
13
+
14
+ def impl (receiver : Expr [SCOps ], args : Expr [Seq [Any ]])
18
15
(implicit tasty : Tasty ): Expr [Xml ] = {
19
16
import tasty ._
20
17
import Term ._
@@ -41,17 +38,21 @@ object XmlQuote {
41
38
case _ => false
42
39
}
43
40
44
- // _root_.scala.StringContext.apply([p0, ...]: String*)
41
+ def isSCOpsConversion (tree : Term ) =
42
+ tree.symbol.fullName == " XmlQuote$.SCOps"
43
+
44
+ def isStringContextApply (tree : Term ) =
45
+ tree.symbol.fullName == " scala.StringContext$.apply"
46
+
47
+ // XmlQuote.SCOps(StringContext.apply([p0, ...]: String*)
45
48
val parts = receiver.toTasty.underlyingArgument match {
46
- case Apply (
47
- Select (New (_), _, _),
48
- List (
49
- Apply (
50
- Select (Select (Select (Ident (" _root_" ), " scala" , _), " StringContext" , _), " apply" , _),
51
- List (Typed (Repeated (values), _))))) if values.forall(isStringConstant) =>
49
+ case Apply (conv, List (Apply (fun, List (Typed (Repeated (values), _)))))
50
+ if isSCOpsConversion(conv) &&
51
+ isStringContextApply(fun) &&
52
+ values.forall(isStringConstant) =>
52
53
values.collect { case Literal (Constant .String (value)) => value }
53
54
case tree =>
54
- abort(s " String literal expected, but $tree found " )
55
+ abort(s " String literal expected, but ${ tree.show} found " )
55
56
}
56
57
57
58
// [a0, ...]: Any*
0 commit comments