@@ -6,14 +6,14 @@ import scala.annotation.switch
6
6
/** Printer for fully elaborated representation of the source code */
7
7
object SourceCode {
8
8
9
- def showTree (using Quotes )(tree : quotes.reflect.Tree )(syntaxHighlight : SyntaxHighlight ): String =
10
- new SourceCodePrinter [quotes.type ](syntaxHighlight).printTree(tree).result()
9
+ def showTree (using Quotes )(tree : quotes.reflect.Tree )(syntaxHighlight : SyntaxHighlight , fullNames : Boolean ): String =
10
+ new SourceCodePrinter [quotes.type ](syntaxHighlight, fullNames ).printTree(tree).result()
11
11
12
- def showType (using Quotes )(tpe : quotes.reflect.TypeRepr )(syntaxHighlight : SyntaxHighlight ): String =
13
- new SourceCodePrinter [quotes.type ](syntaxHighlight).printType(tpe)(using None ).result()
12
+ def showType (using Quotes )(tpe : quotes.reflect.TypeRepr )(syntaxHighlight : SyntaxHighlight , fullNames : Boolean ): String =
13
+ new SourceCodePrinter [quotes.type ](syntaxHighlight, fullNames ).printType(tpe)(using None ).result()
14
14
15
- def showConstant (using Quotes )(const : quotes.reflect.Constant )(syntaxHighlight : SyntaxHighlight ): String =
16
- new SourceCodePrinter [quotes.type ](syntaxHighlight).printConstant(const).result()
15
+ def showConstant (using Quotes )(const : quotes.reflect.Constant )(syntaxHighlight : SyntaxHighlight , fullNames : Boolean ): String =
16
+ new SourceCodePrinter [quotes.type ](syntaxHighlight, fullNames ).printConstant(const).result()
17
17
18
18
def showSymbol (using Quotes )(symbol : quotes.reflect.Symbol )(syntaxHighlight : SyntaxHighlight ): String =
19
19
symbol.fullName
@@ -58,7 +58,7 @@ object SourceCode {
58
58
flagList.result().mkString(" /*" , " " , " */" )
59
59
}
60
60
61
- private class SourceCodePrinter [Q <: Quotes & Singleton ](syntaxHighlight : SyntaxHighlight )(using val quotes : Q ) {
61
+ private class SourceCodePrinter [Q <: Quotes & Singleton ](syntaxHighlight : SyntaxHighlight , fullNames : Boolean )(using val quotes : Q ) {
62
62
import syntaxHighlight ._
63
63
import quotes .reflect ._
64
64
@@ -1073,41 +1073,45 @@ object SourceCode {
1073
1073
1074
1074
case tpe : TypeRef =>
1075
1075
val sym = tpe.typeSymbol
1076
- tpe.qualifier match {
1077
- case ThisType (tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
1078
- case NoPrefix () =>
1079
- if (sym.owner.flags.is(Flags .Package )) {
1080
- // TODO should these be in the prefix? These are at least `scala`, `java` and `scala.collection`.
1081
- val packagePath = sym.owner.fullName.stripPrefix(" <root>" ).stripPrefix(" <empty>" ).stripPrefix(" ." )
1082
- if (packagePath != " " )
1083
- this += packagePath += " ."
1084
- }
1085
- case prefix : TermRef if prefix.termSymbol.isClassDef =>
1086
- printType(prefix)
1087
- this += " #"
1088
- case prefix : TypeRef if prefix.typeSymbol.isClassDef =>
1089
- printType(prefix)
1090
- this += " #"
1091
- case ThisType (TermRef (cdef, _)) if elideThis.nonEmpty && cdef == elideThis.get =>
1092
- case ThisType (TypeRef (cdef, _)) if elideThis.nonEmpty && cdef == elideThis.get =>
1093
- case prefix : TypeRepr =>
1094
- printType(prefix)
1095
- this += " ."
1096
- }
1076
+ if fullNames then
1077
+ tpe.qualifier match {
1078
+ case ThisType (tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
1079
+ case NoPrefix () =>
1080
+ if (sym.owner.flags.is(Flags .Package )) {
1081
+ // TODO should these be in the prefix? These are at least `scala`, `java` and `scala.collection`.
1082
+ val packagePath = sym.owner.fullName.stripPrefix(" <root>" ).stripPrefix(" <empty>" ).stripPrefix(" ." )
1083
+ if (packagePath != " " )
1084
+ this += packagePath += " ."
1085
+ }
1086
+ case prefix : TermRef if prefix.termSymbol.isClassDef =>
1087
+ printType(prefix)
1088
+ this += " #"
1089
+ case prefix : TypeRef if prefix.typeSymbol.isClassDef =>
1090
+ printType(prefix)
1091
+ this += " #"
1092
+ case ThisType (TermRef (cdef, _)) if elideThis.nonEmpty && cdef == elideThis.get =>
1093
+ case ThisType (TypeRef (cdef, _)) if elideThis.nonEmpty && cdef == elideThis.get =>
1094
+ case prefix : TypeRepr =>
1095
+ printType(prefix)
1096
+ this += " ."
1097
+ }
1097
1098
this += highlightTypeDef(sym.name.stripSuffix(" $" ))
1098
1099
1099
1100
case TermRef (prefix, name) =>
1100
- prefix match {
1101
- case NoPrefix () =>
1102
- this += highlightTypeDef(name)
1103
- case ThisType (tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
1104
- this += highlightTypeDef(name)
1105
- case _ =>
1106
- printType(prefix)
1107
- if (name != " package" )
1108
- this += " ." += highlightTypeDef(name)
1109
- this
1110
- }
1101
+ if fullNames then
1102
+ prefix match {
1103
+ case NoPrefix () =>
1104
+ this += highlightTypeDef(name)
1105
+ case ThisType (tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
1106
+ this += highlightTypeDef(name)
1107
+ case _ =>
1108
+ printType(prefix)
1109
+ if (name != " package" )
1110
+ this += " ." += highlightTypeDef(name)
1111
+ this
1112
+ }
1113
+ else
1114
+ this += highlightTypeDef(name)
1111
1115
1112
1116
case tpe @ Refinement (_, _, _) =>
1113
1117
printRefinement(tpe)
@@ -1157,12 +1161,14 @@ object SourceCode {
1157
1161
printFullClassName(tp)
1158
1162
this += highlightTypeDef(" .this" )
1159
1163
case TypeRef (prefix, name) if name.endsWith(" $" ) =>
1160
- prefix match {
1161
- case NoPrefix () =>
1162
- case ThisType (tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
1163
- case _ =>
1164
- printType(prefix)
1165
- this += " ."
1164
+ if (fullNames){
1165
+ prefix match {
1166
+ case NoPrefix () =>
1167
+ case ThisType (tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
1168
+ case _ =>
1169
+ printType(prefix)
1170
+ this += " ."
1171
+ }
1166
1172
}
1167
1173
this += highlightTypeDef(name.stripSuffix(" $" ))
1168
1174
case _ =>
@@ -1378,7 +1384,7 @@ object SourceCode {
1378
1384
1379
1385
private def printFullClassName (tp : TypeRepr ): Unit = {
1380
1386
def printClassPrefix (prefix : TypeRepr ): Unit = prefix match {
1381
- case TypeRef (prefix2, name) =>
1387
+ case TypeRef (prefix2, name) if fullNames =>
1382
1388
printClassPrefix(prefix2)
1383
1389
this += name += " ."
1384
1390
case _ =>
0 commit comments