@@ -13,7 +13,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
13
13
def symbol (implicit ctx : Context ): Symbol = tree.symbol
14
14
}
15
15
16
- object IsPackageClause extends IsPackageClauseExtractor {
16
+ object IsPackageClause extends IsPackageClauseModule {
17
17
def unapply (tree : Tree )(implicit ctx : Context ): Option [PackageClause ] = tree match {
18
18
case x : tpd.PackageDef => Some (x)
19
19
case _ => None
@@ -47,7 +47,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
47
47
48
48
// ----- Definitions ----------------------------------------------
49
49
50
- object IsDefinition extends IsDefinitionExtractor {
50
+ object IsDefinition extends IsDefinitionModule {
51
51
def unapply (tree : Tree )(implicit ctx : Context ): Option [Definition ] = tree match {
52
52
case tree : tpd.MemberDef => Some (tree)
53
53
case tree : PackageDefinition => Some (tree)
@@ -61,7 +61,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
61
61
62
62
// ClassDef
63
63
64
- object IsClassDef extends IsClassDefExtractor {
64
+ object IsClassDef extends IsClassDefModule {
65
65
def unapply (tree : Tree )(implicit ctx : Context ): Option [ClassDef ] = tree match {
66
66
case x : tpd.TypeDef if x.isClassDef => Some (x)
67
67
case _ => None
@@ -87,7 +87,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
87
87
88
88
// DefDef
89
89
90
- object IsDefDef extends IsDefDefExtractor {
90
+ object IsDefDef extends IsDefDefModule {
91
91
def unapply (tree : Tree )(implicit ctx : Context ): Option [DefDef ] = tree match {
92
92
case x : tpd.DefDef => Some (x)
93
93
case _ => None
@@ -112,7 +112,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
112
112
113
113
// ValDef
114
114
115
- object IsValDef extends IsValDefExtractor {
115
+ object IsValDef extends IsValDefModule {
116
116
def unapply (tree : Tree )(implicit ctx : Context ): Option [ValDef ] = tree match {
117
117
case x : tpd.ValDef => Some (x)
118
118
case _ => None
@@ -135,7 +135,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
135
135
136
136
// TypeDef
137
137
138
- object IsTypeDef extends IsTypeDefExtractor {
138
+ object IsTypeDef extends IsTypeDefModule {
139
139
def unapply (tree : Tree )(implicit ctx : Context ): Option [TypeDef ] = tree match {
140
140
case x : tpd.TypeDef if ! x.symbol.isClass => Some (x)
141
141
case _ => None
@@ -168,7 +168,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
168
168
def symbol (implicit ctx : Context ): PackageSymbol = pdef.symbol
169
169
}
170
170
171
- object IsPackageDef extends IsPackageDefExtractor {
171
+ object IsPackageDef extends IsPackageDefModule {
172
172
def unapply (tree : Tree )(implicit ctx : Context ): Option [PackageDef ] = tree match {
173
173
case x : PackageDefinition => Some (x)
174
174
case _ => None
@@ -193,7 +193,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
193
193
def underlying (implicit ctx : Context ): Term = term.underlying
194
194
}
195
195
196
- object IsTerm extends IsTermExtractor {
196
+ object IsTerm extends IsTermModule {
197
197
def unapply (tree : Tree )(implicit ctx : Context ): Option [Term ] =
198
198
if (tree.isTerm) Some (tree) else None
199
199
def unapply (termOrTypeTree : TermOrTypeTree )(implicit ctx : Context , dummy : DummyImplicit ): Option [Term ] =
@@ -202,13 +202,27 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
202
202
203
203
object Term extends TermModule with TermCoreModuleImpl {
204
204
205
+ object IsIdent extends IsIdentModule {
206
+ def unapply (x : Term )(implicit ctx : Context ): Option [Ident ] = x match {
207
+ case x : tpd.Ident if x.isTerm => Some (x)
208
+ case _ => None
209
+ }
210
+ }
211
+
205
212
object Ident extends IdentExtractor {
206
213
def unapply (x : Term )(implicit ctx : Context ): Option [String ] = x match {
207
214
case x : tpd.Ident if x.isTerm => Some (x.name.show)
208
215
case _ => None
209
216
}
210
217
}
211
218
219
+ object IsSelect extends IsSelectModule {
220
+ def unapply (x : Term )(implicit ctx : Context ): Option [Select ] = x match {
221
+ case x : tpd.Select if x.isTerm => Some (x)
222
+ case _ => None
223
+ }
224
+ }
225
+
212
226
object Select extends SelectExtractor {
213
227
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , String , Option [Signature ])] = x match {
214
228
case x : tpd.Select if x.isTerm =>
@@ -220,69 +234,139 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
220
234
}
221
235
}
222
236
237
+ object IsLiteral extends IsLiteralModule {
238
+ def unapply (x : Term )(implicit ctx : Context ): Option [Literal ] = x match {
239
+ case x : tpd.Literal => Some (x)
240
+ case _ => None
241
+ }
242
+ }
243
+
223
244
object Literal extends LiteralExtractor {
224
245
def unapply (x : Term )(implicit ctx : Context ): Option [Constant ] = x match {
225
246
case Trees .Literal (const) => Some (const)
226
247
case _ => None
227
248
}
228
249
}
229
250
251
+ object IsThis extends IsThisModule {
252
+ def unapply (x : Term )(implicit ctx : Context ): Option [This ] = x match {
253
+ case x : tpd.This => Some (x)
254
+ case _ => None
255
+ }
256
+ }
257
+
230
258
object This extends ThisExtractor {
231
259
def unapply (x : Term )(implicit ctx : Context ): Option [Option [Id ]] = x match {
232
260
case Trees .This (qual) => Some (optional(qual))
233
261
case _ => None
234
262
}
235
263
}
236
264
265
+ object IsNew extends IsNewModule {
266
+ def unapply (x : Term )(implicit ctx : Context ): Option [New ] = x match {
267
+ case x : tpd.New => Some (x)
268
+ case _ => None
269
+ }
270
+ }
271
+
237
272
object New extends NewExtractor {
238
273
def unapply (x : Term )(implicit ctx : Context ): Option [TypeTree ] = x match {
239
274
case x : tpd.New => Some (x.tpt)
240
275
case _ => None
241
276
}
242
277
}
243
278
279
+ object IsNamedArg extends IsNamedArgModule {
280
+ def unapply (x : Term )(implicit ctx : Context ): Option [NamedArg ] = x match {
281
+ case x : tpd.NamedArg if x.name.isInstanceOf [Names .TermName ] => Some (x) // TODO: Now, the name should alwas be a term name
282
+ case _ => None
283
+ }
284
+ }
285
+
244
286
object NamedArg extends NamedArgExtractor {
245
287
def unapply (x : Term )(implicit ctx : Context ): Option [(String , Term )] = x match {
246
288
case x : tpd.NamedArg if x.name.isInstanceOf [Names .TermName ] => Some ((x.name.toString, x.arg))
247
289
case _ => None
248
290
}
249
291
}
250
292
293
+ object IsApply extends IsApplyModule {
294
+ def unapply (x : Term )(implicit ctx : Context ): Option [Apply ] = x match {
295
+ case x : tpd.Apply => Some (x)
296
+ case _ => None
297
+ }
298
+ }
299
+
251
300
object Apply extends ApplyExtractor {
252
301
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [Term ])] = x match {
253
302
case x : tpd.Apply => Some ((x.fun, x.args))
254
303
case _ => None
255
304
}
256
305
}
257
306
307
+ object IsTypeApply extends IsTypeApplyModule {
308
+ def unapply (x : Term )(implicit ctx : Context ): Option [TypeApply ] = x match {
309
+ case x : tpd.TypeApply => Some (x)
310
+ case _ => None
311
+ }
312
+ }
313
+
258
314
object TypeApply extends TypeApplyExtractor {
259
315
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [TypeTree ])] = x match {
260
316
case x : tpd.TypeApply => Some ((x.fun, x.args))
261
317
case _ => None
262
318
}
263
319
}
264
320
321
+ object IsSuper extends IsSuperModule {
322
+ def unapply (x : Term )(implicit ctx : Context ): Option [Super ] = x match {
323
+ case x : tpd.Super => Some (x)
324
+ case _ => None
325
+ }
326
+ }
327
+
265
328
object Super extends SuperExtractor {
266
329
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Option [Id ])] = x match {
267
330
case x : tpd.Super => Some ((x.qual, if (x.mix.isEmpty) None else Some (x.mix)))
268
331
case _ => None
269
332
}
270
333
}
271
334
335
+ object IsTyped extends IsTypedModule {
336
+ def unapply (x : Term )(implicit ctx : Context ): Option [Typed ] = x match {
337
+ case x : tpd.Typed => Some (x)
338
+ case _ => None
339
+ }
340
+ }
341
+
272
342
object Typed extends TypedExtractor {
273
343
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , TypeTree )] = x match {
274
344
case x : tpd.Typed => Some ((x.expr, x.tpt))
275
345
case _ => None
276
346
}
277
347
}
278
348
349
+ object IsAssign extends IsAssignModule {
350
+ def unapply (x : Term )(implicit ctx : Context ): Option [Assign ] = x match {
351
+ case x : tpd.Assign => Some (x)
352
+ case _ => None
353
+ }
354
+ }
355
+
279
356
object Assign extends AssignExtractor {
280
357
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Term )] = x match {
281
358
case x : tpd.Assign => Some ((x.lhs, x.rhs))
282
359
case _ => None
283
360
}
284
361
}
285
362
363
+ object IsBlock extends IsBlockModule {
364
+ def unapply (x : Term )(implicit ctx : Context ): Option [Block ] = Block .normalizedLoops(x) match {
365
+ case x : tpd.Block => Some (x)
366
+ case _ => None
367
+ }
368
+ }
369
+
286
370
object Block extends BlockExtractor {
287
371
def unapply (x : Term )(implicit ctx : Context ): Option [(List [Statement ], Term )] = normalizedLoops(x) match {
288
372
case Trees .Block (stats, expr) => Some ((stats, expr))
@@ -292,7 +376,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
292
376
* i) Put `while` and `doWhile` loops in their own blocks: `{ def while$() = ...; while$() }`
293
377
* ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }`
294
378
*/
295
- private def normalizedLoops (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
379
+ private [ Term ] def normalizedLoops (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
296
380
case block : tpd.Block if block.stats.size > 1 =>
297
381
def normalizeInnerLoops (stats : List [tpd.Tree ]): List [tpd.Tree ] = stats match {
298
382
case (x : tpd.DefDef ) :: y :: xs if needsNormalization(y) =>
@@ -318,6 +402,13 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
318
402
}
319
403
}
320
404
405
+ object IsInlined extends IsInlinedModule {
406
+ def unapply (x : Term )(implicit ctx : Context ): Option [Inlined ] = x match {
407
+ case x : tpd.Inlined => Some (x)
408
+ case _ => None
409
+ }
410
+ }
411
+
321
412
object Inlined extends InlinedExtractor {
322
413
def unapply (x : Term )(implicit ctx : Context ): Option [(Option [TermOrTypeTree ], List [Statement ], Term )] = x match {
323
414
case x : tpd.Inlined =>
@@ -326,48 +417,101 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
326
417
}
327
418
}
328
419
420
+ object IsLambda extends IsLambdaModule {
421
+ def unapply (x : Term )(implicit ctx : Context ): Option [Lambda ] = x match {
422
+ case x : tpd.Closure => Some (x)
423
+ case _ => None
424
+ }
425
+ }
426
+
329
427
object Lambda extends LambdaExtractor {
330
428
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Option [TypeTree ])] = x match {
331
429
case x : tpd.Closure => Some ((x.meth, optional(x.tpt)))
332
430
case _ => None
333
431
}
334
432
}
335
433
434
+ object IsIf extends IsIfModule {
435
+ def unapply (x : Term )(implicit ctx : Context ): Option [If ] = x match {
436
+ case x : tpd.If => Some (x)
437
+ case _ => None
438
+ }
439
+ }
440
+
336
441
object If extends IfExtractor {
337
442
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Term , Term )] = x match {
338
443
case x : tpd.If => Some ((x.cond, x.thenp, x.elsep))
339
444
case _ => None
340
445
}
341
446
}
342
447
448
+ object IsMatch extends IsMatchModule {
449
+ def unapply (x : Term )(implicit ctx : Context ): Option [Match ] = x match {
450
+ case x : tpd.Match => Some (x)
451
+ case _ => None
452
+ }
453
+ }
454
+
343
455
object Match extends MatchExtractor {
344
456
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [CaseDef ])] = x match {
345
457
case x : tpd.Match => Some ((x.selector, x.cases))
346
458
case _ => None
347
459
}
348
460
}
349
461
462
+ object IsTry extends IsTryModule {
463
+ def unapply (x : Term )(implicit ctx : Context ): Option [Try ] = x match {
464
+ case x : tpd.Try => Some (x)
465
+ case _ => None
466
+ }
467
+ }
468
+
350
469
object Try extends TryExtractor {
351
470
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [CaseDef ], Option [Term ])] = x match {
352
471
case x : tpd.Try => Some ((x.expr, x.cases, optional(x.finalizer)))
353
472
case _ => None
354
473
}
355
474
}
356
475
476
+ object IsReturn extends IsReturnModule {
477
+ def unapply (x : Term )(implicit ctx : Context ): Option [Return ] = x match {
478
+ case x : tpd.Return => Some (x)
479
+ case _ => None
480
+ }
481
+ }
482
+
357
483
object Return extends ReturnExtractor {
358
484
def unapply (x : Term )(implicit ctx : Context ): Option [Term ] = x match {
359
485
case x : tpd.Return => Some (x.expr)
360
486
case _ => None
361
487
}
362
488
}
363
489
490
+ object IsRepeated extends IsRepeatedModule {
491
+ def unapply (x : Term )(implicit ctx : Context ): Option [Repeated ] = x match {
492
+ case x : tpd.SeqLiteral => Some (x)
493
+ case _ => None
494
+ }
495
+ }
496
+
364
497
object Repeated extends RepeatedExtractor {
365
498
def unapply (x : Term )(implicit ctx : Context ): Option [List [Term ]] = x match {
366
499
case x : tpd.SeqLiteral => Some (x.elems)
367
500
case _ => None
368
501
}
369
502
}
370
503
504
+ object IsSelectOuter extends IsSelectOuterModule {
505
+ def unapply (x : Term )(implicit ctx : Context ): Option [SelectOuter ] = x match {
506
+ case x : tpd.Select =>
507
+ x.name match {
508
+ case NameKinds .OuterSelectName (_, _) => Some (x)
509
+ case _ => None
510
+ }
511
+ case _ => None
512
+ }
513
+ }
514
+
371
515
object SelectOuter extends SelectOuterExtractor {
372
516
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Int , Type )] = x match {
373
517
case x : tpd.Select =>
@@ -379,6 +523,13 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
379
523
}
380
524
}
381
525
526
+ object IsWhile extends IsWhileModule {
527
+ def unapply (x : Term )(implicit ctx : Context ): Option [While ] = x match {
528
+ case x : tpd.WhileDo => Some (x)
529
+ case _ => None
530
+ }
531
+ }
532
+
382
533
object While extends WhileExtractor {
383
534
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Term )] = x match {
384
535
case x : tpd.WhileDo => Some ((x.cond, x.body))
0 commit comments