@@ -8,23 +8,19 @@ import dotty.tools.io.AbstractFile
8
8
import Scaladoc2AnchorCreator .getScaladoc2Type
9
9
import JavadocAnchorCreator .getJavadocType
10
10
11
- class SymOps [Q <: Quotes ](val q : Q ):
12
- import q .reflect ._
11
+ object SymOps :
13
12
14
- given q . type = q
13
+ extension ( using Quotes )( sym : quotes.reflect. Symbol )
15
14
16
- private val externalLinkCache : scala.collection.mutable.Map [AbstractFile , Option [ExternalDocLink ]] = MMap ()
17
-
18
- extension (sym : Symbol )
19
- def packageName : String = (
15
+ def packageName : String =
20
16
if (sym.isPackageDef) sym.fullName
21
17
else sym.maybeOwner.packageName
22
- )
23
18
24
19
def packageNameSplitted : Seq [String ] =
25
20
sym.packageName.split('.' ).toList
26
21
27
22
def className : Option [String ] =
23
+ import quotes .reflect ._
28
24
if (sym.isClassDef && ! sym.flags.is(Flags .Package )) Some (
29
25
Some (sym.maybeOwner).filter(s => s.exists).flatMap(_.className).fold(" " )(cn => cn + " $" ) + sym.name
30
26
).filterNot(_.contains(" package$" ))
@@ -44,7 +40,9 @@ class SymOps[Q <: Quotes](val q: Q):
44
40
else None
45
41
// TODO: Retrieve string that will match scaladoc anchors
46
42
43
+
47
44
def getVisibility (): Visibility =
45
+ import quotes .reflect ._
48
46
import VisibilityScope ._
49
47
50
48
def explicitScope (ownerType : TypeRepr ): VisibilityScope =
@@ -71,7 +69,9 @@ class SymOps[Q <: Quotes](val q: Q):
71
69
72
70
73
71
// Order here determines order in documenation
74
- def getExtraModifiers (): Seq [Modifier ] = Seq (
72
+ def getExtraModifiers (): Seq [Modifier ] =
73
+ import quotes .reflect ._
74
+ Seq (
75
75
Flags .Final -> Modifier .Final ,
76
76
Flags .Sealed -> Modifier .Sealed ,
77
77
Flags .Erased -> Modifier .Erased ,
@@ -83,54 +83,81 @@ class SymOps[Q <: Quotes](val q: Q):
83
83
Flags .Open -> Modifier .Open ,
84
84
Flags .Override -> Modifier .Override ,
85
85
Flags .Case -> Modifier .Case ,
86
- ).collect { case (flag, mod) if sym.flags.is(flag) => mod }
86
+ ).collect { case (flag, mod) if sym.flags.is(flag) => mod }
87
87
88
88
def isHiddenByVisibility (using dctx : DocContext ): Boolean =
89
89
import VisibilityScope ._
90
90
91
- ! summon[DocContext ].args.includePrivateAPI && getVisibility().match
91
+ ! summon[DocContext ].args.includePrivateAPI && sym. getVisibility().match
92
92
case Visibility .Private (_) => true
93
93
case Visibility .Protected (ThisScope | ImplicitModuleScope | _ : ExplicitModuleScope ) => true
94
94
case _ => false
95
95
96
- def shouldDocumentClasslike (using dctx : DocContext ): Boolean = ! isHiddenByVisibility
97
- && ! sym.flags.is(Flags .Synthetic )
98
- && (! sym.flags.is(Flags .Case ) || ! sym.flags.is(Flags .Enum ))
99
- && ! (sym.companionModule.flags.is(Flags .Given ))
100
-
96
+ def shouldDocumentClasslike (using dctx : DocContext ): Boolean =
97
+ import quotes .reflect ._
98
+ ! sym.isHiddenByVisibility
99
+ && ! sym.flags.is(Flags .Synthetic )
100
+ && (! sym.flags.is(Flags .Case ) || ! sym.flags.is(Flags .Enum ))
101
+ && ! (sym.companionModule.flags.is(Flags .Given ))
101
102
102
- def getCompanionSymbol : Option [Symbol ] = Some (sym.companionClass).filter(_.exists)
103
+ def getCompanionSymbol : Option [quotes.reflect. Symbol ] = Some (sym.companionClass).filter(_.exists)
103
104
104
- def isCompanionObject : Boolean = sym.flags.is(Flags .Module ) && sym.companionClass.exists
105
+ def isCompanionObject : Boolean =
106
+ import quotes .reflect ._
107
+ sym.flags.is(Flags .Module ) && sym.companionClass.exists
105
108
106
- def isGiven : Boolean = sym.flags.is(Flags .Given )
109
+ def isGiven : Boolean =
110
+ import quotes .reflect ._
111
+ sym.flags.is(Flags .Given )
107
112
108
- def isExported : Boolean = sym.flags.is(Flags .Exported )
113
+ def isExported : Boolean =
114
+ import quotes .reflect ._
115
+ sym.flags.is(Flags .Exported )
109
116
110
- def isOverridden : Boolean = sym.flags.is(Flags .Override )
117
+ def isOverridden : Boolean =
118
+ import quotes .reflect ._
119
+ sym.flags.is(Flags .Override )
111
120
112
- def isExtensionMethod : Boolean = sym.flags.is(Flags .ExtensionMethod )
121
+ def isExtensionMethod : Boolean =
122
+ import quotes .reflect ._
123
+ sym.flags.is(Flags .ExtensionMethod )
113
124
114
- def isArtifact : Boolean = sym.flags.is(Flags .Artifact )
125
+ def isArtifact : Boolean =
126
+ import quotes .reflect ._
127
+ sym.flags.is(Flags .Artifact )
115
128
116
- def isLeftAssoc ( d : Symbol ) : Boolean = ! d .name.endsWith(" :" )
129
+ def isLeftAssoc : Boolean = ! sym .name.endsWith(" :" )
117
130
118
- def extendedSymbol : Option [ValDef ] =
131
+ def extendedSymbol : Option [quotes.reflect.ValDef ] =
132
+ import quotes .reflect .*
119
133
Option .when(sym.isExtensionMethod){
120
134
val termParamss = sym.tree.asInstanceOf [DefDef ].termParamss
121
- if isLeftAssoc( sym) || termParamss.size == 1 then termParamss(0 ).params(0 )
135
+ if sym.isLeftAssoc || termParamss.size == 1 then termParamss(0 ).params(0 )
122
136
else termParamss(1 ).params(0 )
123
137
}
124
138
139
+ end extension
140
+
141
+ end SymOps
142
+
143
+ // TODO find a better way to handle this cache and move the methods to SymOps
144
+ class SymOpsWithLinkCache :
145
+ import SymOps .*
146
+
147
+ private val externalLinkCache : scala.collection.mutable.Map [AbstractFile , Option [ExternalDocLink ]] = MMap ()
148
+
149
+ extension (using Quotes )(sym : quotes.reflect.Symbol )
150
+
125
151
private def constructPath (location : Seq [String ], anchor : Option [String ], link : ExternalDocLink ): String =
152
+ import quotes .reflect .*
126
153
val extension = " .html"
127
154
val docURL = link.documentationUrl.toString
128
155
def constructPathForJavadoc : String =
129
156
val l = " \\ $+" .r.replaceAllIn(location.mkString(" /" ), _ => " ." )
130
157
val javadocAnchor = if anchor.isDefined then {
131
158
val paramSigs = sym.paramSymss.flatten.map(_.tree).collect {
132
159
case v : ValDef => v.tpt.tpe
133
- }.map(getJavadocType( using q) )
160
+ }.map(getJavadocType)
134
161
" #" + sym.name + paramSigs.mkString(" -" ," -" ," -" )
135
162
} else " "
136
163
docURL + l + extension + javadocAnchor
@@ -156,6 +183,7 @@ class SymOps[Q <: Quotes](val q: Q):
156
183
157
184
// TODO #22 make sure that DRIs are unique plus probably reuse semantic db code?
158
185
def dri (using dctx : DocContext ): DRI =
186
+ import quotes .reflect .*
159
187
if sym == Symbol .noSymbol then topLevelDri
160
188
else if sym.isValDef && sym.moduleClass.exists then sym.moduleClass.dri
161
189
else
@@ -172,9 +200,9 @@ class SymOps[Q <: Quotes](val q: Q):
172
200
val location = sym.packageNameSplitted ++ className
173
201
174
202
val externalLink = {
175
- import q .reflect ._
203
+ import quotes .reflect ._
176
204
import dotty .tools .dotc
177
- given ctx : dotc.core.Contexts .Context = q .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
205
+ given ctx : dotc.core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
178
206
val csym = sym.asInstanceOf [dotc.core.Symbols .Symbol ]
179
207
val extLink = if externalLinkCache.contains(csym.associatedFile) then externalLinkCache(csym.associatedFile)
180
208
else {
@@ -183,7 +211,7 @@ class SymOps[Q <: Quotes](val q: Q):
183
211
externalLinkCache += (csym.associatedFile -> calculatedLink)
184
212
calculatedLink
185
213
}
186
- extLink.map(link => constructPath(location, anchor, link))
214
+ extLink.map(link => sym. constructPath(location, anchor, link))
187
215
}
188
216
189
217
DRI (
@@ -195,7 +223,7 @@ class SymOps[Q <: Quotes](val q: Q):
195
223
s " ${sym.name}${sym.fullName}/ ${sym.signature.resultSig}/[ ${sym.signature.paramSigs.mkString(" /" )}] "
196
224
)
197
225
198
- def driInContextOfInheritingParent (par : Symbol )(using dctx : DocContext ): DRI = sym.dri.copy(
226
+ def driInContextOfInheritingParent (par : quotes.reflect. Symbol )(using dctx : DocContext ): DRI = sym.dri.copy(
199
227
location = par.dri.location,
200
228
externalLink = None
201
229
)
0 commit comments