Skip to content

Commit 056f4a4

Browse files
committed
Refactor styles
1 parent a82605f commit 056f4a4

File tree

4 files changed

+88
-100
lines changed

4 files changed

+88
-100
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@ object ConstantOps:
2121
case DoubleTag => s.DoubleConstant(const.doubleValue)
2222
case StringTag => s.StringConstant(const.stringValue)
2323
case NullTag => s.NullConstant()
24-
// ConstantType(_: Type, ClazzTag) should be converted as it's type
25-
// NoTag => it shouldn't happen
2624
case _ => throw new Error(s"Constant ${const} can't be converted to Semanticdb Constant.")
2725
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ExtractSemanticDB extends Phase:
5050

5151
/** Extractor of symbol occurrences from trees */
5252
class Extractor extends TreeTraverser:
53-
given builder: s.SemanticSymbolBuilder = s.SemanticSymbolBuilder()
53+
given s.SemanticSymbolBuilder = s.SemanticSymbolBuilder()
5454
val converter = s.TypeOps()
5555

5656
/** The bodies of synthetic locals */
@@ -328,7 +328,7 @@ class ExtractSemanticDB extends Phase:
328328
else
329329
val content = source.content()
330330
val (start, end) =
331-
if content.lift(span.end - 1).map(_ == '`').getOrElse(false) then
331+
if content.lift(span.end - 1).exists(_ == '`') then
332332
(span.start + 1, span.end - 1)
333333
else (span.start, span.end)
334334
val nameInSource = content.slice(start, end).mkString

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

Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -41,67 +41,82 @@ object Scala3:
4141
case class TypeParamRefSymbol(owner: Symbol, name: Name, tp: TypeBounds) extends FakeSymbol
4242
case class RefinementSymbol(owner: Symbol, name: Name, tp: Type) extends FakeSymbol
4343
type SemanticSymbol = Symbol | FakeSymbol
44-
extension (sym: SemanticSymbol)
45-
def name(using Context): Name = sym match
46-
case s: Symbol => s.name
47-
case s: WildcardTypeSymbol => nme.WILDCARD
48-
case s: TermParamRefSymbol => s.name
49-
case s: TypeParamRefSymbol => s.name
50-
case s: RefinementSymbol => s.name
51-
52-
def symbolName(using builder: SemanticSymbolBuilder)(using Context): String =
53-
sym match
54-
case s: Symbol => SymbolOps.symbolName(s)
55-
case s: FakeSymbol =>
56-
s.sname.getOrElse {
57-
val sname = builder.symbolName(s)
58-
s.sname = Some(sname)
59-
sname
60-
}
61-
62-
def symbolInfo(symkinds: Set[SymbolKind])(using LinkMode, TypeOps, SemanticSymbolBuilder, Context): SymbolInformation =
63-
sym match
64-
case s: Symbol => SymbolOps.symbolInfo(s)(symkinds)
65-
case s: WildcardTypeSymbol =>
66-
SymbolInformation(
67-
symbol = symbolName,
68-
language = Language.SCALA,
69-
kind = SymbolInformation.Kind.TYPE,
70-
displayName = nme.WILDCARD.show,
71-
signature = s.bounds.toSemanticSig(s.owner),
72-
)
73-
case s: TermParamRefSymbol =>
74-
SymbolInformation(
75-
symbol = symbolName,
76-
language = Language.SCALA,
77-
kind = SymbolInformation.Kind.PARAMETER,
78-
displayName = s.name.show.unescapeUnicode,
79-
signature = s.tp.toSemanticSig(s.owner),
80-
)
81-
case s: TypeParamRefSymbol =>
82-
SymbolInformation(
83-
symbol = symbolName,
84-
language = Language.SCALA,
85-
kind = SymbolInformation.Kind.TYPE_PARAMETER,
86-
displayName = s.name.show.unescapeUnicode,
87-
signature = s.tp.toSemanticSig(s.owner),
88-
)
89-
case s: RefinementSymbol =>
90-
val signature = s.tp.toSemanticSig(s.owner)
91-
val kind = signature match
92-
case _: TypeSignature => SymbolInformation.Kind.TYPE
93-
case _: MethodSignature => SymbolInformation.Kind.METHOD
94-
case _: ValueSignature => SymbolInformation.Kind.FIELD
95-
case _ => SymbolInformation.Kind.UNKNOWN_KIND
96-
SymbolInformation(
97-
symbol = symbolName,
98-
language = Language.SCALA,
99-
kind = kind,
100-
displayName = s.name.show.unescapeUnicode,
101-
properties =
102-
SymbolInformation.Property.ABSTRACT.value,
103-
signature = signature,
104-
)
44+
45+
given SemanticSymbolOps : AnyRef with
46+
extension (sym: SemanticSymbol)
47+
def name(using Context): Name = sym match
48+
case s: Symbol => s.name
49+
case s: WildcardTypeSymbol => nme.WILDCARD
50+
case s: TermParamRefSymbol => s.name
51+
case s: TypeParamRefSymbol => s.name
52+
case s: RefinementSymbol => s.name
53+
54+
def symbolName(using builder: SemanticSymbolBuilder)(using Context): String =
55+
sym match
56+
case s: Symbol => builder.symbolName(s)
57+
case s: FakeSymbol =>
58+
s.sname.getOrElse {
59+
val sname = builder.symbolName(s)
60+
s.sname = Some(sname)
61+
sname
62+
}
63+
64+
def symbolInfo(symkinds: Set[SymbolKind])(using LinkMode, TypeOps, SemanticSymbolBuilder, Context): SymbolInformation =
65+
sym match
66+
case s: Symbol =>
67+
val kind = s.symbolKind(symkinds)
68+
val sname = sym.symbolName
69+
val signature = s.info.toSemanticSig(s)
70+
SymbolInformation(
71+
symbol = sname,
72+
language = Language.SCALA,
73+
kind = kind,
74+
properties = s.symbolProps(symkinds),
75+
displayName = Symbols.displaySymbol(s),
76+
signature = signature,
77+
access = s.symbolAccess(kind),
78+
)
79+
case s: WildcardTypeSymbol =>
80+
SymbolInformation(
81+
symbol = symbolName,
82+
language = Language.SCALA,
83+
kind = SymbolInformation.Kind.TYPE,
84+
displayName = nme.WILDCARD.show,
85+
signature = s.bounds.toSemanticSig(s.owner),
86+
)
87+
case s: TermParamRefSymbol =>
88+
SymbolInformation(
89+
symbol = symbolName,
90+
language = Language.SCALA,
91+
kind = SymbolInformation.Kind.PARAMETER,
92+
displayName = s.name.show.unescapeUnicode,
93+
signature = s.tp.toSemanticSig(s.owner),
94+
)
95+
case s: TypeParamRefSymbol =>
96+
SymbolInformation(
97+
symbol = symbolName,
98+
language = Language.SCALA,
99+
kind = SymbolInformation.Kind.TYPE_PARAMETER,
100+
displayName = s.name.show.unescapeUnicode,
101+
signature = s.tp.toSemanticSig(s.owner),
102+
)
103+
case s: RefinementSymbol =>
104+
val signature = s.tp.toSemanticSig(s.owner)
105+
val kind = signature match
106+
case _: TypeSignature => SymbolInformation.Kind.TYPE
107+
case _: MethodSignature => SymbolInformation.Kind.METHOD
108+
case _: ValueSignature => SymbolInformation.Kind.FIELD
109+
case _ => SymbolInformation.Kind.UNKNOWN_KIND
110+
SymbolInformation(
111+
symbol = symbolName,
112+
language = Language.SCALA,
113+
kind = kind,
114+
displayName = s.name.show.unescapeUnicode,
115+
properties =
116+
SymbolInformation.Property.ABSTRACT.value,
117+
signature = signature,
118+
)
119+
end SemanticSymbolOps
105120

