Skip to content

Commit 757c3c7

Browse files
committed
Add missing extension methods
1 parent 989eb02 commit 757c3c7

File tree

4 files changed

+126
-34
lines changed

4 files changed

+126
-34
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
4949
}
5050

5151
def ConstantTypeDeco(x: ConstantType): ConstantTypeAPI = new ConstantTypeAPI {
52-
52+
def value(implicit ctx: Context): Any = x.value
5353
}
5454

5555
object ConstantType extends ConstantTypeExtractor {
@@ -60,7 +60,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
6060
}
6161

6262
object IsSymRef extends IsSymRefModule {
63-
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = tpe match {
63+
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = tpe match {
6464
case tp: Types.NamedType =>
6565
tp.designator match {
6666
case sym: Symbol => Some(tp)
@@ -71,7 +71,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
7171
}
7272

7373
def SymRefDeco(x: SymRef): SymRefAPI = new SymRefAPI {
74-
74+
def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix
7575
}
7676

7777
object SymRef extends SymRefExtractor {
@@ -97,7 +97,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
9797
}
9898

9999
def TermRefDeco(x: TermRef): TermRefAPI = new TermRefAPI {
100-
100+
def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix
101101
}
102102

103103
object TermRef extends TermRefExtractor {
@@ -123,7 +123,8 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
123123
}
124124

125125
def TypeRefDeco(x: TypeRef): TypeRefAPI = new TypeRefAPI {
126-
126+
def name(implicit ctx: Context): String = x.name.toString
127+
def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix
127128
}
128129

129130
object TypeRef extends TypeRefExtractor {
@@ -145,7 +146,8 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
145146
}
146147

147148
def SuperTypeDeco(x: SuperType): SuperTypeAPI = new SuperTypeAPI {
148-
149+
def thistpe(implicit ctx: Context): Type = x.thistpe
150+
def supertpe(implicit ctx: Context): Type = x.supertpe
149151
}
150152

151153
object SuperType extends SuperTypeExtractor {
@@ -163,7 +165,9 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
163165
}
164166

165167
def RefinementDeco(x: Refinement): RefinementAPI = new RefinementAPI {
166-
168+
def parent(implicit ctx: Context): Type = x.parent
169+
def name(implicit ctx: Context): String = x.refinedName.toString
170+
def info(implicit ctx: Context): TypeOrBounds = x.refinedInfo
167171
}
168172

169173
object Refinement extends RefinementExtractor {
@@ -181,7 +185,8 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
181185
}
182186

183187
def AppliedTypeDeco(x: AppliedType): AppliedTypeAPI = new AppliedTypeAPI {
184-
188+
def tycon(implicit ctx: Context): Type = x.tycon
189+
def args(implicit ctx: Context): List[TypeOrBounds] = x.args
185190
}
186191

187192
object AppliedType extends AppliedTypeExtractor {
@@ -199,7 +204,8 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
199204
}
200205

201206
def AnnotatedTypeDeco(x: AnnotatedType): AnnotatedTypeAPI = new AnnotatedTypeAPI {
202-
207+
def underlying(implicit ctx: Context): Type = x.underlying.stripTypeVar
208+
def annot(implicit ctx: Context): Term = x.annot.tree
203209
}
204210

205211
object AnnotatedType extends AnnotatedTypeExtractor {
@@ -217,7 +223,8 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
217223
}
218224

219225
def AndTypeDeco(x: AndType): AndTypeAPI = new AndTypeAPI {
220-
226+
def left(implicit ctx: Context): Type = x.tp1.stripTypeVar
227+
def right(implicit ctx: Context): Type = x.tp2.stripTypeVar
221228
}
222229

223230
object AndType extends AndTypeExtractor {
@@ -235,7 +242,8 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
235242
}
236243

237244
def OrTypeDeco(x: OrType): OrTypeAPI = new OrTypeAPI {
238-
245+
def left(implicit ctx: Context): Type = x.tp1
246+
def right(implicit ctx: Context): Type = x.tp2
239247
}
240248

241249
object OrType extends OrTypeExtractor {
@@ -253,7 +261,9 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
253261
}
254262

255263
def MatchTypeDeco(x: MatchType): MatchTypeAPI = new MatchTypeAPI {
256-
264+
def bound(implicit ctx: Context): Type = x.bound
265+
def scrutinee(implicit ctx: Context): Type = x.scrutinee
266+
def cases(implicit ctx: Context): List[Type] = x.cases
257267
}
258268

259269
object MatchType extends MatchTypeExtractor {
@@ -271,7 +281,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
271281
}
272282

273283
def ByNameTypeDeco(x: ByNameType): ByNameTypeAPI = new ByNameTypeAPI {
274-
284+
def underlying(implicit ctx: Context): Type = x.resType.stripTypeVar
275285
}
276286

277287
object ByNameType extends ByNameTypeExtractor {
@@ -290,7 +300,9 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
290300
}
291301

292302
def ParamRefDeco(x: ParamRef): ParamRefAPI = new ParamRefAPI {
293-
303+
def binder(implicit ctx: Context): LambdaType[TypeOrBounds] =
304+
x.binder.asInstanceOf[LambdaType[TypeOrBounds]] // Cast to tpd
305+
def paramNum(implicit ctx: Context): Int = x.paramNum
294306
}
295307

296308
object ParamRef extends ParamRefExtractor {
@@ -312,7 +324,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
312324
}
313325

314326
def ThisTypeDeco(x: ThisType): ThisTypeAPI = new ThisTypeAPI {
315-
327+
def underlying(implicit ctx: Context): Type = x.underlying
316328
}
317329

318330
object ThisType extends ThisTypeExtractor {
@@ -330,7 +342,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
330342
}
331343

332344
def RecursiveThisDeco(x: RecursiveThis): RecursiveThisAPI = new RecursiveThisAPI {
333-
345+
def binder(implicit ctx: Context): RecursiveType = x.binder
334346
}
335347

336348
object RecursiveThis extends RecursiveThisExtractor {
@@ -348,7 +360,7 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
348360
}
349361

350362
def RecursiveTypeDeco(x: RecursiveType): RecursiveTypeAPI = new RecursiveTypeAPI {
351-
363+
def underlying(implicit ctx: Context): Type = x.underlying.stripTypeVar
352364
}
353365

354366
object RecursiveType extends RecursiveTypeExtractor {
@@ -366,7 +378,9 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
366378
}
367379

368380
def MethodTypeDeco(x: MethodType): MethodTypeAPI = new MethodTypeAPI {
369-
381+
def paramNames(implicit ctx: Context): List[String] = x.paramNames.map(_.toString)
382+
def paramTypes(implicit ctx: Context): List[Type] = x.paramInfos
383+
def resType(implicit ctx: Context): Type = x.resType
370384
}
371385

372386
object MethodType extends MethodTypeExtractor {
@@ -384,7 +398,9 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
384398
}
385399

386400
def PolyTypeDeco(x: PolyType): PolyTypeAPI = new PolyTypeAPI {
387-
401+
def paramNames(implicit ctx: Contexts.Context): List[String] = x.paramNames.map(_.toString)
402+
def paramBounds(implicit ctx: Contexts.Context): List[TypeBounds] = x.paramInfos
403+
def resType(implicit ctx: Contexts.Context): Type = x.resType
388404
}
389405

390406
object PolyType extends PolyTypeExtractor {
@@ -402,7 +418,9 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI
402418
}
403419

404420
def TypeLambdaDeco(x: TypeLambda): TypeLambdaAPI = new TypeLambdaAPI {
405-
421+
def paramNames(implicit ctx: Contexts.Context): List[String] = x.paramNames.map(_.toString)
422+
def paramBounds(implicit ctx: Contexts.Context): List[TypeBounds] = x.paramInfos
423+
def resType(implicit ctx: Contexts.Context): Type = x.resType
406424
}
407425

408426
object TypeLambda extends TypeLambdaExtractor {

compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
5757
}
5858

5959
def IdentDeco(x: Ident): IdentAPI = new IdentAPI {
60-
60+
def name(implicit ctx: Contexts.Context): String = x.name.toString
6161
}
6262

6363
object Ident extends IdentExtractor {
@@ -75,7 +75,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
7575
}
7676

7777
def SelectDeco(x: Select): SelectAPI = new SelectAPI {
78-
78+
def qualifier(implicit ctx: Contexts.Context): Term = x.qualifier
79+
def name(implicit ctx: Contexts.Context): String = x.name.toString
7980
}
8081

8182
object Select extends SelectExtractor {
@@ -93,7 +94,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
9394
}
9495

9596
def ProjectDeco(x: Project): ProjectAPI = new ProjectAPI {
96-
97+
def qualifier(implicit ctx: Contexts.Context): TypeTree = x.qualifier
98+
def name(implicit ctx: Contexts.Context): String = x.name.toString
9799
}
98100

99101
object Project extends ProjectExtractor {
@@ -111,7 +113,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
111113
}
112114

113115
def SingletonDeco(x: Singleton): SingletonAPI = new SingletonAPI {
114-
116+
def ref(implicit ctx: Contexts.Context): Term = x.ref
115117
}
116118

117119
object Singleton extends SingletonExtractor {
@@ -129,7 +131,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
129131
}
130132

131133
def RefinedDeco(x: Refined): RefinedAPI = new RefinedAPI {
132-
134+
def tpt(implicit ctx: Contexts.Context): TypeTree = x.tpt
135+
def refinements(implicit ctx: Contexts.Context): List[Definition] = x.refinements
133136
}
134137

135138
object Refined extends RefinedExtractor {
@@ -147,7 +150,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
147150
}
148151

149152
def AppliedDeco(x: Applied): AppliedAPI = new AppliedAPI {
150-
153+
def tpt(implicit ctx: Contexts.Context): TypeTree = x.tpt
154+
def args(implicit ctx: Contexts.Context): List[TypeOrBoundsTree] = x.args
151155
}
152156

153157
object Applied extends AppliedExtractor {
@@ -165,7 +169,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
165169
}
166170

167171
def AnnotatedDeco(x: Annotated): AnnotatedAPI = new AnnotatedAPI {
168-
172+
def arg(implicit ctx: Contexts.Context): TypeTree = x.arg
173+
def annotation(implicit ctx: Contexts.Context): Term = x.annot
169174
}
170175

171176
object Annotated extends AnnotatedExtractor {
@@ -183,7 +188,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
183188
}
184189

185190
def AndDeco(x: And): OrAPI = new OrAPI {
186-
191+
def left(implicit ctx: Contexts.Context): TypeTree = x.left
192+
def right(implicit ctx: Contexts.Context): TypeTree = x.right
187193
}
188194

189195
object And extends AndExtractor {
@@ -201,7 +207,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
201207
}
202208

203209
def OrDeco(x: Or): OrAPI = new OrAPI {
204-
210+
def left(implicit ctx: Contexts.Context): TypeTree = x.left
211+
def right(implicit ctx: Contexts.Context): TypeTree = x.right
205212
}
206213

207214
object Or extends OrExtractor {
@@ -219,7 +226,9 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
219226
}
220227

221228
def MatchTypeDeco(x: MatchType): MatchTypeAPI = new MatchTypeAPI {
222-
229+
def bound(implicit ctx: Contexts.Context): Option[TypeTree] = if (x.bound == tpd.EmptyTree) None else Some(x.bound)
230+
def selector(implicit ctx: Contexts.Context): TypeTree = x.selector
231+
def cases(implicit ctx: Contexts.Context): List[CaseDef] = x.cases
223232
}
224233

225234
object MatchType extends MatchTypeExtractor {
@@ -237,7 +246,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
237246
}
238247

239248
def ByNameDeco(x: ByName): ByNameAPI = new ByNameAPI {
240-
249+
def result(implicit ctx: Contexts.Context): TypeTree = x.result
241250
}
242251

243252
object ByName extends ByNameExtractor {
@@ -255,7 +264,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
255264
}
256265

257266
def LambdaTypeTreeDeco(x: LambdaTypeTree): LambdaTypeTreeAPI = new LambdaTypeTreeAPI {
258-
267+
def tparams(implicit ctx: Contexts.Context): List[TypeDef] = x.tparams
268+
def body(implicit ctx: Contexts.Context): TypeOrBoundsTree = x.body
259269
}
260270

261271
object LambdaTypeTree extends LambdaTypeTreeExtractor {
@@ -273,7 +283,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
273283
}
274284

275285
def BindDeco(x: Bind): BindAPI = new BindAPI {
276-
286+
def name(implicit ctx: Contexts.Context): String = x.name.toString
287+
def body(implicit ctx: Contexts.Context): TypeOrBoundsTree = x.body
277288
}
278289

279290
object Bind extends BindExtractor {
@@ -291,7 +302,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
291302
}
292303

293304
def BlockDeco(x: Block): BlockAPI = new BlockAPI {
294-
305+
def aliases(implicit ctx: Contexts.Context): List[TypeDef] = x.stats.map { case alias: TypeDef => alias }
306+
def tpt(implicit ctx: Contexts.Context): TypeTree = x.expr
295307
}
296308

297309
object Block extends BlockExtractor {

0 commit comments

Comments
 (0)