@@ -15,32 +15,68 @@ case class NoAutoTupling(mirror: Mirror) extends SemanticRewrite(mirror) {
15
15
ctx.addLeft(args.head.tokens.head, " (" ) +
16
16
ctx.addRight(args.last.tokens.last, " )" )
17
17
18
+ private [this ] def fixMethods (ctx : RewriteCtx ,
19
+ jvmSignature : String ,
20
+ argss : Seq [Seq [Term .Arg ]],
21
+ fixed : mutable.Set [Seq [Term .Arg ]]): Patch = {
22
+ val argListSignatures =
23
+ jvmSignature.stripPrefix(" (" ).takeWhile(_ != ')' ).split(';' )
24
+ argListSignatures
25
+ .zip(argss)
26
+ .foldLeft(Patch .empty) {
27
+ case (patches, (argListSignature, args)) =>
28
+ if (! fixed(args) && singleTuplePattern
29
+ .matcher(argListSignature)
30
+ .matches && args.length > 1 ) {
31
+ fixed += args // dirty hack, see explanation above
32
+ patches + addWrappingParens(ctx, args)
33
+ } else {
34
+ patches
35
+ }
36
+ }
37
+ }
38
+
39
+ private [this ] def fixFunctions (ctx : RewriteCtx ,
40
+ symbol : Symbol ,
41
+ argss : Seq [Seq [Term .Arg ]],
42
+ fixed : mutable.Set [Seq [Term .Arg ]],
43
+ mirror : Mirror ): Patch =
44
+ mirror.database.denotations
45
+ .get(symbol)
46
+ .map { denot =>
47
+ val argListSignatures =
48
+ denot.info.split(" =>" ).map(_.trim).toList.dropRight(1 )
49
+ argListSignatures
50
+ .zip(argss)
51
+ .foldLeft(Patch .empty) {
52
+ case (patches, (argListSignature, args)) =>
53
+ if (! fixed(args) && argListSignature.startsWith(" ((" ) && argListSignature
54
+ .endsWith(" ))" )
55
+ && args.length > 1 ) {
56
+ fixed += args
57
+ patches + addWrappingParens(ctx, args)
58
+ } else {
59
+ patches
60
+ }
61
+ }
62
+ }
63
+ .asPatch
64
+
18
65
override def rewrite (ctx : RewriteCtx ): Patch = {
19
66
// "hack" to avoid fixing an argument list more than once due
20
67
// to recursive matching of multiple parameters lists.
21
68
val fixed = mutable.Set .empty[Seq [Term .Arg ]]
22
69
ctx.tree.collect {
23
70
case q " ${fun : Term .Ref }(... $argss) " if argss.nonEmpty =>
24
- fun.symbolOpt
25
- .collect {
26
- case Symbol .Global (_, Signature .Method (_, jvmSignature)) =>
27
- val argListSignatures =
28
- jvmSignature.stripPrefix(" (" ).takeWhile(_ != ')' ).split(';' )
29
- argListSignatures
30
- .zip(argss)
31
- .foldLeft(Patch .empty) {
32
- case (patches, (argListSignature, args)) =>
33
- if (! fixed(args) && singleTuplePattern
34
- .matcher(argListSignature)
35
- .matches && args.length > 1 ) {
36
- fixed += args // dirty hack, see explanation above
37
- patches + addWrappingParens(ctx, args)
38
- } else {
39
- patches
40
- }
41
- }
42
- }
43
- .getOrElse(Patch .empty)
71
+ fun.symbolOpt.collect {
72
+ case s @ Symbol .Global (_, Signature .Method (_, jvmSignature)) =>
73
+ fixMethods(ctx, jvmSignature, argss, fixed) +
74
+ fixFunctions(ctx, s, argss, fixed, mirror)
75
+
76
+ case s @ Symbol .Global (_, Signature .Term (x))
77
+ if mirror.database.denotations.get(s).isDefined =>
78
+ fixFunctions(ctx, s, argss, fixed, mirror)
79
+ }.asPatch
44
80
}.asPatch
45
81
}
46
82
}
0 commit comments