Skip to content

Commit 9bcf227

Browse files
committed
adjust extension method syntax
1 parent fef188c commit 9bcf227

File tree

1 file changed

+57
-27
lines changed

1 file changed

+57
-27
lines changed

compiler/src/dotty/tools/dotc/semanticdb/Scala.scala

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.dotc.semanticdb
22

3-
import dotty.tools.dotc.core.Symbols.{ Symbol, defn }
3+
import dotty.tools.dotc.core.Symbols.{ Symbol , defn }
44
import dotty.tools.dotc.core.Contexts.Context
55
import dotty.tools.dotc.core.Names
66
import dotty.tools.dotc.core.Names.Name
@@ -14,6 +14,7 @@ import scala.annotation.internal.sharable
1414
import scala.annotation.switch
1515

1616
object Scala with
17+
import Symbols._
1718
import NameOps.given
1819

1920
@sharable private val unicodeEscape = raw"\$$u(\p{XDigit}{4})".r
@@ -30,15 +31,16 @@ object Scala with
3031
def isVar: Boolean = kind match
3132
case Var | Setter => true
3233
case _ => false
33-
3434
def isVal: Boolean = kind == Val
35-
3635
def isVarOrVal: Boolean = kind.isVar || kind.isVal
3736

37+
end SymbolKind
38+
3839
object SymbolKind with
3940
val ValSet = Set(Val)
4041
val VarSet = Set(Var)
4142
val emptySet = Set.empty[SymbolKind]
43+
end SymbolKind
4244

4345
object Symbols with
4446

@@ -62,9 +64,7 @@ object Scala with
6264
else
6365
symbol.name.show
6466

65-
given symbolOps: (symbol: String) with
66-
def unescapeUnicode =
67-
unicodeEscape.replaceAllIn(symbol, m => String.valueOf(Integer.parseInt(m.group(1), 16).toChar))
67+
end Symbols
6868

6969
given nameOps: (name: Name) with
7070

@@ -79,6 +79,7 @@ object Scala with
7979
case NameKinds.ModuleClassName(original) => original.isScala2PackageObjectName
8080
case _ => false
8181

82+
end nameOps
8283

8384
given symbolOps: (sym: Symbol) with
8485

@@ -100,33 +101,40 @@ object Scala with
100101

101102
sym.owner.info.decls.find(s => s.name == setterName && s.info.matchingType)
102103

104+
end symbolOps
105+
103106
object LocalSymbol with
104107
def unapply(symbolInfo: SymbolInformation): Option[Int] =
105-
symbolInfo.symbol match
106-
case locals(ints) =>
107-
val bi = BigInt(ints)
108-
if bi.isValidInt then Some(bi.toInt) else None
109-
case _ => None
110-
111-
given (symbol: String) with
112-
113-
def isNoSymbol: Boolean =
114-
symbol == Symbols.NoSymbol
115-
def isRootPackage: Boolean =
116-
symbol == Symbols.RootPackage
117-
def isEmptyPackage: Boolean =
118-
symbol == Symbols.EmptyPackage
108+
symbolInfo.symbol match
109+
110+
case locals(ints) =>
111+
val bi = BigInt(ints)
112+
if bi.isValidInt
113+
Some(bi.toInt)
114+
else
115+
None
116+
117+
case _ => None
118+
119+
end LocalSymbol
120+
121+
given stringOps: (symbol: String) with
122+
123+
def isNoSymbol: Boolean = NoSymbol == symbol
124+
def isRootPackage: Boolean = RootPackage == symbol
125+
def isEmptyPackage: Boolean = EmptyPackage == symbol
126+
119127
def isGlobal: Boolean =
120128
!symbol.isNoSymbol
121129
&& !symbol.isMulti
122130
&& { (symbol.last: @switch) match
123131
case '.' | '#' | '/' | ')' | ']' => true
124132
case _ => false
125133
}
126-
def isLocal: Boolean =
127-
locals matches symbol
128-
def isMulti: Boolean =
129-
symbol startsWith ";"
134+
135+
def isLocal: Boolean = !symbol.isGlobal
136+
def isMulti: Boolean = symbol startsWith ";"
137+
130138
def isConstructor: Boolean =
131139
ctor matches symbol
132140
def isTerm: Boolean =
@@ -140,33 +148,55 @@ object Scala with
140148
def isTypeParameter: Boolean =
141149
!symbol.isNoSymbol && !symbol.isMulti && symbol.last == ']'
142150

143-
given (info: SymbolInformation) with
151+
def unescapeUnicode =
152+
unicodeEscape.replaceAllIn(symbol, m => String.valueOf(Integer.parseInt(m.group(1), 16).toChar))
153+
154+
end stringOps
155+
156+
given infoOps: (info: SymbolInformation) with
144157

145-
def isPrimary: Boolean =
146-
(info.properties & SymbolInformation.Property.PRIMARY.value) != 0
147158
def isAbstract: Boolean =
148159
(info.properties & SymbolInformation.Property.ABSTRACT.value) != 0
160+
149161
def isFinal: Boolean =
150162
(info.properties & SymbolInformation.Property.FINAL.value) != 0
163+
151164
def isSealed: Boolean =
152165
(info.properties & SymbolInformation.Property.SEALED.value) != 0
166+
153167
def isImplicit: Boolean =
154168
(info.properties & SymbolInformation.Property.IMPLICIT.value) != 0
169+
155170
def isLazy: Boolean =
156171
(info.properties & SymbolInformation.Property.LAZY.value) != 0
172+
157173
def isCase: Boolean =
158174
(info.properties & SymbolInformation.Property.CASE.value) != 0
175+
159176
def isCovariant: Boolean =
160177
(info.properties & SymbolInformation.Property.COVARIANT.value) != 0
178+
161179
def isContravariant: Boolean =
162180
(info.properties & SymbolInformation.Property.CONTRAVARIANT.value) != 0
181+
182+
def isPrimary: Boolean =
183+
(info.properties & SymbolInformation.Property.PRIMARY.value) != 0
184+
163185
def isVal: Boolean =
164186
(info.properties & SymbolInformation.Property.VAL.value) != 0
187+
165188
def isVar: Boolean =
166189
(info.properties & SymbolInformation.Property.VAR.value) != 0
190+
167191
def isStatic: Boolean =
168192
(info.properties & SymbolInformation.Property.STATIC.value) != 0
193+
169194
def isEnum: Boolean =
170195
(info.properties & SymbolInformation.Property.ENUM.value) != 0
196+
171197
def isDefault: Boolean =
172198
(info.properties & SymbolInformation.Property.DEFAULT.value) != 0
199+
200+
end infoOps
201+
202+
end Scala

0 commit comments

Comments
 (0)