@@ -119,6 +119,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
119
119
}
120
120
121
121
implicit class SymbolExtender (symbol : Symbol ) {
122
+ def exists = ! (symbol.name == " <none>" || symbol == NoSymbol )
122
123
/* Return true if symbol represents the definition of a var setter, false otherwise.
123
124
We return true if the extract of source code corresponding to the position of the symbol is the same as the symbol name.
124
125
Ex:
@@ -192,15 +193,15 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
192
193
193
194
def isValueParameter : Boolean = symbol.isParameter && ! symbol.isType && ! symbol.flags.is(Flags .ParamAccessor )
194
195
195
- def isJavaClass : Boolean = symbol.isClass && symbol.flags.is(Flags .JavaDefined )
196
+ def isJavaClass : Boolean = ( symbol.isClass || symbol.isObject) && symbol.flags.is(Flags .JavaDefined )
196
197
197
198
def isSelfParameter (implicit ctx : Context ): Boolean =
198
- symbol != NoSymbol && symbol.owner == symbol
199
+ symbol.exists && symbol.owner == symbol
199
200
200
201
def isSemanticdbLocal (implicit ctx : Context ): Boolean = {
201
202
def definitelyGlobal = symbol.isPackage
202
203
def definitelyLocal =
203
- symbol == NoSymbol ||
204
+ ! symbol.exists ||
204
205
(symbol.owner.isTerm && ! symbol.isParameter) ||
205
206
((symbol.owner.isAliasType || symbol.owner.isAbstractType) && ! symbol.isParameter) ||
206
207
symbol.isSelfParameter ||
@@ -217,7 +218,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
217
218
symbol.name == " <init>"
218
219
219
220
def isSyntheticConstructor (implicit ctx : Context ): Boolean = {
220
- val isObjectConstructor = symbol.isConstructor && symbol.owner != NoSymbol && symbol.owner.flags.is(Flags .Object )
221
+ val isObjectConstructor = symbol.isConstructor && symbol.owner.exists && symbol.owner.flags.is(Flags .Object )
221
222
val isModuleConstructor = symbol.isConstructor && symbol.owner.isClass
222
223
val isTraitConstructor = symbol.isConstructor && symbol.owner.isTrait
223
224
val isInterfaceConstructor = symbol.isConstructor && symbol.owner.flags.is(Flags .JavaDefined ) && symbol.owner.isTrait
@@ -268,7 +269,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
268
269
(/* isFieldForPrivateThis ||*/ isFieldForOther) && ! isJavaDefined
269
270
}
270
271
def isUselessField (implicit ctx : Context ): Boolean = {
271
- symbol.isScalacField && symbol.owner != NoSymbol
272
+ symbol.isScalacField && symbol.owner.exists
272
273
}
273
274
def isUsefulField (implicit ctx : Context ): Boolean = {
274
275
symbol.isScalacField && ! symbol.isUselessField
@@ -277,7 +278,11 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
277
278
symbol.flags.is(Flags .CaseAcessor ) && symbol.trueName.contains(" $" )
278
279
}
279
280
def isSyntheticJavaModule (implicit ctx : Context ): Boolean = {
280
- ! symbol.flags.is(Flags .Package ) && symbol.flags.is(Flags .JavaDefined ) && symbol.flags.is(Flags .Object )
281
+ val resolved = symbol match {
282
+ case IsClassSymbol (c) => resolveClass(c)
283
+ case _ => symbol
284
+ }
285
+ ! resolved.flags.is(Flags .Package ) && resolved.flags.is(Flags .JavaDefined ) && resolved.flags.is(Flags .Object )
281
286
}
282
287
def isAnonymousClassConstructor (implicit ctx : Context ): Boolean = {
283
288
symbol.isConstructor && symbol.owner.isAnonymousClass
@@ -299,7 +304,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
299
304
}
300
305
}
301
306
def isStaticMember (implicit ctx : Context ): Boolean =
302
- ( symbol == NoSymbol ) &&
307
+ symbol.exists &&
303
308
(symbol.flags.is(Flags .Static ) || symbol.owner.flags.is(Flags .ImplClass ) ||
304
309
/* symbol.annots.find(_ == ctx.definitions.ScalaStaticAnnot)*/ false )
305
310
@@ -308,8 +313,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
308
313
}
309
314
310
315
def isInitChild (implicit ctx : Context ): Boolean = {
311
- if (! (symbol.name == " <none>" || symbol == NoSymbol )
312
- && symbol.owner != NoSymbol ) {
316
+ if (symbol.exists && symbol.owner.exists) {
313
317
return symbol.owner.name == " <init>" || symbol.owner.isInitChild
314
318
} else {
315
319
return false
@@ -322,13 +326,13 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
322
326
}
323
327
324
328
def isAnonymousInit (implicit ctx : Context ): Boolean = {
325
- return symbol.owner != NoSymbol &&
329
+ return symbol.exists && symbol.owner.exists &&
326
330
(symbol.owner.isAnonymousFunction || symbol.owner.isAnonymousClass) &&
327
331
symbol.name == " <init>"
328
332
}
329
333
330
334
def isUseless (implicit ctx : Context ): Boolean = {
331
- ( symbol.name == " <none> " || symbol == NoSymbol ) ||
335
+ ! symbol.exists ||
332
336
symbol.isReservedName ||
333
337
symbol.isAnonymousInit ||
334
338
symbol.isDefaultGetter ||
@@ -343,9 +347,6 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
343
347
symbol.isSyntheticCaseAccessor ||
344
348
symbol.isRefinementClass ||
345
349
symbol.isSyntheticJavaModule
346
- // isSyntheticJavaModule disable the symbol Class in
347
- // Class.forName(???) to be recorded as Class is considered to
348
- // be a class in dotty, not a typed.
349
350
}
350
351
def isUseful (implicit ctx : Context ): Boolean = ! symbol.isUseless
351
352
def isUselessOccurrence (implicit ctx : Context ): Boolean = {
@@ -392,42 +393,41 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
392
393
}
393
394
394
395
def iterateParent (symbol : Symbol , isMutableAssignement: Boolean = false ): String = {
395
- if (symbol.name == " <none> " || symbol.name == " <root>" ) then {
396
+ if (! symbol.exists || symbol.name == " <root>" ) then {
396
397
" "
397
398
} else {
399
+ val rsymbol = symbol match {
400
+ case IsClassSymbol (c) => resolveClass(c)
401
+ case _ => symbol
402
+ }
398
403
val previous_symbol =
399
404
/* When we consider snipper of the form: `abstract class DepAdvD[CC[X[C] <: B], X[Z], C] extends DepTemp`,
400
405
The symbol for C will be something like example/DepAdvD#`<init>`().[CC].[X].[C].
401
406
This is illogic: a init method can't have any child. Thus, when the current symbol is
402
407
a typeparameter, and the owner is an init, we can just "jump" over the init. */
403
- if (symbol .owner.name == " <init>" && symbol .isType)
404
- iterateParent(symbol .owner.owner)
408
+ if (rsymbol .owner.name == " <init>" && rsymbol .isType)
409
+ iterateParent(rsymbol .owner.owner)
405
410
else
406
- iterateParent(symbol .owner)
411
+ iterateParent(rsymbol .owner)
407
412
408
413
409
- val isdef = symbol match {case IsDefSymbol (_) => true case _ => false }
410
- val symbolName = if (isMutableAssignement) symbol .trueName + " _=" else symbol .trueName
414
+ val isdef = rsymbol match {case IsDefSymbol (_) => true case _ => false }
415
+ val symbolName = if (isMutableAssignement) rsymbol .trueName + " _=" else rsymbol .trueName
411
416
val next_atom =
412
- if (symbol .isPackage) {
417
+ if (rsymbol .isPackage) {
413
418
d.Package (symbolName)
414
- } else if (symbol.isObject) {
415
- symbol match {
416
- case IsClassSymbol (classsymbol) =>
417
- d.Term (resolveClass(classsymbol).trueName)
418
- case _ =>
419
- d.Term (symbolName)
420
- }
421
- } else if (symbol.isValMethod && ! symbol.isVarAccessor) {
419
+ } else if (rsymbol.isObject && ! rsymbol.isJavaClass) {
420
+ d.Term (symbolName)
421
+ } else if (rsymbol.isValMethod && ! rsymbol.isVarAccessor) {
422
422
d.Term (symbolName)
423
- } else if (symbol .isMethod || symbol .isUsefulField || symbol .isVarAccessor) {
423
+ } else if (rsymbol .isMethod || rsymbol .isUsefulField || rsymbol .isVarAccessor) {
424
424
d.Method (symbolName,
425
- disimbiguate(previous_symbol + symbolName, symbol ))
426
- } else if (symbol .isTypeParameter) {
425
+ disimbiguate(previous_symbol + symbolName, rsymbol ))
426
+ } else if (rsymbol .isTypeParameter) {
427
427
d.TypeParameter (symbolName)
428
- } else if (symbol .isValueParameter) {
428
+ } else if (rsymbol .isValueParameter) {
429
429
d.Parameter (symbolName)
430
- } else if (symbol .isType || symbol.isTrait ) {
430
+ } else if (rsymbol .isType || rsymbol.isJavaClass ) {
431
431
d.Type (symbolName)
432
432
} else {
433
433
d.Term (symbolName)
@@ -451,7 +451,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
451
451
typeSymbol : s.SymbolOccurrence .Role ,
452
452
range : s.Range ,
453
453
isMutableAssignement: Boolean = false ): Unit = {
454
- if (symbol.name == " <none> " ) return
454
+ if (! symbol.exists ) return
455
455
456
456
val symbolName = if (isMutableAssignement) symbol.trueName + " _=" else symbol.trueName
457
457
val (symbolPath, isGlobal) =
@@ -515,7 +515,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
515
515
range : s.Range ,
516
516
forceAdd : Boolean = false ,
517
517
isMutableAssignement : Boolean = false ): Unit = {
518
- if (tree.symbol.isUseful &&
518
+ if (! tree.symbol.isUselessOccurrence &&
519
519
tree.symbol.isMutableSetterExplicit(typeSymbol) &&
520
520
(tree.isUserCreated || forceAdd)) {
521
521
addOccurence(tree.symbol, typeSymbol, range, isMutableAssignement)
@@ -525,15 +525,15 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
525
525
def addOccurenceTypeTree (typetree : TypeTree ,
526
526
typeSymbol : s.SymbolOccurrence .Role ,
527
527
range : s.Range ): Unit = {
528
- if (typetree.symbol.isUseful && typetree.isUserCreated) {
528
+ if (! typetree.symbol.isUselessOccurrence && typetree.isUserCreated) {
529
529
addOccurence(typetree.symbol, typeSymbol, range)
530
530
}
531
531
}
532
532
533
533
def addOccurencePatternTree (tree : Pattern ,
534
534
typeSymbol : s.SymbolOccurrence .Role ,
535
535
range : s.Range ): Unit = {
536
- if (tree.symbol.isUseful && tree.isUserCreated) {
536
+ if (! tree.symbol.isUselessOccurrence && tree.isUserCreated) {
537
537
addOccurence(tree.symbol, typeSymbol, range)
538
538
}
539
539
}
@@ -920,7 +920,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
920
920
}
921
921
}
922
922
923
- if (tree.symbol.trueName != " <none> " ) {
923
+ if (tree.symbol.exists ) {
924
924
val pos = tree.symbol.pos
925
925
var rangeSymbol = createRange(pos.startLine, pos.startColumn, tree.symbol.trueName.length)
926
926
0 commit comments