@@ -95,7 +95,8 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
95
95
case _ => false
96
96
}
97
97
98
- def isDefaultGetter : Boolean = symbol.name.contains(tpnme.DEFAULT_GETTER .toString)
98
+ def isDefaultGetter : Boolean =
99
+ symbol.name.contains(tpnme.DEFAULT_GETTER .toString)
99
100
100
101
def isParameter : Boolean = symbol.flags.is(Flags .Param )
101
102
@@ -388,12 +389,12 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
388
389
)
389
390
}
390
391
391
- val reserverdFunctions : List [String ] = " apply" :: " unapply" :: Nil
392
+ val reservedFunctions : List [String ] = " apply" :: " unapply" :: Nil
392
393
def addOccurenceTree (tree : Tree ,
393
394
type_symbol : s.SymbolOccurrence .Role ,
394
395
range : s.Range ,
395
396
force_add : Boolean = false ): Unit = {
396
- if (type_symbol != s.SymbolOccurrence .Role .DEFINITION && reserverdFunctions
397
+ if (type_symbol != s.SymbolOccurrence .Role .DEFINITION && reservedFunctions
397
398
.contains(tree.symbol.name))
398
399
return
399
400
if (tree.isUserCreated || (force_add && ! (! tree.isUserCreated && iterateParent(
@@ -566,68 +567,109 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
566
567
super .traverseTree(tree)
567
568
}
568
569
case ClassDef (classname, constr, parents, selfopt, statements) => {
569
- // we first add the class to the symbol list
570
- addOccurenceTree(tree,
571
- s.SymbolOccurrence .Role .DEFINITION ,
572
- range(tree, tree.symbol.pos, tree.symbol.name))
573
- // println("constr symbol pos: ", constr.symbol.pos.startColumn, constr.symbol.pos.endColumn)
574
- // println("constr pos: ", constr.pos.startColumn, constr.pos.endColumn)
575
- // then the constructor
576
- if (! constr.isUserCreated) {
577
- fittedInitClassRange = Some (
578
- s.Range (tree.symbol.pos.startLine,
579
- tree.symbol.pos.startColumn + classname.length + 1 ,
580
- tree.symbol.pos.startLine,
581
- tree.symbol.pos.startColumn + classname.length + 1 ))
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
+
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" )
582
610
} else {
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
-
592
- // we add the parents to the symbol list
593
- forceAddBecauseParents = true
594
- parents.foreach(_ match {
595
- case IsTypeTree (t) => traverseTypeTree(t)
596
- case IsTerm (t) => {
597
- traverseTree(t)
611
+ // we first add the class to the symbol list
612
+ addOccurenceTree(tree,
613
+ s.SymbolOccurrence .Role .DEFINITION ,
614
+ range(tree, tree.symbol.pos, tree.symbol.name))
615
+ // println("constr symbol pos: ", constr.symbol.pos.startColumn, constr.symbol.pos.endColumn)
616
+ // println("constr pos: ", constr.pos.startColumn, constr.pos.endColumn)
617
+ // then the constructor
618
+ if (! constr.isUserCreated) {
619
+ fittedInitClassRange = Some (
620
+ s.Range (tree.symbol.pos.startLine,
621
+ tree.symbol.pos.startColumn + classname.length + 1 ,
622
+ tree.symbol.pos.startLine,
623
+ tree.symbol.pos.startColumn + classname.length + 1 ))
624
+ } else {
625
+ fittedInitClassRange = Some (
626
+ s.Range (constr.symbol.pos.startLine,
627
+ constr.symbol.pos.startColumn,
628
+ constr.symbol.pos.endLine,
629
+ constr.symbol.pos.endColumn))
598
630
}
599
- })
600
- forceAddBecauseParents = false
601
-
602
- selfopt match {
603
- case Some (vdef @ ValDef (name, _, _)) if name != " _" => {
604
- // To find the current position, we will heuristically
605
- // reparse the source code.
606
- // The process is done in three steps:
607
- // 1) Find a position before the '{' of the self but after any
608
- // non related '{'. Here, it will be the largest end pos of a parent
609
- // 2) Find the first '{'
610
- // 3) Iterate until the character we are seeing is a letter
611
- val startPosSearch : Int = parents.foldLeft(tree.pos.endColumn)(
612
- (old : Int , ct : TermOrTypeTree ) =>
631
+ traverseTree(constr)
632
+ fittedInitClassRange = None
633
+
634
+ // we add the parents to the symbol list
635
+ forceAddBecauseParents = true
636
+ parents.foreach(_ match {
637
+ case IsTypeTree (t) => traverseTypeTree(t)
638
+ case IsTerm (t) => {
639
+ traverseTree(t)
640
+ }
641
+ })
642
+ forceAddBecauseParents = false
643
+
644
+ selfopt match {
645
+ case Some (vdef @ ValDef (name, _, _)) if name != " _" => {
646
+ // To find the current position, we will heuristically
647
+ // reparse the source code.
648
+ // The process is done in three steps:
649
+ // 1) Find a position before the '{' of the self but after any
650
+ // non related '{'. Here, it will be the largest end pos of a parent
651
+ // 2) Find the first '{'
652
+ // 3) Iterate until the character we are seeing is a letter
653
+ val startPosSearch : Int = parents.foldLeft(
654
+ tree.pos.endColumn)((old : Int , ct : TermOrTypeTree ) =>
613
655
ct match {
614
656
case IsTerm (t) if t.pos.endColumn < old => t.pos.endColumn
615
- case _ => old
657
+ case _ => old
616
658
})
617
- var posColumn = sourceCode.indexOf(" {" , startPosSearch)
618
- while (! sourceCode(posColumn).isLetter && posColumn < sourceCode.length) posColumn += 1
619
-
620
- addSelfDefinition(name,
621
- s.Range (vdef.pos.startLine,
622
- posColumn,
623
- vdef.pos.endLine,
624
- posColumn + name.length))
659
+ var posColumn = sourceCode.indexOf(" {" , startPosSearch)
660
+ while (! sourceCode(posColumn).isLetter && posColumn < sourceCode.length) posColumn += 1
661
+
662
+ addSelfDefinition(name,
663
+ s.Range (vdef.pos.startLine,
664
+ posColumn,
665
+ vdef.pos.endLine,
666
+ posColumn + name.length))
667
+ }
668
+ case _ =>
625
669
}
626
- case _ =>
627
- }
628
- selfopt.foreach(traverseTree)
629
670
630
- statements.foreach(traverseTree)
671
+ statements.foreach(traverseTree)
672
+ }
631
673
}
632
674
case IsDefinition (cdef) => {
633
675
0 commit comments