@@ -4,19 +4,12 @@ import org.jetbrains.dokka.links._
4
4
import org .jetbrains .dokka .model ._
5
5
import collection .JavaConverters ._
6
6
import dotty .dokka ._
7
- import dotty .dokka .model .api .Visibility
8
- import dotty .dokka .model .api .VisibilityScope
9
- import dotty .dokka .model .api .Modifier
10
7
import dotty .dokka .model .api .Annotation
11
8
12
-
13
- import scala .tasty .Reflection
14
-
15
9
trait BasicSupport :
16
10
self : TastyParser =>
17
- import reflect ._
18
-
19
- object SymOps extends SymOps [reflect.type ](reflect)
11
+ import qctx .reflect ._
12
+ object SymOps extends SymOps [qctx.reflect.type ](qctx.reflect)
20
13
export SymOps ._
21
14
22
15
def parseAnnotation (annotTerm : Term ): Annotation =
@@ -39,8 +32,8 @@ trait BasicSupport:
39
32
Annotation (dri, params)
40
33
41
34
42
- extension (sym : reflect. Symbol ):
43
- def documentation (using cxt : reflect. Context ) = sym.documentation match
35
+ extension (sym : Symbol ):
36
+ def documentation (using cxt : Context ) = sym.documentation match
44
37
case Some (comment) =>
45
38
Map (sourceSet.getSourceSet -> parseComment(comment, sym.tree))
46
39
case None =>
@@ -58,114 +51,5 @@ trait BasicSupport:
58
51
59
52
private val emptyDRI = DRI .Companion .getTopLevel
60
53
61
- class SymOps [R <: Reflection ](val r : R ):
62
- import r ._
63
-
64
- given R = r
65
-
66
- extension (sym : r.Symbol ):
67
- def packageName (using ctx : Context ): String =
68
- if (sym.isPackageDef) sym.fullName
69
- else sym.maybeOwner.packageName
70
-
71
- def topLevelEntryName (using ctx : Context ): Option [String ] = if (sym.isPackageDef) None else
72
- if (sym.owner.isPackageDef) Some (sym.name) else sym.owner.topLevelEntryName
73
-
74
- def getVisibility (): Visibility =
75
- import VisibilityScope ._
76
-
77
- def explicitScope (ownerType : TypeRepr ): VisibilityScope =
78
- val moduleSym = ownerType.typeSymbol.companionModule
79
- if moduleSym.isNoSymbol
80
- then ExplicitTypeScope (ownerType.typeSymbol.name)
81
- else ExplicitModuleScope (moduleSym.name)
82
-
83
- def implicitScope (ownerSym : Symbol ): VisibilityScope =
84
- val moduleSym = ownerSym.companionModule
85
- if moduleSym.isNoSymbol
86
- then ImplicitTypeScope
87
- else ImplicitModuleScope
88
-
89
- val visibilityFlags = (sym.flags.is(Flags .Private ), sym.flags.is(Flags .Protected ), sym.flags.is(Flags .Local ))
90
- (sym.privateWithin, sym.protectedWithin, visibilityFlags) match
91
- case (Some (owner), None , _) => Visibility .Private (explicitScope(owner))
92
- case (None , Some (owner), _) => Visibility .Protected (explicitScope(owner))
93
- case (None , None , (true , false , _)) => Visibility .Private (implicitScope(sym.owner))
94
- case (None , None , (false , true , true )) => Visibility .Protected (ThisScope )
95
- case (None , None , (false , true , false )) => Visibility .Protected (implicitScope(sym.owner))
96
- case (None , None , (false , false , false )) => Visibility .Unrestricted
97
- case _ => throw new Exception (s " Visibility for symbol $sym cannot be determined " )
98
-
99
- // TODO: #49 Remove it after TASTY-Reflect release with published flag Extension
100
- def hackIsOpen : Boolean = {
101
- import dotty .tools .dotc
102
- given dotc .core.Contexts .Context = r.rootContext.asInstanceOf
103
- val symbol = sym.asInstanceOf [dotc.core.Symbols .Symbol ]
104
- symbol.is(dotc.core.Flags .Open )
105
- }
106
-
107
- // Order here determines order in documenation
108
- def getExtraModifiers (): Seq [Modifier ] = Seq (
109
- Flags .Final -> Modifier .Final ,
110
- Flags .Sealed -> Modifier .Sealed ,
111
- Flags .Erased -> Modifier .Erased ,
112
- Flags .Abstract -> Modifier .Abstract ,
113
- Flags .Implicit -> Modifier .Implicit ,
114
- Flags .Inline -> Modifier .Inline ,
115
- Flags .Lazy -> Modifier .Lazy ,
116
- Flags .Override -> Modifier .Override ,
117
- Flags .Case -> Modifier .Case ,
118
- ).collect { case (flag, mod) if sym.flags.is(flag) => mod }
119
- ++ (if (sym.hackIsOpen) Seq (Modifier .Open ) else Nil )
120
-
121
- def isHiddenByVisibility : Boolean =
122
- import VisibilityScope ._
123
-
124
- getVisibility() match
125
- case Visibility .Private (_) => true
126
- case Visibility .Protected (ThisScope | ImplicitModuleScope | _ : ExplicitModuleScope ) => true
127
- case _ => false
128
-
129
- def shouldDocumentClasslike : Boolean = ! isHiddenByVisibility
130
- && ! sym.flags.is(Flags .Synthetic )
131
- && (! sym.flags.is(Flags .Case ) || ! sym.flags.is(Flags .Enum ))
132
- && ! (sym.companionModule.flags.is(Flags .Given ))
133
-
134
-
135
- def getCompanionSymbol : Option [Symbol ] = Some (sym.companionClass).filter(_.exists)
136
-
137
- def isCompanionObject : Boolean = sym.flags.is(Flags .Object ) && sym.companionClass.exists
138
-
139
- def isGiven : Boolean = sym.flags.is(Flags .Given )
140
-
141
- def isExtensionMethod : Boolean = sym.flags.is(Flags .ExtensionMethod )
142
-
143
- def isLeftAssoc (d : Symbol ): Boolean = ! d.name.endsWith(" :" )
144
-
145
- def extendedSymbol : Option [ValDef ] =
146
- Option .when(sym.isExtensionMethod)(
147
- if (isLeftAssoc(sym)) sym.tree.asInstanceOf [DefDef ].paramss(0 )(0 )
148
- else sym.tree.asInstanceOf [DefDef ].paramss(1 )(0 )
149
- )
150
-
151
- // TODO #22 make sure that DRIs are unique plus probably reuse semantic db code?
152
- def dri : DRI =
153
- if sym == Symbol .noSymbol then emptyDRI else if sym.isValDef && sym.moduleClass.exists then sym.moduleClass.dri else
154
- val pointsTo =
155
- if (! sym.isTypeDef) PointingToDeclaration .INSTANCE
156
- else PointingToGenericParameters (sym.owner.typeMembers.indexOf(sym))
157
-
158
- val method =
159
- if (sym.isDefDef) Some (sym)
160
- else if (sym.maybeOwner.isDefDef) Some (sym.owner)
161
- else None
162
54
163
- new DRI (
164
- sym.packageName,
165
- sym.topLevelEntryName.orNull, // TODO do we need any of this fields?
166
- method.map(s => new org.jetbrains.dokka.links.Callable (s.name, null , Nil .asJava)).orNull,
167
- pointsTo, // TODO different targets?
168
- s " ${sym.show}/ ${sym.signature.resultSig}/[ ${sym.signature.paramSigs.mkString(" /" )}] "
169
- )
170
55
171
- private val emptyDRI = DRI .Companion .getTopLevel
0 commit comments