106121
enum SymbolKind derives CanEqual:
107122
kind =>
@@ -205,28 +220,14 @@ object Scala3:
205220
def isSyntheticWithIdent(using Context): Boolean =
206221
sym.is(Synthetic) && !sym.isAnonymous && !sym.name.isEmptyNumbered
207222

208-
def symbolInfo(symkinds: Set[SymbolKind])(using LinkMode, TypeOps, SemanticSymbolBuilder, Context): SymbolInformation =
209-
val sname = sym.symbolName
210-
val signature = sym.info.toSemanticSig(sym)
211-
val kind = symbolKind(symkinds)
212-
SymbolInformation(
213-
symbol = sname,
214-
language = Language.SCALA,
215-
kind = kind,
216-
properties = sym.symbolProps(symkinds),
217-
displayName = Symbols.displaySymbol(sym),
218-
signature = signature,
219-
access = symbolAccess(kind),
220-
)
221-
222223
/** The semanticdb name of the given symbol */
223224
def symbolName(using builder: SemanticSymbolBuilder)(using Context): String =
224225
builder.symbolName(sym)
225226

226227
def funParamSymbol(using builder: SemanticSymbolBuilder)(using Context): Name => String =
227228
builder.funParamSymbol(sym)
228229

229-
private def symbolKind(symkinds: Set[SymbolKind])(using Context): SymbolInformation.Kind =
230+
def symbolKind(symkinds: Set[SymbolKind])(using Context): SymbolInformation.Kind =
230231
if sym.isTypeParam then
231232
SymbolInformation.Kind.TYPE_PARAMETER
232233
else if sym.is(TermParam) then
@@ -260,7 +261,7 @@ object Scala3:
260261
else
261262
SymbolInformation.Kind.UNKNOWN_KIND
262263

