@@ -150,7 +150,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
150
150
}
151
151
152
152
val parents1 = parents.filter {
153
- case Apply (Select (New (tpt), _), _) => ! Types . JavaLangObject .unapply(tpt.tpe )
153
+ case Apply (Select (New (tpt), _), _) => tpt.tpe.typeSymbol != ctx.requiredClass( " java.lang.Object " )
154
154
case TypeSelect (Select (Ident (" _root_" ), " scala" ), " Product" ) => false
155
155
case TypeSelect (Select (Ident (" _root_" ), " scala" ), " Serializable" ) => false
156
156
case _ => true
@@ -356,7 +356,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
356
356
this += " throw "
357
357
printTree(expr)
358
358
359
- case Apply (fn, args) if fn.symbol.fullName == " scala.internal.Quoted$ .exprQuote" =>
359
+ case Apply (fn, args) if fn.symbol == ctx.requiredMethod( " scala.internal.Quoted.exprQuote" ) =>
360
360
args.head match {
361
361
case Block (stats, expr) =>
362
362
this += " '{"
@@ -371,12 +371,12 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
371
371
this += " }"
372
372
}
373
373
374
- case TypeApply (fn, args) if fn.symbol.fullName == " scala.internal.Quoted$ .typeQuote" =>
374
+ case TypeApply (fn, args) if fn.symbol == ctx.requiredMethod( " scala.internal.Quoted.typeQuote" ) =>
375
375
this += " '["
376
376
printTypeTree(args.head)
377
377
this += " ]"
378
378
379
- case Apply (fn, arg :: Nil ) if fn.symbol.fullName == " scala.internal.Quoted$ .exprSplice" =>
379
+ case Apply (fn, arg :: Nil ) if fn.symbol == ctx.requiredMethod( " scala.internal.Quoted.exprSplice" ) =>
380
380
this += " ${"
381
381
printTree(arg)
382
382
this += " }"
@@ -573,7 +573,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
573
573
def printFlatBlock (stats : List [Statement ], expr : Term )(given elideThis : Option [Symbol ]): Buffer = {
574
574
val (stats1, expr1) = flatBlock(stats, expr)
575
575
val stats2 = stats1.filter {
576
- case tree : TypeDef => ! tree.symbol.annots.exists(_.symbol.owner.fullName == " scala.internal.Quoted$ .quoteTypeTag" )
576
+ case tree : TypeDef => ! tree.symbol.annots.exists(_.symbol.owner == ctx.requiredClass( " scala.internal.Quoted.quoteTypeTag" ) )
577
577
case _ => true
578
578
}
579
579
if (stats2.isEmpty) {
@@ -971,7 +971,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
971
971
printTypeAndAnnots(tp)
972
972
this += " "
973
973
printAnnotation(annot)
974
- case tpe : TypeRef if tpe.typeSymbol.fullName == " scala.runtime.Null$" || tpe.typeSymbol.fullName == " scala.runtime.Nothing$" =>
974
+ case tpe : TypeRef if tpe.typeSymbol == ctx.requiredClass( " scala.runtime.Null$" ) || tpe.typeSymbol == ctx.requiredClass( " scala.runtime.Nothing$" ) =>
975
975
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
976
976
printType(tpe)
977
977
case tpe : TermRef if tpe.termSymbol.isClassDef && tpe.termSymbol.name.endsWith(" $" ) =>
@@ -1014,7 +1014,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1014
1014
case Annotated (tpt, annot) =>
1015
1015
val Annotation (ref, args) = annot
1016
1016
ref.tpe match {
1017
- case Types . RepeatedAnnotation ( ) =>
1017
+ case tpe : TypeRef if tpe.typeSymbol == ctx.requiredClass( " scala.annotation.internal.Repeated " ) =>
1018
1018
val Types .Sequence (tp) = tpt.tpe
1019
1019
printType(tp)
1020
1020
this += highlightTypeDef(" *" )
@@ -1115,7 +1115,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1115
1115
tp match {
1116
1116
case tp : TypeLambda =>
1117
1117
printType(tpe.dealias)
1118
- case TypeRef ( Types . ScalaPackage (), " <repeated>" ) =>
1118
+ case tp : TypeRef if tp.typeSymbol == ctx.requiredClass( " scala. <repeated>" ) =>
1119
1119
this += " _*"
1120
1120
case _ =>
1121
1121
printType(tp)
@@ -1228,7 +1228,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1228
1228
1229
1229
def printAnnotation (annot : Term )(given elideThis : Option [Symbol ]): Buffer = {
1230
1230
val Annotation (ref, args) = annot
1231
- if (annot.symbol.maybeOwner.fullName == " scala.internal.quoted.showName" ) this
1231
+ if (annot.symbol.maybeOwner == ctx.requiredClass( " scala.internal.quoted.showName" ) ) this
1232
1232
else {
1233
1233
this += " @"
1234
1234
printTypeTree(ref)
@@ -1242,12 +1242,9 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1242
1242
def printDefAnnotations (definition : Definition )(given elideThis : Option [Symbol ]): Buffer = {
1243
1243
val annots = definition.symbol.annots.filter {
1244
1244
case Annotation (annot, _) =>
1245
- annot.tpe match {
1246
- case TypeRef (prefix : TermRef , _) if prefix.termSymbol.fullName == " scala.annotation.internal" => false
1247
- case TypeRef (prefix : TypeRef , _) if prefix.typeSymbol.fullName == " scala.annotation.internal" => false
1248
- case TypeRef (Types .ScalaPackage (), " forceInline" ) => false
1249
- case _ => true
1250
- }
1245
+ val sym = annot.tpe.typeSymbol
1246
+ sym != ctx.requiredClass(" scala.forceInline" ) &&
1247
+ sym.maybeOwner != ctx.requiredPackage(" scala.annotation.internal" )
1251
1248
case x => throw new MatchError (x.showExtractors)
1252
1249
}
1253
1250
printAnnotations(annots)
@@ -1404,7 +1401,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1404
1401
}
1405
1402
1406
1403
private def splicedName (sym : Symbol )(given ctx : Context ): Option [String ] = {
1407
- sym.annots.find(_.symbol.owner.fullName == " scala.internal.quoted.showName" ).flatMap {
1404
+ sym.annots.find(_.symbol.owner == ctx.requiredClass( " scala.internal.quoted.showName" ) ).flatMap {
1408
1405
case Apply (_, Literal (Constant (c : String )) :: Nil ) => Some (c)
1409
1406
case Apply (_, Inlined (_, _, Literal (Constant (c : String ))) :: Nil ) => Some (c)
1410
1407
case annot => None
@@ -1435,43 +1432,20 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1435
1432
// TODO Provide some of these in scala.tasty.Reflection.scala and implement them using checks on symbols for performance
1436
1433
private object Types {
1437
1434
1438
- object JavaLangObject {
1439
- def unapply (tpe : Type )(given ctx : Context ): Boolean = tpe match {
1440
- case TypeRef (prefix : TermRef , " Object" ) => prefix.typeSymbol.fullName == " java.lang"
1441
- case _ => false
1442
- }
1443
- }
1444
-
1445
1435
object Sequence {
1446
1436
def unapply (tpe : Type )(given ctx : Context ): Option [Type ] = tpe match {
1447
- case AppliedType (TypeRef (prefix : TermRef , " Seq" ), (tp : Type ) :: Nil ) if prefix.termSymbol.fullName == " scala.collection" => Some (tp)
1448
- case AppliedType (TypeRef (prefix : TypeRef , " Seq" ), (tp : Type ) :: Nil ) if prefix.typeSymbol.fullName == " scala.collection" => Some (tp)
1437
+ case AppliedType (seq, (tp : Type ) :: Nil ) if seq.typeSymbol == ctx.requiredClass(" scala.collection.Seq" ) => Some (tp)
1449
1438
case _ => None
1450
1439
}
1451
1440
}
1452
1441
1453
- object RepeatedAnnotation {
1454
- def unapply (tpe : Type )(given ctx : Context ): Boolean = tpe match {
1455
- case TypeRef (prefix : TermRef , " Repeated" ) => prefix.termSymbol.fullName == " scala.annotation.internal"
1456
- case TypeRef (prefix : TypeRef , " Repeated" ) => prefix.typeSymbol.fullName == " scala.annotation.internal"
1457
- case _ => false
1458
- }
1459
- }
1460
-
1461
1442
object Repeated {
1462
1443
def unapply (tpe : Type )(given ctx : Context ): Option [Type ] = tpe match {
1463
- case AppliedType (TypeRef ( ScalaPackage (), " <repeated> " ), (tp : Type ) :: Nil ) => Some (tp)
1444
+ case AppliedType (rep, (tp : Type ) :: Nil ) if rep.typeSymbol == ctx.requiredClass( " scala.<repeated> " ) => Some (tp)
1464
1445
case _ => None
1465
1446
}
1466
1447
}
1467
1448
1468
- object ScalaPackage {
1469
- def unapply (tpe : TypeOrBounds )(given ctx : Context ): Boolean = tpe match {
1470
- case tpe : Type => tpe.termSymbol == defn.ScalaPackage
1471
- case _ => false
1472
- }
1473
- }
1474
-
1475
1449
}
1476
1450
1477
1451
object PackageObject {
0 commit comments