@@ -34,6 +34,7 @@ import util.{SourceFile, NoSource, Property, SourcePosition, SrcPos, EqHashMap}
34
34
import scala .collection .JavaConverters ._
35
35
import scala .annotation .internal .sharable
36
36
import config .Printers .typr
37
+ import annotation .targetName
37
38
38
39
object Symbols {
39
40
@@ -42,12 +43,120 @@ object Symbols {
42
43
/** Tree attachment containing the identifiers in a tree as a sorted array */
43
44
val Ids : Property .Key [Array [String ]] = new Property .Key
44
45
46
+ abstract class SymbolDecl extends Designator , ParamInfo , SrcPos , printing.Showable :
47
+ type ThisName <: Name
48
+
49
+ /** A unique id */
50
+ def id : Int
51
+
52
+ /** The coordinate of this symbol (either an index or a span) */
53
+ def coord : Coord
54
+
55
+ /** Set the coordinate of this symbol. This is only useful when the coordinate is
56
+ * not known at symbol creation. This is the case for root symbols unpickled from TASTY.
57
+ *
58
+ * @pre coord == NoCoord
59
+ */
60
+ private [core] def coord_= (c : Coord ): Unit
61
+
62
+ /** The tree defining the symbol at pickler time, EmptyTree if none was retained */
63
+ def defTree : Tree
64
+
65
+ /** Set defining tree if this symbol retains its definition tree */
66
+ def defTree_= (tree : Tree )(using Context ): Unit
67
+
68
+ /** Does this symbol retain its definition tree?
69
+ * A good policy for this needs to balance costs and benefits, where
70
+ * costs are mainly memoty leaks, in particular across runs.
71
+ */
72
+ def retainsDefTree (using Context ): Boolean
73
+
74
+ def denot (using Context ): SymDenotation
75
+ private [core] def denot_= (d : SymDenotation ): Unit
76
+ private [core] def invalidateDenotCache (): Unit
77
+
78
+ def originDenotation : SymDenotation
79
+ def lastKnownDenotation : SymDenotation
80
+ private [core] def defRunId : RunId
81
+ def isDefinedInCurrentRun (using Context ): Boolean
82
+ def isValidInCurrentRun (using Context ): Boolean
83
+
84
+ @ targetName(" invalidSymbol" )
85
+ def symbol (implicit ev : DontUseSymbolOnSymbol ): Nothing
86
+
87
+ def isTerm (using Context ): Boolean
88
+ def isType (using Context ): Boolean
89
+ def asTerm (using Context ): TermSymbol
90
+ def asType (using Context ): TypeSymbol
91
+ def isClass : Boolean
92
+ def asClass : ClassSymbol
93
+
94
+ def isPrivate (using Context ): Boolean
95
+ def isPatternBound (using Context ): Boolean
96
+ def isStatic (using Context ): Boolean
97
+
98
+ def name (using Context ): ThisName
99
+ def signature (using Context ): Signature
100
+
101
+ def span : Span
102
+ def sourcePos (using Context ): SourcePosition
103
+
104
+ def associatedFile (using Context ): AbstractFile
105
+ def binaryFile (using Context ): AbstractFile
106
+ def source (using Context ): SourceFile
107
+
108
+ def sourceSymbol (using Context ): Symbol
109
+
110
+ def entered (using Context ): this .type
111
+ def enteredAfter (phase : DenotTransformer )(using Context ): this .type
112
+
113
+ def drop ()(using Context ): Unit
114
+ def dropAfter (phase : DenotTransformer )(using Context ): Unit
115
+
116
+ inline def orElse (inline that : Symbol )(using Context ): Symbol
117
+ def filter (p : Symbol => Boolean ): Symbol
118
+
119
+ // ParamInfo types and methods
120
+ def isTypeParam (using Context ): Boolean
121
+ def paramName (using Context ): ThisName
122
+ def paramInfo (using Context ): Type
123
+ def paramInfoAsSeenFrom (pre : Type )(using Context ): Type
124
+ def paramInfoOrCompleter (using Context ): Type
125
+ def paramVariance (using Context ): Variance
126
+ def paramRef (using Context ): TypeRef
127
+
128
+ // Printing
129
+ def toText (printer : Printer ): Text
130
+ def showLocated (using Context ): String
131
+ def showExtendedLocation (using Context ): String
132
+ def showDcl (using Context ): String
133
+ def showKind (using Context ): String
134
+ def showName (using Context ): String
135
+ def showFullName (using Context ): String
136
+ end SymbolDecl
137
+
138
+ trait ClassSymbolDecl extends SymbolDecl :
139
+ type ThisName = TypeName
140
+ type TreeOrProvider = tpd.TreeProvider | tpd.Tree
141
+
142
+ def classDenot (using Context ): ClassDenotation
143
+
144
+ def assocFile : AbstractFile
145
+
146
+ def rootTree (using Context ): Tree
147
+ def rootTreeContaining (id : String )(using Context ): Tree
148
+ def rootTreeOrProvider : TreeOrProvider
149
+ private [dotc] def rootTreeOrProvider_= (t : TreeOrProvider )(using Context ): Unit
150
+
151
+ def sourceOfClass (using Context ): SourceFile
152
+ end ClassSymbolDecl
153
+
45
154
/** A Symbol represents a Scala definition/declaration or a package.
46
155
* @param coord The coordinates of the symbol (a position or an index)
47
156
* @param id A unique identifier of the symbol (unique per ContextBase)
48
157
*/
49
158
class Symbol private [Symbols ] (private var myCoord : Coord , val id : Int )
50
- extends Designator , ParamInfo , SrcPos , printing. Showable {
159
+ extends SymbolDecl {
51
160
52
161
type ThisName <: Name
53
162
@@ -275,8 +384,8 @@ object Symbols {
275
384
* the same as `x`.
276
385
* With the given setup, all such calls will give implicit-not found errors
277
386
*/
387
+ @ targetName(" invalidSymbol" )
278
388
final def symbol (implicit ev : DontUseSymbolOnSymbol ): Nothing = unsupported(" symbol" )
279
- type DontUseSymbolOnSymbol
280
389
281
390
final def source (using Context ): SourceFile = {
282
391
def valid (src : SourceFile ): SourceFile =
@@ -369,7 +478,7 @@ object Symbols {
369
478
type TypeSymbol = Symbol { type ThisName = TypeName }
370
479
371
480
class ClassSymbol private [Symbols ] (coord : Coord , val assocFile : AbstractFile , id : Int )
372
- extends Symbol (coord, id) {
481
+ extends Symbol (coord, id), ClassSymbolDecl {
373
482
374
483
type ThisName = TypeName
375
484
@@ -506,6 +615,8 @@ object Symbols {
506
615
def MutableSymbolMap [T ](): EqHashMap [Symbol , T ] = EqHashMap [Symbol , T ]()
507
616
def MutableSymbolMap [T ](initialCapacity : Int ): EqHashMap [Symbol , T ] = EqHashMap [Symbol , T ](initialCapacity)
508
617
618
+ type DontUseSymbolOnSymbol
619
+
509
620
// ---- Symbol creation methods ----------------------------------
510
621
511
622
/** Create a symbol from its fields (info may be lazy) */
0 commit comments