Skip to content

Commit 69fa64c

Browse files
committed
Add refelct shorthand for quotes.reflect
1 parent 4b734bf commit 69fa64c

13 files changed

+123
-115
lines changed

scaladoc/src/dotty/tools/scaladoc/tasty/BasicSupport.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ trait BasicSupport:
1515
export SymOpsWithLinkCache._
1616

1717

18-
def parseAnnotation(using Quotes)(annotTerm: quotes.reflect.Term): Annotation =
19-
import quotes.reflect._
18+
def parseAnnotation(using Quotes)(annotTerm: reflect.Term): Annotation =
19+
import reflect._
2020
import dotty.tools.dotc.ast.Trees.{SeqLiteral}
2121
val dri = annotTerm.tpe.typeSymbol.dri
2222
def inner(t: Term): List[Annotation.AnnotationParameter] = t match {
@@ -36,7 +36,7 @@ trait BasicSupport:
3636

3737
Annotation(dri, params)
3838

39-
extension (using Quotes)(sym: quotes.reflect.Symbol)
39+
extension (using Quotes)(sym: reflect.Symbol)
4040
def documentation = sym.docstring.map(parseComment(_, sym.tree))
4141

4242
def source =

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ trait ClassLikeSupport:
1616

1717
private given qctx.type = qctx
1818

19-
private def bareClasslikeKind(using Quotes)(symbol: quotes.reflect.Symbol): Kind =
20-
import quotes.reflect._
19+
private def bareClasslikeKind(using Quotes)(symbol: reflect.Symbol): Kind =
20+
import reflect._
2121
if symbol.flags.is(Flags.Module) then Kind.Object
2222
else if symbol.flags.is(Flags.Trait) then Kind.Trait(Nil, Nil)
2323
else if symbol.flags.is(Flags.Enum) then Kind.Enum(Nil, Nil)
@@ -217,7 +217,7 @@ trait ClassLikeSupport:
217217
}
218218
).map(_.copy(inheritedFrom = inheritance))
219219

220-
extension (using Quotes)(c: quotes.reflect.ClassDef)
220+
extension (using Quotes)(c: reflect.ClassDef)
221221

222222
def membersToDocument = c.body.filterNot(_.symbol.isHiddenByVisibility)
223223

scaladoc/src/dotty/tools/scaladoc/tasty/JavadocAnchorCreator.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import scala.util.matching.Regex
77

88
object JavadocAnchorCreator:
99

10-
private def javadocPrimitives(using Quotes)(sym: quotes.reflect.Symbol) =
11-
import quotes.reflect.*
10+
private def javadocPrimitives(using Quotes)(sym: reflect.Symbol) =
11+
import reflect.*
1212
if sym == defn.IntClass then Some("int")
1313
else if sym == defn.FloatClass then Some("float")
1414
else if sym == defn.DoubleClass then Some("double")
@@ -20,17 +20,17 @@ object JavadocAnchorCreator:
2020
else if sym == defn.ObjectClass then Some("java.lang.Object")
2121
else None
2222

23-
private def transformPrimitiveType(using Quotes)(tpe: quotes.reflect.TypeRepr): String = tpe.classSymbol
23+
private def transformPrimitiveType(using Quotes)(tpe: reflect.TypeRepr): String = tpe.classSymbol
2424
.flatMap(javadocPrimitives)
2525
.filter(_ => !tpe.typeSymbol.isTypeParam)
2626
.getOrElse(tpe.show)
2727

28-
private def transformType(using Quotes)(tpe: quotes.reflect.TypeRepr): String =
29-
import quotes.reflect.*
28+
private def transformType(using Quotes)(tpe: reflect.TypeRepr): String =
29+
import reflect.*
3030
tpe.simplified match
3131
case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.ArrayClass) => transformType(typeList.head) + ":A"
3232
case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.RepeatedParamClass) => transformType(typeList.head) + "..."
3333
case AppliedType(tpe, typeList) => transformPrimitiveType(tpe)
3434
case other => transformPrimitiveType(other)
3535

