1
1
package dotty .tools .dotc .semanticdb
2
2
3
- import dotty .tools .dotc .core .Symbols .{ Symbol , defn }
4
- import dotty .tools .dotc .core .Contexts .Context
5
- import dotty .tools .dotc .core .Names
6
- import dotty .tools .dotc .core .Names .Name
7
- import dotty .tools .dotc .core .Types .Type
8
- import dotty .tools .dotc .core .Flags ._
9
- import dotty .tools .dotc .core .NameKinds
10
- import dotty .tools .dotc .core .NameOps
11
- import dotty .tools .dotc .core .StdNames .nme
3
+ import dotty .tools .dotc .core
4
+ import core .Symbols .{ Symbol , defn }
5
+ import core .Contexts .Context
6
+ import core .Names
7
+ import core .Names .Name
8
+ import core .Types .Type
9
+ import core .Flags ._
10
+ import core .NameKinds
11
+ import core .StdNames .nme
12
+
13
+ import java .lang .Character .{isJavaIdentifierPart , isJavaIdentifierStart }
12
14
13
15
import scala .annotation .internal .sharable
14
16
import scala .annotation .switch
15
17
16
18
object Scala3 with
17
19
import Symbols ._
18
- import NameOps .given
20
+ import core . NameOps .given
19
21
20
22
@ sharable private val unicodeEscape = raw " \ $$ u(\p{XDigit}{4}) " .r
21
23
@ sharable private val locals = raw " local(\d+) " .r
@@ -44,7 +46,6 @@ object Scala3 with
44
46
45
47
object Symbols with
46
48
47
- val NoSymbol : String = " "
48
49
val RootPackage : String = " _root_/"
49
50
val EmptyPackage : String = " _empty_/"
50
51
val LocalPrefix : String = " local"
@@ -66,7 +67,7 @@ object Scala3 with
66
67
67
68
end Symbols
68
69
69
- given nameOps : (name : Name ) with
70
+ given NameOps : (name : Name ) with
70
71
71
72
def isWildcard = name match
72
73
case nme.WILDCARD | WILDCARDTypeName => true
@@ -79,9 +80,16 @@ object Scala3 with
79
80
case NameKinds .ModuleClassName (original) => original.isScala2PackageObjectName
80
81
case _ => false
81
82
82
- end nameOps
83
+ def isEmptyNumbered : Boolean =
84
+ ! name.is(NameKinds .WildcardParamName )
85
+ && { name match
86
+ case NameKinds .AnyNumberedName (nme.EMPTY , _) => true
87
+ case _ => false
88
+ }
83
89
84
- given symbolOps : (sym : Symbol ) with
90
+ end NameOps
91
+
92
+ given SymbolOps : (sym : Symbol ) with
85
93
86
94
def isScala2PackageObject (given Context ): Boolean =
87
95
sym.name.isScala2PackageObjectName && sym.owner.is(Package ) && sym.is(Module )
@@ -101,54 +109,64 @@ object Scala3 with
101
109
102
110
sym.owner.info.decls.find(s => s.name == setterName && s.info.matchingType)
103
111
112
+ /** Is symbol global? Non-global symbols get localN names */
113
+ def isGlobal (given Context ): Boolean =
114
+ sym.is(Package )
115
+ || ! sym.isSelfSym && (sym.is(Param ) || sym.owner.isClass) && sym.owner.isGlobal
116
+
117
+ def isLocalWithinSameName (given Context ): Boolean =
118
+ sym.exists && ! sym.isGlobal && sym.name == sym.owner.name
104
119
120
+ /** Synthetic symbols that are not anonymous or numbered empty ident */
105
121
def isSyntheticWithIdent (given Context ): Boolean =
106
- sym.is(Synthetic ) && ! sym.isAnonymous
122
+ sym.is(Synthetic ) && ! sym.isAnonymous && ! sym.name.isEmptyNumbered
107
123
108
- end symbolOps
124
+ end SymbolOps
109
125
110
126
object LocalSymbol with
111
- def unapply (symbolInfo : SymbolInformation ): Option [Int ] =
112
- symbolInfo.symbol match
113
127
114
- case locals(ints) =>
115
- val bi = BigInt (ints)
116
- if bi.isValidInt
117
- Some (bi.toInt)
118
- else
119
- None
128
+ def unapply (symbolInfo : SymbolInformation ): Option [Int ] = symbolInfo.symbol match
129
+ case locals(ints) =>
130
+ val bi = BigInt (ints)
131
+ if bi.isValidInt
132
+ Some (bi.toInt)
133
+ else
134
+ None
120
135
121
- case _ => None
136
+ case _ => None
122
137
123
138
end LocalSymbol
124
139
125
140
private inline def (char : Char ) `is/.#])` = (char : @ switch) match
126
141
case '/' | '.' | '#' | ']' | ')' => true
127
142
case _ => false
128
143
129
- given stringOps : (symbol : String ) with
144
+ given StringOps : (symbol : String ) with
130
145
131
- def isNoSymbol : Boolean = NoSymbol == symbol
146
+ def isSymbol : Boolean = ! symbol.isEmpty
132
147
def isRootPackage : Boolean = RootPackage == symbol
133
148
def isEmptyPackage : Boolean = EmptyPackage == symbol
134
149
135
- def isGlobal : Boolean = ! symbol.isNoSymbol && ! symbol.isMulti && symbol.last.`is/.#])`
136
- def isLocal : Boolean = ! symbol.isNoSymbol && ! symbol.isMulti && ! symbol.last.`is/.#])`
150
+ def isGlobal : Boolean = ! symbol.isEmpty && ! symbol.isMulti && symbol.last.`is/.#])`
151
+ def isLocal : Boolean = ! symbol.isEmpty && ! symbol.isMulti && ! symbol.last.`is/.#])`
137
152
def isMulti : Boolean = symbol startsWith " ;"
138
153
139
154
def isConstructor : Boolean = ctor matches symbol
140
- def isPackage : Boolean = ! symbol.isNoSymbol && ! symbol.isMulti && symbol.last == '/'
141
- def isTerm : Boolean = ! symbol.isNoSymbol && ! symbol.isMulti && symbol.last == '.'
142
- def isType : Boolean = ! symbol.isNoSymbol && ! symbol.isMulti && symbol.last == '#'
143
- def isTypeParameter : Boolean = ! symbol.isNoSymbol && ! symbol.isMulti && symbol.last == ']'
144
- def isParameter : Boolean = ! symbol.isNoSymbol && ! symbol.isMulti && symbol.last == ')'
155
+ def isPackage : Boolean = ! symbol.isEmpty && ! symbol.isMulti && symbol.last == '/'
156
+ def isTerm : Boolean = ! symbol.isEmpty && ! symbol.isMulti && symbol.last == '.'
157
+ def isType : Boolean = ! symbol.isEmpty && ! symbol.isMulti && symbol.last == '#'
158
+ def isTypeParameter : Boolean = ! symbol.isEmpty && ! symbol.isMulti && symbol.last == ']'
159
+ def isParameter : Boolean = ! symbol.isEmpty && ! symbol.isMulti && symbol.last == ')'
145
160
146
161
def unescapeUnicode =
147
162
unicodeEscape.replaceAllIn(symbol, m => String .valueOf(Integer .parseInt(m.group(1 ), 16 ).toChar))
148
163
149
- end stringOps
164
+ def isJavaIdent =
165
+ isJavaIdentifierStart(symbol.head) && symbol.tail.forall(isJavaIdentifierPart)
166
+
167
+ end StringOps
150
168
151
- given infoOps : (info : SymbolInformation ) with
169
+ given InfoOps : (info : SymbolInformation ) with
152
170
153
171
def isAbstract : Boolean = (info.properties & SymbolInformation .Property .ABSTRACT .value) != 0
154
172
def isFinal : Boolean = (info.properties & SymbolInformation .Property .FINAL .value) != 0
@@ -182,6 +200,6 @@ object Scala3 with
182
200
def isTrait : Boolean = info.kind.isTrait
183
201
def isInterface : Boolean = info.kind.isInterface
184
202
185
- end infoOps
203
+ end InfoOps
186
204
187
205
end Scala3
0 commit comments