@@ -119,6 +119,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
119119 }
120120
121121 implicit class SymbolExtender (symbol : Symbol ) {
122+ def exists = ! (symbol.name == " <none>" || symbol == NoSymbol )
122123 /* Return true if symbol represents the definition of a var setter, false otherwise.
123124 We return true if the extract of source code corresponding to the position of the symbol is the same as the symbol name.
124125 Ex:
@@ -192,15 +193,15 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
192193
193194 def isValueParameter : Boolean = symbol.isParameter && ! symbol.isType && ! symbol.flags.is(Flags .ParamAccessor )
194195
195- def isJavaClass : Boolean = symbol.isClass && symbol.flags.is(Flags .JavaDefined )
196+ def isJavaClass : Boolean = ( symbol.isClass || symbol.isObject) && symbol.flags.is(Flags .JavaDefined )
196197
197198 def isSelfParameter (implicit ctx : Context ): Boolean =
198- symbol != NoSymbol && symbol.owner == symbol
199+ symbol.exists && symbol.owner == symbol
199200
200201 def isSemanticdbLocal (implicit ctx : Context ): Boolean = {
201202 def definitelyGlobal = symbol.isPackage
202203 def definitelyLocal =
203- symbol == NoSymbol ||
204+ ! symbol.exists ||
204205 (symbol.owner.isTerm && ! symbol.isParameter) ||
205206 ((symbol.owner.isAliasType || symbol.owner.isAbstractType) && ! symbol.isParameter) ||
206207 symbol.isSelfParameter ||
@@ -217,7 +218,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
217218 symbol.name == " <init>"
218219
219220 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 )
221222 val isModuleConstructor = symbol.isConstructor && symbol.owner.isClass
222223 val isTraitConstructor = symbol.isConstructor && symbol.owner.isTrait
223224 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
268269 (/* isFieldForPrivateThis ||*/ isFieldForOther) && ! isJavaDefined
269270 }
270271 def isUselessField (implicit ctx : Context ): Boolean = {
271- symbol.isScalacField && symbol.owner != NoSymbol
272+ symbol.isScalacField && symbol.owner.exists
272273 }
273274 def isUsefulField (implicit ctx : Context ): Boolean = {
274275 symbol.isScalacField && ! symbol.isUselessField
@@ -277,7 +278,11 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
277278 symbol.flags.is(Flags .CaseAcessor ) && symbol.trueName.contains(" $" )
278279 }
279280 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 )
281286 }
282287 def isAnonymousClassConstructor (implicit ctx : Context ): Boolean = {
283288 symbol.isConstructor && symbol.owner.isAnonymousClass
@@ -299,7 +304,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
299304 }
300305 }
301306 def isStaticMember (implicit ctx : Context ): Boolean =
302- ( symbol == NoSymbol ) &&
307+ symbol.exists &&
303308 (symbol.flags.is(Flags .Static ) || symbol.owner.flags.is(Flags .ImplClass ) ||
304309 /* symbol.annots.find(_ == ctx.definitions.ScalaStaticAnnot)*/ false )
305310
@@ -308,8 +313,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
308313 }
309314
310315 def isInitChild (implicit ctx : Context ): Boolean = {
311- if (! (symbol.name == " <none>" || symbol == NoSymbol )
312- && symbol.owner != NoSymbol ) {
316+ if (symbol.exists && symbol.owner.exists) {
313317 return symbol.owner.name == " <init>" || symbol.owner.isInitChild
314318 } else {
315319 return false
@@ -322,13 +326,13 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
322326 }
323327
324328 def isAnonymousInit (implicit ctx : Context ): Boolean = {
325- return symbol.owner != NoSymbol &&
329+ return symbol.exists && symbol.owner.exists &&
326330 (symbol.owner.isAnonymousFunction || symbol.owner.isAnonymousClass) &&
327331 symbol.name == " <init>"
328332 }
329333
330334 def isUseless (implicit ctx : Context ): Boolean = {
331- ( symbol.name == " <none> " || symbol == NoSymbol ) ||
335+ ! symbol.exists ||
332336 symbol.isReservedName ||
333337 symbol.isAnonymousInit ||
334338 symbol.isDefaultGetter ||
@@ -343,9 +347,6 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
343347 symbol.isSyntheticCaseAccessor ||
344348 symbol.isRefinementClass ||
345349 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.
349350 }
350351 def isUseful (implicit ctx : Context ): Boolean = ! symbol.isUseless
351352 def isUselessOccurrence (implicit ctx : Context ): Boolean = {
@@ -392,42 +393,41 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
392393 }
393394
394395 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 {
396397 " "
397398 } else {
399+ val rsymbol = symbol match {
400+ case IsClassSymbol (c) => resolveClass(c)
401+ case _ => symbol
402+ }
398403 val previous_symbol =
399404 /* When we consider snipper of the form: `abstract class DepAdvD[CC[X[C] <: B], X[Z], C] extends DepTemp`,
400405 The symbol for C will be something like example/DepAdvD#`<init>`().[CC].[X].[C].
401406 This is illogic: a init method can't have any child. Thus, when the current symbol is
402407 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)
405410 else
406- iterateParent(symbol .owner)
411+ iterateParent(rsymbol .owner)
407412
408413
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
411416 val next_atom =
412- if (symbol .isPackage) {
417+ if (rsymbol .isPackage) {
413418 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) {
422422 d.Term (symbolName)
423- } else if (symbol .isMethod || symbol .isUsefulField || symbol .isVarAccessor) {
423+ } else if (rsymbol .isMethod || rsymbol .isUsefulField || rsymbol .isVarAccessor) {
424424 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) {
427427 d.TypeParameter (symbolName)
428- } else if (symbol .isValueParameter) {
428+ } else if (rsymbol .isValueParameter) {
429429 d.Parameter (symbolName)
430- } else if (symbol .isType || symbol.isTrait ) {
430+ } else if (rsymbol .isType || rsymbol.isJavaClass ) {
431431 d.Type (symbolName)
432432 } else {
433433 d.Term (symbolName)
@@ -451,7 +451,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
451451 typeSymbol : s.SymbolOccurrence .Role ,
452452 range : s.Range ,
453453 isMutableAssignement: Boolean = false ): Unit = {
454- if (symbol.name == " <none> " ) return
454+ if (! symbol.exists ) return
455455
456456 val symbolName = if (isMutableAssignement) symbol.trueName + " _=" else symbol.trueName
457457 val (symbolPath, isGlobal) =
@@ -515,7 +515,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
515515 range : s.Range ,
516516 forceAdd : Boolean = false ,
517517 isMutableAssignement : Boolean = false ): Unit = {
518- if (tree.symbol.isUseful &&
518+ if (! tree.symbol.isUselessOccurrence &&
519519 tree.symbol.isMutableSetterExplicit(typeSymbol) &&
520520 (tree.isUserCreated || forceAdd)) {
521521 addOccurence(tree.symbol, typeSymbol, range, isMutableAssignement)
@@ -525,15 +525,15 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
525525 def addOccurenceTypeTree (typetree : TypeTree ,
526526 typeSymbol : s.SymbolOccurrence .Role ,
527527 range : s.Range ): Unit = {
528- if (typetree.symbol.isUseful && typetree.isUserCreated) {
528+ if (! typetree.symbol.isUselessOccurrence && typetree.isUserCreated) {
529529 addOccurence(typetree.symbol, typeSymbol, range)
530530 }
531531 }
532532
533533 def addOccurencePatternTree (tree : Pattern ,
534534 typeSymbol : s.SymbolOccurrence .Role ,
535535 range : s.Range ): Unit = {
536- if (tree.symbol.isUseful && tree.isUserCreated) {
536+ if (! tree.symbol.isUselessOccurrence && tree.isUserCreated) {
537537 addOccurence(tree.symbol, typeSymbol, range)
538538 }
539539 }
@@ -920,7 +920,7 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
920920 }
921921 }
922922
923- if (tree.symbol.trueName != " <none> " ) {
923+ if (tree.symbol.exists ) {
924924 val pos = tree.symbol.pos
925925 var rangeSymbol = createRange(pos.startLine, pos.startColumn, tree.symbol.trueName.length)
926926
0 commit comments