36-
def getJavadocType(using Quotes)(s: quotes.reflect.TypeRepr) = transformType(s)
36+
def getJavadocType(using Quotes)(s: reflect.TypeRepr) = transformType(s)

scaladoc/src/dotty/tools/scaladoc/tasty/NameNormalizer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import SymOps._
99

1010
object NameNormalizer {
1111

12-
extension (using Quotes)(s: quotes.reflect.Symbol) def normalizedName: String = {
13-
import quotes.reflect.*
12+
extension (using Quotes)(s: reflect.Symbol) def normalizedName: String = {
13+
import reflect.*
1414
val withoutGivenPrefix = if s.isGiven then s.name.stripPrefix("given_") else s.name
1515
val withoutObjectSuffix = if s.flags.is(Flags.Module) then withoutGivenPrefix.stripSuffix("$") else withoutGivenPrefix
1616
val constructorNormalizedName = if s.isClassConstructor then "this" else withoutObjectSuffix

scaladoc/src/dotty/tools/scaladoc/tasty/ScalaDocSupport.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import scala.quoted._
1010

1111
object ScaladocSupport:
1212

13-
def parseCommentString(using Quotes, DocContext)(comment: String, sym: quotes.reflect.Symbol, pos: Option[quotes.reflect.Position]): Comment =
14-
import quotes.reflect.report
13+
def parseCommentString(using Quotes, DocContext)(comment: String, sym: reflect.Symbol, pos: Option[reflect.Position]): Comment =
14+
import reflect.report
1515
val preparsed = comments.Preparser.preparse(comments.Cleaner.clean(comment))
1616

1717
val commentSyntax =
@@ -35,7 +35,7 @@ object ScaladocSupport:
3535
}
3636
parser.parse(preparsed)
3737

38-
def parseComment(using Quotes, DocContext)(docstring: String, tree: quotes.reflect.Tree): Comment =
38+
def parseComment(using Quotes, DocContext)(docstring: String, tree: reflect.Tree): Comment =
3939
val commentString: String =
4040
if tree.symbol.isClassDef || tree.symbol.owner.isClassDef then
4141
import dotty.tools.dotc

scaladoc/src/dotty/tools/scaladoc/tasty/Scaladoc2AnchorCreator.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import scala.util.matching.Regex
77

88
object Scaladoc2AnchorCreator:
99

10-
def getScaladoc2Type(using Quotes)(t: quotes.reflect.Tree) =
11-
import quotes.reflect.*
10+
def getScaladoc2Type(using Quotes)(t: reflect.Tree) =
11+
import reflect.*
1212
val regex = t match
1313
case d: DefDef => "def"
1414
case t: TypeDef => "type"

scaladoc/src/dotty/tools/scaladoc/tasty/SymOps.scala

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import JavadocAnchorCreator.getJavadocType
1010

1111
object SymOps:
1212

13-
extension (using Quotes)(sym: quotes.reflect.Symbol)
13+
extension (using Quotes)(sym: reflect.Symbol)
1414

1515
def packageName: String =
1616
if (sym.isPackageDef) sym.fullName
@@ -20,7 +20,7 @@ object SymOps:
2020
sym.packageName.split('.').toList
2121

2222
def className: Option[String] =
23-
import quotes.reflect._
23+
import reflect._
2424
if (sym.isClassDef && !sym.flags.is(Flags.Package)) Some(
2525
Some(sym.maybeOwner).filter(s => s.exists).flatMap(_.className).fold("")(cn => cn + "$") + sym.name
2626
).filterNot(_.contains("package$"))
@@ -42,7 +42,7 @@ object SymOps:
4242

4343

4444
def getVisibility(): Visibility =
45-
import quotes.reflect._
45+
import reflect._
4646
import VisibilityScope._
4747

4848
def explicitScope(ownerType: TypeRepr): VisibilityScope =
@@ -70,7 +70,7 @@ object SymOps:
7070

7171
// Order here determines order in documenation
7272
def getExtraModifiers(): Seq[Modifier] =
73-
import quotes.reflect._
73+
import reflect._
7474
Seq(
7575
Flags.Final -> Modifier.Final,
7676
Flags.Sealed -> Modifier.Sealed,
@@ -94,42 +94,42 @@ object SymOps:
9494
case _ => false
9595

9696
def shouldDocumentClasslike(using dctx: DocContext): Boolean =
97-
import quotes.reflect._
97+
import reflect._
9898
!sym.isHiddenByVisibility
9999
&& !sym.flags.is(Flags.Synthetic)
100100
&& (!sym.flags.is(Flags.Case) || !sym.flags.is(Flags.Enum))
101101
&& !(sym.companionModule.flags.is(Flags.Given))
102102

103-
def getCompanionSymbol: Option[quotes.reflect.Symbol] = Some(sym.companionClass).filter(_.exists)
103+
def getCompanionSymbol: Option[reflect.Symbol] = Some(sym.companionClass).filter(_.exists)
104104

105105
def isCompanionObject: Boolean =
106-
import quotes.reflect._
106+
import reflect._
107107
sym.flags.is(Flags.Module) && sym.companionClass.exists
108108

109109
def isGiven: Boolean =
110-
import quotes.reflect._
110+
import reflect._
111111
sym.flags.is(Flags.Given)
112112

113113
def isExported: Boolean =
114-
import quotes.reflect._
114+
import reflect._
115115
sym.flags.is(Flags.Exported)
116116

117117
def isOverridden: Boolean =
118-
import quotes.reflect._
118+
import reflect._
119119
sym.flags.is(Flags.Override)
120120

121121
def isExtensionMethod: Boolean =
122-
import quotes.reflect._
122+
import reflect._
123123
sym.flags.is(Flags.ExtensionMethod)
124124

125125
def isArtifact: Boolean =
126-
import quotes.reflect._
126+
import reflect._
127127
sym.flags.is(Flags.Artifact)
128128

129129
def isLeftAssoc: Boolean = !sym.name.endsWith(":")
130130

131-
def extendedSymbol: Option[quotes.reflect.ValDef] =
132-
import quotes.reflect.*
131+
def extendedSymbol: Option[reflect.ValDef] =
132+
import reflect.*
133133
Option.when(sym.isExtensionMethod){
134134
val termParamss = sym.tree.asInstanceOf[DefDef].termParamss
135135
if sym.isLeftAssoc || termParamss.size == 1 then termParamss(0).params(0)
@@ -146,10 +146,10 @@ class SymOpsWithLinkCache:
146146

147147
private val externalLinkCache: scala.collection.mutable.Map[AbstractFile, Option[ExternalDocLink]] = MMap()
148148

149-
extension (using Quotes)(sym: quotes.reflect.Symbol)
149+
extension (using Quotes)(sym: reflect.Symbol)
150150

151151
private def constructPath(location: Seq[String], anchor: Option[String], link: ExternalDocLink): String =
152-
import quotes.reflect.*
152+
import reflect.*
153153
val extension = ".html"
154154
val docURL = link.documentationUrl.toString
155155
def constructPathForJavadoc: String =
@@ -183,7 +183,7 @@ class SymOpsWithLinkCache:
183183

184184
// TODO #22 make sure that DRIs are unique plus probably reuse semantic db code?
185185
def dri(using dctx: DocContext): DRI =
186-
import quotes.reflect.*
186+
import reflect.*
187187
if sym == Symbol.noSymbol then topLevelDri
188188
else if sym.isValDef && sym.moduleClass.exists then sym.moduleClass.dri
189189
else
@@ -200,7 +200,7 @@ class SymOpsWithLinkCache:
200200
val location = sym.packageNameSplitted ++ className
201201

202202
val externalLink = {
203-
import quotes.reflect._
203+
import reflect._
204204
import dotty.tools.dotc
205205
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
206206
val csym = sym.asInstanceOf[dotc.core.Symbols.Symbol]
@@ -223,7 +223,7 @@ class SymOpsWithLinkCache:
223223
s"${sym.name}${sym.fullName}/${sym.signature.resultSig}/[${sym.signature.paramSigs.mkString("/")}]"
224224
)
225225

226-
def driInContextOfInheritingParent(par: quotes.reflect.Symbol)(using dctx: DocContext): DRI = sym.dri.copy(
226+
def driInContextOfInheritingParent(par: reflect.Symbol)(using dctx: DocContext): DRI = sym.dri.copy(
227227
location = par.dri.location,
228228
externalLink = None
229229
)

scaladoc/src/dotty/tools/scaladoc/tasty/SyntheticSupport.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,51 @@ import scala.quoted._
55

66
object SyntheticsSupport:
77

8-
extension (using Quotes)(t: quotes.reflect.TypeRepr)
8+
extension (using Quotes)(t: reflect.TypeRepr)
99
def isTupleType: Boolean = t.hackIsTupleType(t)
1010

1111
def isCompiletimeAppliedType: Boolean = t.hackIsCompiletimeAppliedType(t)
1212

13-
private def hackIsTupleType(rtpe: quotes.reflect.TypeRepr): Boolean =
13+
private def hackIsTupleType(rtpe: reflect.TypeRepr): Boolean =
1414
import dotty.tools.dotc
1515
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
1616
val tpe = rtpe.asInstanceOf[dotc.core.Types.Type]
1717
ctx.definitions.isTupleType(tpe)
1818

19-
private def hackIsCompiletimeAppliedType(rtpe: quotes.reflect.TypeRepr): Boolean =
19+
private def hackIsCompiletimeAppliedType(rtpe: reflect.TypeRepr): Boolean =
2020
import dotty.tools.dotc
2121
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
2222
val tpe = rtpe.asInstanceOf[dotc.core.Types.Type]
2323
ctx.definitions.isCompiletimeAppliedType(tpe.typeSymbol)
2424
end extension
2525

26-
extension (using Quotes)(s: quotes.reflect.Symbol)
26+
extension (using Quotes)(s: reflect.Symbol)
2727
def isSyntheticFunc: Boolean =
28-
import quotes.reflect._
28+
import reflect._
2929
s.flags.is(Flags.Synthetic) || s.flags.is(Flags.FieldAccessor) || s.isDefaultHelperMethod
3030

3131
def isSuperBridgeMethod: Boolean = s.name.contains("$super$")
3232

3333
def isDefaultHelperMethod: Boolean = ".*\\$default\\$\\d+$".r.matches(s.name)
3434

3535
def isOpaque: Boolean =
36-
import quotes.reflect._
36+
import reflect._
3737
s.flags.is(Flags.Opaque)
3838

3939
def isInfix: Boolean = hackIsInfix(s)
4040

41-
def getmembers: List[quotes.reflect.Symbol] = hackGetmembers(s)
41+
def getmembers: List[reflect.Symbol] = hackGetmembers(s)
4242

4343
end extension
4444

45-
def isValidPos(using Quotes)(pos: quotes.reflect.Position) =
45+
def isValidPos(using Quotes)(pos: reflect.Position) =
4646
if hackExists(pos) then pos.start != pos.end else false
4747

48-
def isSyntheticField(using Quotes)(c: quotes.reflect.Symbol) =
49-
import quotes.reflect._
48+
def isSyntheticField(using Quotes)(c: reflect.Symbol) =
49+
import reflect._
5050
c.flags.is(Flags.CaseAccessor) || (c.flags.is(Flags.Module) && !c.flags.is(Flags.Given))
5151

52-
def constructorWithoutParamLists(using Quotes)(c: quotes.reflect.ClassDef): Boolean =
52+
def constructorWithoutParamLists(using Quotes)(c: reflect.ClassDef): Boolean =
5353
!isValidPos(c.constructor.pos) || {
5454
val end = c.constructor.pos.end
5555
val typesEnd = c.constructor.leadingTypeParams.lastOption.fold(end - 1)(_.pos.end)
@@ -58,8 +58,8 @@ object SyntheticsSupport:
5858
}
5959

6060
// TODO: #49 Remove it after TASTY-Reflect release with published flag Extension
61-
private def hackIsInfix(using Quotes)(rsym: quotes.reflect.Symbol): Boolean = {
62-
import quotes.reflect._
61+
private def hackIsInfix(using Quotes)(rsym: reflect.Symbol): Boolean = {
62+
import reflect._
6363
import dotty.tools.dotc
6464
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
6565
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
@@ -69,8 +69,8 @@ object SyntheticsSupport:
6969
They are valdefs that describe case companion objects and cases from enum.
7070
TASTY crashed when calling _.tree on them.
7171
*/
72-
private def hackGetmembers(using Quotes)(rsym: quotes.reflect.Symbol): List[quotes.reflect.Symbol] = {
73-
import quotes.reflect._
72+
private def hackGetmembers(using Quotes)(rsym: reflect.Symbol): List[reflect.Symbol] = {
73+
import reflect._
7474
import dotty.tools.dotc
7575
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
7676
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
@@ -83,8 +83,8 @@ object SyntheticsSupport:
8383
}.toList
8484
}
8585

86-
private def hackGetSupertypes(using Quotes)(rdef: quotes.reflect.ClassDef) = {
87-
import quotes.reflect._
86+
private def hackGetSupertypes(using Quotes)(rdef: reflect.ClassDef) = {
87+
import reflect._
8888
import dotty.tools.dotc
8989
given dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
9090
val classdef = rdef.asInstanceOf[dotc.ast.tpd.TypeDef]
@@ -94,26 +94,26 @@ object SyntheticsSupport:
9494
baseTypes.asInstanceOf[List[(Symbol, TypeRepr)]]
9595
}
9696

97-
private def hackExists(using Quotes)(rpos: quotes.reflect.Position) = {
98-
import quotes.reflect._
97+
private def hackExists(using Quotes)(rpos: reflect.Position) = {
98+
import reflect._
9999
import dotty.tools.dotc
100100
import dotty.tools.dotc.util.Spans._
101101
given dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
102102
val pos = rpos.asInstanceOf[dotc.util.SourcePosition]
103103
pos.exists
104104
}
105105

106-
def getSupertypes(using Quotes)(c: quotes.reflect.ClassDef) = hackGetSupertypes(c).tail
106+
def getSupertypes(using Quotes)(c: reflect.ClassDef) = hackGetSupertypes(c).tail
107107

108-
def typeForClass(using Quotes)(c: quotes.reflect.ClassDef): quotes.reflect.TypeRepr =
109-
import quotes.reflect._
108+
def typeForClass(using Quotes)(c: reflect.ClassDef): reflect.TypeRepr =
109+
import reflect._
110110
import dotty.tools.dotc
111111
given dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
112112
val cSym = c.symbol.asInstanceOf[dotc.core.Symbols.Symbol]
113113
cSym.typeRef.appliedTo(cSym.typeParams.map(_.typeRef)).asInstanceOf[TypeRepr]
114114

115-
def memberInfo(using Quotes)(c: quotes.reflect.ClassDef, symbol: quotes.reflect.Symbol): quotes.reflect.TypeRepr =
116-
import quotes.reflect._
115+
def memberInfo(using Quotes)(c: reflect.ClassDef, symbol: reflect.Symbol): reflect.TypeRepr =
116+
import reflect._
117117
import dotty.tools.dotc
118118
given dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
119119
typeForClass(c).asInstanceOf[dotc.core.Types.Type]

0 commit comments

Comments
 (0)