@@ -281,7 +281,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
281281 }
282282
283283 def isUseless (implicit ctx : Context ): Boolean = {
284- symbol == NoSymbol ||
284+ ( symbol.name == " <none> " || symbol == NoSymbol ) ||
285285 symbol.isReservedName ||
286286 symbol.isAnonymousInit ||
287287 symbol.isDefaultGetter ||
@@ -296,6 +296,9 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
296296 symbol.isSyntheticCaseAccessor ||
297297 symbol.isRefinementClass ||
298298 symbol.isSyntheticJavaModule
299+ // isSyntheticJavaModule disable the symbol Class in
300+ // Class.forName(???) to be recorded as Class is considered to
301+ // be a class in dotty, not a typed.
299302 }
300303 def isUseful (implicit ctx : Context ): Boolean = ! symbol.isUseless
301304 def isUselessOccurrence (implicit ctx : Context ): Boolean = {
@@ -427,8 +430,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
427430 isMutableAssignement: Boolean = false ): Unit = {
428431 if (symbol.name == " <none>" ) return
429432
430-
431- println(" ===> " , symbol, symbol.flags)
432433 val symbolName = if (isMutableAssignement) symbol.trueName + " _=" else symbol.trueName
433434 val (symbol_path, is_global) = posToRange(symbol.pos) match {
434435 case Some (keyRange)
@@ -456,12 +457,8 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
456457 // dotty will generate a ValDef for the x, but the x will also
457458 // be present in the constructor, thus making a double definition
458459 if (symbolPathsMap.contains(key)) return
459- // if (is_global) {
460- symbolPathsMap += key
461- // }
462- println(symbol_path,
463- range,
464- symbol.flags)
460+
461+ symbolPathsMap += key
465462 occurrences =
466463 occurrences :+
467464 s.SymbolOccurrence (
@@ -490,15 +487,15 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
490487
491488 val reservedFunctions : List [String ] = Nil
492489 def addOccurenceTree (tree : Tree ,
493- type_symbol : s.SymbolOccurrence .Role ,
490+ typeSymbol : s.SymbolOccurrence .Role ,
494491 range : s.Range ,
495492 force_add : Boolean = false ,
496493 isMutableAssignement : Boolean = false ): Unit = {
497494 if (tree.symbol.isUseful &&
498- isMutableSetterExplicit(tree.symbol, type_symbol ) &&
495+ isMutableSetterExplicit(tree.symbol, typeSymbol ) &&
499496 (tree.isUserCreated ||
500- (force_add && ! (! tree.isUserCreated && iterateParent(tree.symbol) == " java/lang/Object#`<init>`()." )))) {
501- addOccurence(tree.symbol, type_symbol , range, isMutableAssignement)
497+ (force_add /* && !(!tree.isUserCreated && iterateParent(tree.symbol) == "java/lang/Object#`<init>`().")*/ ))) {
498+ addOccurence(tree.symbol, typeSymbol , range, isMutableAssignement)
502499 }
503500 }
504501 def addOccurenceTypeTree (typetree : TypeTree ,
@@ -761,7 +758,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
761758 val start = Map [String , s.Range ]()
762759 params.foldLeft(start)((old, statements) => {
763760 statements.foldLeft(old)((old, cval) => {
764- println(cval)
765761 old + (cval.name -> range(cval, cval.symbol.pos, cval.symbol.trueName))
766762 })
767763 }
@@ -833,9 +829,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
833829 forceAddBecauseParents = ! (tree.symbol.flags.is(Flags .Case ))
834830 parents.foreach(_ match {
835831 case IsTypeTree (t) => traverseTypeTree(t)
836- case IsTerm (t) => {
837- traverseTree(t)
838- }
832+ case IsTerm (t) => traverseTree(t)
839833 })
840834 forceAddBecauseParents = false
841835 selfopt match {
@@ -870,31 +864,20 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
870864 }
871865 case _ =>
872866 }
873- if ( ! tree.symbol.flags.is( Flags . Case )) {
867+
874868 classStacks = tree.symbol :: classStacks
875869
876- println(statements)
877- println(" " )
878870 val paramsPosMapping = generateParamsPosMapping(constr)
879- println(paramsPosMapping)
880- println(" " )
881871
882872 statements.foreach(statement => {
883873 if (statement.symbol.flags.is(Flags .ParamAccessor )) {
884874 if (paramsPosMapping.contains(statement.symbol.name)) {
885- println(" parameter " + statement)
886- addOccurence(statement.symbol, s.SymbolOccurrence .Role .DEFINITION , paramsPosMapping(statement.symbol.name))
875+ addOccurenceTree(statement, s.SymbolOccurrence .Role .DEFINITION , paramsPosMapping(statement.symbol.name))
887876 }
888- // traverseTree(statement)
889877 } else if (! statement.symbol.flags.is(Flags .Param )) {
890- println(statement.symbol, statement.symbol.flags)
891878 traverseTree(statement)
892879 }
893880 })
894-
895- classStacks = classStacks.tail
896- }
897-
898881 }
899882
900883 case DefDef (" <init>" , typeparams, valparams, type_, statements) if fittedInitClassRange != None => {
@@ -914,13 +897,12 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
914897
915898 case Term .Assign (lhs, rhs) => {
916899 isAssignedTerm = true
917- super . traverseTree(tree )
900+ traverseTree(lhs )
918901 isAssignedTerm = false
902+ traverseTree(rhs)
919903 }
920904
921905 case IsDefinition (cdef) => {
922- println(" definition " + cdef.symbol + " " + cdef.symbol.flags)
923- println(cdef.symbol.protectedWithin, cdef.symbol.privateWithin)
924906 if (cdef.symbol.flags.is(Flags .Protected )) {
925907 cdef.symbol.protectedWithin match {
926908 case Some (within) => {
@@ -939,7 +921,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
939921 } else {
940922 cdef.symbol.privateWithin match {
941923 case Some (within) => {
942- println(" YES" )
943924 val startColumn = cdef.pos.startColumn + " private[" .length
944925 addOccurence(
945926 within.typeSymbol,
@@ -978,10 +959,24 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
978959 super .traverseTree(cdef)
979960 }
980961
981- case Term .This (Some (_)) => {
962+ case Term .This (Some (id)) => {
963+ /* We've got two options here:
964+ - either the this is explicit: eg C.this.XXX. In this case, the position is [C.this], but
965+ we want to put the symbol on the C, so around id
966+ - either it is not explicit (eg a.foo). We want to put the symbol only around the a.
967+ Distinguishing between the two is easy. If the sourcecode between [pos.start; pos.end] ends
968+ with a 'this', then we're in the first case, otherwise the second
969+ */
970+ var rangeThis = posToRange(tree.pos).get
971+ if (sourceCode.substring(tree.pos.start, tree.pos.end).endsWith(" this" )) {
972+ rangeThis = range(tree, tree.pos, tree.symbol.trueName)
973+ }
974+ /* range = s.Range(tree.pos.startLine, tree.pos.startColumn,
975+ tree.pos.endLine,
976+ )*/
982977 addOccurenceTree(tree,
983978 s.SymbolOccurrence .Role .REFERENCE ,
984- posToRange(tree.pos).get )
979+ rangeThis )
985980 }
986981
987982 case Term .Super (_, Some (id)) =>
@@ -1001,14 +996,15 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
1001996 range = s.Range (tree.pos.startLine, tree.pos.start - 5 , tree.pos.startLine, tree.pos.start - 1 )
1002997 shouldForceAdd = true
1003998 } else {
999+ range = s.Range (tree.pos.endLine, tree.pos.endColumn, tree.pos.endLine, tree.pos.endColumn)
10041000 shouldForceAdd = qualifier.isUserCreated
10051001 }
10061002 }
10071003 val temp = isAssignedTerm
10081004 isAssignedTerm = false
10091005 super .traverseTree(tree)
10101006 isAssignedTerm = temp
1011- addOccurenceTree(tree, s.SymbolOccurrence .Role .REFERENCE , range, shouldForceAdd, isAssignedTerm && tree.symbol.flags.is(Flags .Mutable ))
1007+ addOccurenceTree(tree, s.SymbolOccurrence .Role .REFERENCE , range, shouldForceAdd, isAssignedTerm && tree.symbol.flags.is(Flags .Mutable ) && ! tree.symbol.flags.is( Flags . PrivateLocal ) )
10121008 }
10131009
10141010 case Term .Ident (name) => {
@@ -1062,9 +1058,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
10621058 }
10631059
10641060 }
1065- println(" {--------------------------------------}" )
1066- println(root)
1067- println(" {--------------------------------------}" )
10681061
10691062 Traverser .traverseTree(root)(reflect.rootContext)
10701063 }
0 commit comments