@@ -110,6 +110,24 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
110
110
case _ => 0
111
111
}
112
112
113
+ /** The type arguments of a possibly curried call */
114
+ def typeArgss (tree : Tree ): List [List [Tree ]] =
115
+ @ tailrec
116
+ def loop (tree : Tree , argss : List [List [Tree ]]): List [List [Tree ]] = tree match
117
+ case TypeApply (fn, args) => loop(fn, args :: argss)
118
+ case Apply (fn, args) => loop(fn, argss)
119
+ case _ => argss
120
+ loop(tree, Nil )
121
+
122
+ /** The term arguments of a possibly curried call */
123
+ def termArgss (tree : Tree ): List [List [Tree ]] =
124
+ @ tailrec
125
+ def loop (tree : Tree , argss : List [List [Tree ]]): List [List [Tree ]] = tree match
126
+ case Apply (fn, args) => loop(fn, args :: argss)
127
+ case TypeApply (fn, args) => loop(fn, argss)
128
+ case _ => argss
129
+ loop(tree, Nil )
130
+
113
131
/** All term arguments of an application in a single flattened list */
114
132
def allArguments (tree : Tree ): List [Tree ] = unsplice(tree) match {
115
133
case Apply (fn, args) => allArguments(fn) ::: args
@@ -342,26 +360,19 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
342
360
* * callee = foo
343
361
* * core = foo
344
362
* * targs = Nil
345
- * * argss = List(List(arg11, arg12 ...), List(arg21, arg22 , ...))
363
+ * * argss = List(List(arg21, arg22, ...), List(arg11, arg12 , ...))
346
364
*
347
365
* Apply(Apply(TypeApply(foo, List(targs1, targs2, ...)), List(arg21, arg22, ...)), List(arg11, arg12...))
348
366
* * callee = TypeApply(foo, List(targs1, targs2, ...))
349
367
* * core = foo
350
368
* * targs = Nil
351
- * * argss = List(List(arg11, arg12 ...), List(arg21, arg22 , ...))
369
+ * * argss = List(List(arg21, arg22, ...), List(arg11, arg12 , ...))
352
370
*/
353
371
final class Applied (val tree : Tree ) {
354
372
/** The tree stripped of the possibly nested applications.
355
373
* The original tree if it's not an application.
356
374
*/
357
- def callee : Tree = {
358
- @ tailrec
359
- def loop (tree : Tree ): Tree = tree match {
360
- case Apply (fn, _) => loop(fn)
361
- case tree => tree
362
- }
363
- loop(tree)
364
- }
375
+ def callee : Tree = stripApply(tree)
365
376
366
377
/** The `callee` unwrapped from type applications.
367
378
* The original `callee` if it's not a type application.
@@ -384,28 +395,7 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
384
395
/** (Possibly multiple lists of) value arguments of an application.
385
396
* `Nil` if the `callee` is not an application.
386
397
*/
387
- def argss : List [List [Tree ]] = {
388
- def loop (tree : Tree ): List [List [Tree ]] = tree match {
389
- case Apply (fn, args) => loop(fn) :+ args
390
- case _ => Nil
391
- }
392
- loop(tree)
393
- }
394
- }
395
-
396
- /** Returns a wrapper that knows how to destructure and analyze applications.
397
- */
398
- final def dissectApplied (tree : Tree ) = new Applied (tree)
399
-
400
- /** Equivalent ot disectApplied(tree).core, but more efficient */
401
- @ scala.annotation.tailrec
402
- final def dissectCore (tree : Tree ): Tree = tree match {
403
- case TypeApply (fun, _) =>
404
- dissectCore(fun)
405
- case Apply (fun, _) =>
406
- dissectCore(fun)
407
- case t =>
408
- t
398
+ def argss : List [List [Tree ]] = termArgss(tree)
409
399
}
410
400
411
401
/** Destructures applications into important subparts described in `Applied` class,
@@ -424,7 +414,7 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
424
414
Some ((applied.core, applied.targs, applied.argss))
425
415
426
416
def unapply (tree : Tree ): Some [(Tree , List [Tree ], List [List [Tree ]])] =
427
- unapply(dissectApplied (tree))
417
+ unapply(new Applied (tree))
428
418
}
429
419
430
420
/** Is tree an application with result `this.type`?
@@ -442,8 +432,9 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
442
432
def checkSingle (sym : Symbol ): Boolean =
443
433
(sym == receiver.symbol) || {
444
434
receiver match {
445
- case Apply (_, _) => op.isOpAssignmentName // xs(i) += x
446
- case _ => receiver.symbol.isGetter || receiver.symbol.isField // xs.addOne(x) for var xs
435
+ case Apply (_, _) => op.isOpAssignmentName // xs(i) += x
436
+ case _ => receiver.symbol != NoSymbol &&
437
+ (receiver.symbol.isGetter || receiver.symbol.isField) // xs.addOne(x) for var xs
447
438
}
448
439
}
449
440
@ tailrec def loop (mt : Type ): Boolean = mt match {
@@ -456,7 +447,7 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
456
447
case PolyType (_, restpe) => loop(restpe)
457
448
case _ => false
458
449
}
459
- loop(fun.symbol.info)
450
+ fun.symbol != NoSymbol && loop(fun.symbol.info)
460
451
}
461
452
case _ =>
462
453
tree.tpe.isInstanceOf [ThisType ]
@@ -836,24 +827,6 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
836
827
}
837
828
}
838
829
839
- /** The type arguments of a possibly curried call */
840
- def typeArgss (tree : Tree ): List [List [Tree ]] =
841
- @ tailrec
842
- def loop (tree : Tree , argss : List [List [Tree ]]): List [List [Tree ]] = tree match
843
- case TypeApply (fn, args) => loop(fn, args :: argss)
844
- case Apply (fn, args) => loop(fn, argss)
845
- case _ => argss
846
- loop(tree, Nil )
847
-
848
- /** The term arguments of a possibly curried call */
849
- def termArgss (tree : Tree ): List [List [Tree ]] =
850
- @ tailrec
851
- def loop (tree : Tree , argss : List [List [Tree ]]): List [List [Tree ]] = tree match
852
- case Apply (fn, args) => loop(fn, args :: argss)
853
- case TypeApply (fn, args) => loop(fn, argss)
854
- case _ => argss
855
- loop(tree, Nil )
856
-
857
830
/** The type and term arguments of a possibly curried call, in the order they are given */
858
831
def allArgss (tree : Tree ): List [List [Tree ]] =
859
832
@ tailrec
0 commit comments