263-
private def symbolProps(symkinds: Set[SymbolKind])(using Context): Int =
264+
def symbolProps(symkinds: Set[SymbolKind])(using Context): Int =
264265
if sym.is(ModuleClass) then
265266
return sym.sourceModule.symbolProps(symkinds)
266267
var props = 0
@@ -308,7 +309,7 @@ object Scala3:
308309
props |= SymbolInformation.Property.OPAQUE.value
309310
props
310311

311-
private def symbolAccess(kind: SymbolInformation.Kind)(using Context, SemanticSymbolBuilder): Access =
312+
def symbolAccess(kind: SymbolInformation.Kind)(using Context, SemanticSymbolBuilder): Access =
312313
kind match
313314
case k.LOCAL | k.PARAMETER | k.SELF_PARAMETER | k.TYPE_PARAMETER | k.PACKAGE | k.PACKAGE_OBJECT =>
314315
Access.Empty

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import core.Flags
1010
import core.Names.Name
1111
import core.StdNames.tpnme
1212
import ast.tpd._
13+
import scala.util.chaining.scalaUtilChainingOps
1314

1415
import collection.mutable
1516

@@ -153,18 +154,14 @@ class TypeOps:
153154
case mt: MethodType =>
154155
val syms: List[SemanticSymbol] = mt.paramNames.zip(mt.paramInfos).map { (name, info) =>
155156
paramRefSymtab.lookup(mt, name).getOrElse {
156-
val fakeSym = TermParamRefSymbol(sym, name, info)
157-
registerFakeSymbol(fakeSym)
158-
fakeSym
157+
TermParamRefSymbol(sym, name, info).tap(registerFakeSymbol)
159158
}
160159
}
161160
flatten(mt.resType, paramss :+ syms, tparams)
162161
case pt: PolyType =>
163162
val syms: List[SemanticSymbol] = pt.paramNames.zip(pt.paramInfos).map { (name, info) =>
164163
paramRefSymtab.lookup(pt, name).getOrElse {
165-
val fakeSym = TypeParamRefSymbol(sym, name, info)
166-
registerFakeSymbol(fakeSym)
167-
fakeSym
164+
TypeParamRefSymbol(sym, name, info).tap(registerFakeSymbol)
168165
}
169166
}
170167
flatten(pt.resType, paramss, tparams ++ syms)
@@ -195,14 +192,10 @@ class TypeOps:
195192
val paramSyms: List[SemanticSymbol] = lambda.paramNames.zip(lambda.paramInfos).map { (paramName, bounds) =>
196193
// def x[T[_]] = ???
197194
if paramName.isWildcard then
198-
val fakeSym = WildcardTypeSymbol(sym, bounds)
199-
registerFakeSymbol(fakeSym)
200-
fakeSym
195+
WildcardTypeSymbol(sym, bounds).tap(registerFakeSymbol)
201196
else
202197
paramRefSymtab.lookup(lambda, paramName).getOrElse {
203-
val fakeSym = TypeParamRefSymbol(sym, paramName, bounds)
204-
registerFakeSymbol(fakeSym)
205-
fakeSym
198+
TypeParamRefSymbol(sym, paramName, bounds).tap(registerFakeSymbol)
206199
}
207200
}
208201
(lambda.resType, paramSyms)
@@ -261,9 +254,7 @@ class TypeOps:
261254
tref.binder.typeParams.find(param => param.paramName == tref.paramName) match
262255
case Some(param) =>
263256
val info = param.paramInfo
264-
val fakeSym = TypeParamRefSymbol(sym, tref.paramName, info)
265-
registerFakeSymbol(fakeSym)
266-
Some(fakeSym)
257+
Some(TypeParamRefSymbol(sym, tref.paramName, info).tap(registerFakeSymbol))
267258
case None =>
268259
symbolNotFound(tref.binder, tref.paramName, sym)
269260
None
@@ -319,9 +310,7 @@ class TypeOps:
319310

320311
val decls: List[SemanticSymbol] = refinedInfos.map { (name, info) =>
321312
refinementSymtab.lookup(rt, name).getOrElse {
322-
val fakeSym = RefinementSymbol(sym, name, info)
323-
registerFakeSymbol(fakeSym)
324-
fakeSym
313+
RefinementSymbol(sym, name, info).tap(registerFakeSymbol)
325314
}
326315
}
327316
val sdecls = decls.sscopeOpt(using LinkMode.HardlinkChildren)

0 commit comments

Comments
 (0)