@@ -281,7 +281,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
281
281
}
282
282
283
283
def isUseless (implicit ctx : Context ): Boolean = {
284
- symbol == NoSymbol ||
284
+ ( symbol.name == " <none> " || symbol == NoSymbol ) ||
285
285
symbol.isReservedName ||
286
286
symbol.isAnonymousInit ||
287
287
symbol.isDefaultGetter ||
@@ -296,6 +296,9 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
296
296
symbol.isSyntheticCaseAccessor ||
297
297
symbol.isRefinementClass ||
298
298
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.
299
302
}
300
303
def isUseful (implicit ctx : Context ): Boolean = ! symbol.isUseless
301
304
def isUselessOccurrence (implicit ctx : Context ): Boolean = {
@@ -427,8 +430,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
427
430
isMutableAssignement: Boolean = false ): Unit = {
428
431
if (symbol.name == " <none>" ) return
429
432
430
-
431
- println(" ===> " , symbol, symbol.flags)
432
433
val symbolName = if (isMutableAssignement) symbol.trueName + " _=" else symbol.trueName
433
434
val (symbol_path, is_global) = posToRange(symbol.pos) match {
434
435
case Some (keyRange)
@@ -456,12 +457,8 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
456
457
// dotty will generate a ValDef for the x, but the x will also
457
458
// be present in the constructor, thus making a double definition
458
459
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
465
462
occurrences =
466
463
occurrences :+
467
464
s.SymbolOccurrence (
@@ -490,15 +487,15 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
490
487
491
488
val reservedFunctions : List [String ] = Nil
492
489
def addOccurenceTree (tree : Tree ,
493
- type_symbol : s.SymbolOccurrence .Role ,
490
+ typeSymbol : s.SymbolOccurrence .Role ,
494
491
range : s.Range ,
495
492
force_add : Boolean = false ,
496
493
isMutableAssignement : Boolean = false ): Unit = {
497
494
if (tree.symbol.isUseful &&
498
- isMutableSetterExplicit(tree.symbol, type_symbol ) &&
495
+ isMutableSetterExplicit(tree.symbol, typeSymbol ) &&
499
496
(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)
502
499
}
503
500
}
504
501
def addOccurenceTypeTree (typetree : TypeTree ,
@@ -761,7 +758,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
761
758
val start = Map [String , s.Range ]()
762
759
params.foldLeft(start)((old, statements) => {
763
760
statements.foldLeft(old)((old, cval) => {
764
- println(cval)
765
761
old + (cval.name -> range(cval, cval.symbol.pos, cval.symbol.trueName))
766
762
})
767
763
}
@@ -833,9 +829,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
833
829
forceAddBecauseParents = ! (tree.symbol.flags.is(Flags .Case ))
834
830
parents.foreach(_ match {
835
831
case IsTypeTree (t) => traverseTypeTree(t)
836
- case IsTerm (t) => {
837
- traverseTree(t)
838
- }
832
+ case IsTerm (t) => traverseTree(t)
839
833
})
840
834
forceAddBecauseParents = false
841
835
selfopt match {
@@ -870,31 +864,20 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
870
864
}
871
865
case _ =>
872
866
}
873
- if ( ! tree.symbol.flags.is( Flags . Case )) {
867
+
874
868
classStacks = tree.symbol :: classStacks
875
869
876
- println(statements)
877
- println(" " )
878
870
val paramsPosMapping = generateParamsPosMapping(constr)
879
- println(paramsPosMapping)
880
- println(" " )
881
871
882
872
statements.foreach(statement => {
883
873
if (statement.symbol.flags.is(Flags .ParamAccessor )) {
884
874
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))
887
876
}
888
- // traverseTree(statement)
889
877
} else if (! statement.symbol.flags.is(Flags .Param )) {
890
- println(statement.symbol, statement.symbol.flags)
891
878
traverseTree(statement)
892
879
}
893
880
})
894
-
895
- classStacks = classStacks.tail
896
- }
897
-
898
881
}
899
882
900
883
case DefDef (" <init>" , typeparams, valparams, type_, statements) if fittedInitClassRange != None => {
@@ -914,13 +897,12 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
914
897
915
898
case Term .Assign (lhs, rhs) => {
916
899
isAssignedTerm = true
917
- super . traverseTree(tree )
900
+ traverseTree(lhs )
918
901
isAssignedTerm = false
902
+ traverseTree(rhs)
919
903
}
920
904
921
905
case IsDefinition (cdef) => {
922
- println(" definition " + cdef.symbol + " " + cdef.symbol.flags)
923
- println(cdef.symbol.protectedWithin, cdef.symbol.privateWithin)
924
906
if (cdef.symbol.flags.is(Flags .Protected )) {
925
907
cdef.symbol.protectedWithin match {
926
908
case Some (within) => {
@@ -939,7 +921,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
939
921
} else {
940
922
cdef.symbol.privateWithin match {
941
923
case Some (within) => {
942
- println(" YES" )
943
924
val startColumn = cdef.pos.startColumn + " private[" .length
944
925
addOccurence(
945
926
within.typeSymbol,
@@ -978,10 +959,24 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
978
959
super .traverseTree(cdef)
979
960
}
980
961
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
+ )*/
982
977
addOccurenceTree(tree,
983
978
s.SymbolOccurrence .Role .REFERENCE ,
984
- posToRange(tree.pos).get )
979
+ rangeThis )
985
980
}
986
981
987
982
case Term .Super (_, Some (id)) =>
@@ -1001,14 +996,15 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
1001
996
range = s.Range (tree.pos.startLine, tree.pos.start - 5 , tree.pos.startLine, tree.pos.start - 1 )
1002
997
shouldForceAdd = true
1003
998
} else {
999
+ range = s.Range (tree.pos.endLine, tree.pos.endColumn, tree.pos.endLine, tree.pos.endColumn)
1004
1000
shouldForceAdd = qualifier.isUserCreated
1005
1001
}
1006
1002
}
1007
1003
val temp = isAssignedTerm
1008
1004
isAssignedTerm = false
1009
1005
super .traverseTree(tree)
1010
1006
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 ) )
1012
1008
}
1013
1009
1014
1010
case Term .Ident (name) => {
@@ -1062,9 +1058,6 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
1062
1058
}
1063
1059
1064
1060
}
1065
- println(" {--------------------------------------}" )
1066
- println(root)
1067
- println(" {--------------------------------------}" )
1068
1061
1069
1062
Traverser .traverseTree(root)(reflect.rootContext)
1070
1063
}
0 commit comments