@@ -70,6 +70,12 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
70
70
}
71
71
}
72
72
73
+ implicit class PatternExtender (tree : Pattern ) {
74
+ def isUserCreated : Boolean = {
75
+ return ! (tree.pos.exists && tree.pos.start == tree.pos.end)
76
+ }
77
+ }
78
+
73
79
implicit class SymbolExtender (symbol : Symbol ) {
74
80
def isClass : Boolean = symbol match {
75
81
case IsClassSymbol (_) => true
@@ -251,9 +257,9 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
251
257
252
258
def resolveClass (symbol : ClassSymbol ): Symbol =
253
259
(symbol.companionClass, symbol.companionModule) match {
260
+ case (Some (c), _) => c
254
261
case (_, Some (module)) if symbol.flags.is(Flags .Object ) => module
255
- case (Some (c), _) => c
256
- case _ => symbol
262
+ case _ => symbol
257
263
}
258
264
259
265
def disimbiguate (symbol_path : String , symbol : Symbol ): String = {
@@ -379,7 +385,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
379
385
if (is_global) {
380
386
symbolPathsMap += key
381
387
}
382
- println(symbol_path, range, symbol.owner.flags, is_global)
388
+ println(symbol_path, range, symbol.owner.flags, is_global, iterateParent(symbol) )
383
389
occurrences =
384
390
occurrences :+
385
391
s.SymbolOccurrence (
@@ -389,14 +395,24 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
389
395
)
390
396
}
391
397
392
- val reservedFunctions : List [String ] = " apply " :: " unapply " :: Nil
398
+ val reservedFunctions : List [String ] = Nil
393
399
def addOccurenceTree (tree : Tree ,
394
400
type_symbol : s.SymbolOccurrence .Role ,
395
401
range : s.Range ,
396
402
force_add : Boolean = false ): Unit = {
397
403
if (type_symbol != s.SymbolOccurrence .Role .DEFINITION && reservedFunctions
398
404
.contains(tree.symbol.name))
399
405
return
406
+ /* println(tree.isUserCreated, iterateParent(tree.symbol), force_add)
407
+
408
+ val children: List[Position] =
409
+ ChildTraverser.getChildren(tree)(reflect.rootContext).map(_.pos)
410
+ println("#####", tree.pos.start, tree.pos.end)
411
+ if (tree.symbol.pos.exists) {
412
+ println("#####", tree.symbol.pos.start, tree.symbol.pos.end, tree, tree.symbol.name)
413
+
414
+ }
415
+ children.foreach(p => println(p.start, p.end))*/
400
416
if (tree.isUserCreated || (force_add && ! (! tree.isUserCreated && iterateParent(
401
417
tree.symbol) == " java/lang/Object#`<init>`()." ))) {
402
418
addOccurence(tree.symbol, type_symbol, range)
@@ -405,10 +421,18 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
405
421
def addOccurenceTypeTree (typetree : TypeTree ,
406
422
type_symbol : s.SymbolOccurrence .Role ,
407
423
range : s.Range ): Unit = {
424
+ println(typetree)
408
425
if (typetree.isUserCreated) {
409
426
addOccurence(typetree.symbol, type_symbol, range)
410
427
}
411
428
}
429
+ def addOccurencePatternTree (tree : Pattern ,
430
+ type_symbol : s.SymbolOccurrence .Role ,
431
+ range : s.Range ): Unit = {
432
+ if (tree.isUserCreated) {
433
+ addOccurence(tree.symbol, type_symbol, range)
434
+ }
435
+ }
412
436
def addOccurenceId (parent_path : String , id : Id ): Unit = {
413
437
val symbol_path = Symbols .Global (parent_path, d.Term (id.name))
414
438
occurrences =
@@ -490,15 +514,16 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
490
514
selectors : List [ImportSelector ]): Unit = {
491
515
selectors.foreach(selector =>
492
516
selector match {
493
- case SimpleSelector (id) => {
517
+ case SimpleSelector (id) if id.name != " _ " => {
494
518
addOccurenceId(parent_path, id)
495
519
}
496
- case RenameSelector (id, _) => {
520
+ case RenameSelector (id, _) if id.name != " _ " => {
497
521
addOccurenceId(parent_path, id)
498
522
}
499
- case OmitSelector (id) => {
523
+ case OmitSelector (id) if id.name != " _ " => {
500
524
addOccurenceId(parent_path, id)
501
525
}
526
+ case _ =>
502
527
})
503
528
}
504
529
@@ -526,6 +551,10 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
526
551
range)
527
552
super .traverseTypeTree(typetree)
528
553
}
554
+ case TypeTree .Inferred () => {
555
+ val typetree = extractTypeTree(tree)
556
+ addOccurenceTypeTree(typetree, s.SymbolOccurrence .Role .REFERENCE , posToRange(typetree.pos).get)
557
+ }
529
558
case _ =>
530
559
super .traverseTypeTree(tree)
531
560
}
@@ -534,8 +563,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
534
563
override def traversePattern (tree : Pattern )(implicit ctx : Context ): Unit = {
535
564
tree match {
536
565
case Pattern .Bind (name, _) => {
537
- addOccurence(
538
- tree.symbol,
566
+ addOccurencePatternTree(tree,
539
567
s.SymbolOccurrence .Role .REFERENCE ,
540
568
s.Range (tree.symbol.pos.startLine,
541
569
tree.symbol.pos.startColumn,
@@ -567,47 +595,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
567
595
super .traverseTree(tree)
568
596
}
569
597
case ClassDef (classname, constr, parents, selfopt, statements) => {
570
- println(" \n " )
571
- val resolvedClassSymbol = tree.symbol.asClass.companionClass
572
- val resolvedObjectSymbol = tree.symbol.asClass.companionModule
573
- println(tree.symbol.flags)
574
- if (resolvedClassSymbol != None && resolvedClassSymbol.get.flags.isCase) {
575
- // case class
576
- if (resolvedClassSymbol.get == tree.symbol) {
577
- println(" YES" )
578
- // we first add the class to the symbol list
579
- addOccurenceTree(tree,
580
- s.SymbolOccurrence .Role .DEFINITION ,
581
- range(tree, tree.symbol.pos, tree.symbol.name))
582
598
583
- fittedInitClassRange = Some (
584
- s.Range (constr.symbol.pos.startLine,
585
- constr.symbol.pos.startColumn,
586
- constr.symbol.pos.endLine,
587
- constr.symbol.pos.endColumn))
588
-
589
- traverseTree(constr)
590
- fittedInitClassRange = None
591
- } else {
592
- println(" NO" )
593
- }
594
- } else if (tree.symbol.flags.isObject && tree.symbol.flags.isCase) {
595
- println(" YES object" )
596
- // we first add the class to the symbol list
597
- addOccurenceTree(tree,
598
- s.SymbolOccurrence .Role .DEFINITION ,
599
- range(tree, tree.symbol.pos, tree.symbol.name))
600
-
601
- fittedInitClassRange = Some (
602
- s.Range (constr.symbol.pos.startLine,
603
- constr.symbol.pos.startColumn,
604
- constr.symbol.pos.endLine,
605
- constr.symbol.pos.endColumn))
606
-
607
- traverseTree(constr)
608
- fittedInitClassRange = None
609
- println(" NO object" )
610
- } else {
611
599
// we first add the class to the symbol list
612
600
addOccurenceTree(tree,
613
601
s.SymbolOccurrence .Role .DEFINITION ,
@@ -669,7 +657,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
669
657
}
670
658
671
659
statements.foreach(traverseTree)
672
- }
660
+
673
661
}
674
662
case IsDefinition (cdef) => {
675
663
@@ -740,8 +728,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
740
728
}
741
729
addOccurenceTree(tree,
742
730
s.SymbolOccurrence .Role .REFERENCE ,
743
- range,
744
- true )
731
+ range)
745
732
super .traverseTree(tree)
746
733
}
747
734
0 commit comments