Skip to content

Commit

Permalink
Fix the order of traverse tree
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishiking committed Aug 20, 2021
1 parent 5a108df commit 91f243c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ class ExtractSemanticDB extends Phase:
registerSymbol(tree.symbol, symbolKinds(tree))
case tree: Template =>
val ctorSym = tree.constr.symbol
if !excludeDef(ctorSym) then
traverseAnnotsOfDefinition(ctorSym)
registerDefinition(ctorSym, tree.constr.nameSpan.startPos, Set.empty, tree.source)
ctorParams(tree.constr.termParamss, tree.constr.leadingTypeParams, tree.body)
for parent <- tree.parentsOrDerived if parent.span.hasLength do
traverse(parent)
val selfSpan = tree.self.span
Expand All @@ -191,6 +187,10 @@ class ExtractSemanticDB extends Phase:
tree.body.foreachUntilImport(traverse).foreach(traverse) // the first import statement
else
tree.body.foreach(traverse)
if !excludeDef(ctorSym) then
traverseAnnotsOfDefinition(ctorSym)
registerDefinition(ctorSym, tree.constr.nameSpan.startPos, Set.empty, tree.source)
ctorParams(tree.constr.termParamss, tree.constr.leadingTypeParams, tree.body)
case tree: Apply =>
@tu lazy val genParamSymbol: Name => String = tree.fun.symbol.funParamSymbol
traverse(tree.fun)
Expand Down
20 changes: 10 additions & 10 deletions tests/semanticdb/expect/RecOrRefined.expect.scala
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package example

def m1/*<-example::RecOrRefined$package.m1().*/(a/*<-example::RecOrRefined$package.m1().(a)*/: Int/*->scala::Int#*/ { val x/*<-local3*/: Int/*->scala::Int#*/ }) = ???/*->scala::Predef.`???`().*/
def m2/*<-example::RecOrRefined$package.m2().*/(x/*<-example::RecOrRefined$package.m2().(x)*/: { val x/*<-local4*/: Int/*->scala::Int#*/; def y/*<-local5*/: Int/*->scala::Int#*/ }) = ???/*->scala::Predef.`???`().*/
def m3/*<-example::RecOrRefined$package.m3().*/(x/*<-example::RecOrRefined$package.m3().(x)*/: { val x/*<-local6*/: Int/*->scala::Int#*/; def y/*<-local7*/: Int/*->scala::Int#*/; type z/*<-local8*/ }) = ???/*->scala::Predef.`???`().*/
def m1/*<-example::RecOrRefined$package.m1().*/(a/*<-example::RecOrRefined$package.m1().(a)*/: Int/*->scala::Int#*/ { val x/*<-local4*/: Int/*->scala::Int#*/ }) = ???/*->scala::Predef.`???`().*/
def m2/*<-example::RecOrRefined$package.m2().*/(x/*<-example::RecOrRefined$package.m2().(x)*/: { val x/*<-local5*/: Int/*->scala::Int#*/; def y/*<-local6*/: Int/*->scala::Int#*/ }) = ???/*->scala::Predef.`???`().*/
def m3/*<-example::RecOrRefined$package.m3().*/(x/*<-example::RecOrRefined$package.m3().(x)*/: { val x/*<-local7*/: Int/*->scala::Int#*/; def y/*<-local8*/: Int/*->scala::Int#*/; type z/*<-local9*/ }) = ???/*->scala::Predef.`???`().*/
trait PolyHolder/*<-example::PolyHolder#*/ {
def foo/*<-example::PolyHolder#foo().*/[T/*<-example::PolyHolder#foo().[T]*/](t/*<-example::PolyHolder#foo().(t)*/: T/*->example::PolyHolder#foo().[T]*/): Any/*->scala::Any#*/
}

def m4/*<-example::RecOrRefined$package.m4().*/(x/*<-example::RecOrRefined$package.m4().(x)*/: PolyHolder/*->example::PolyHolder#*/ { def foo/*<-local11*/[T/*<-local9*/](t/*<-local10*/: T/*->local9*/): T/*->local9*/ }) = ???/*->scala::Predef.`???`().*/
def m5/*<-example::RecOrRefined$package.m5().*/[Z/*<-example::RecOrRefined$package.m5().[Z]*/](x/*<-example::RecOrRefined$package.m5().(x)*/: Int/*->scala::Int#*/): PolyHolder/*->example::PolyHolder#*/ { def foo/*<-local14*/[T/*<-local12*/](t/*<-local13*/: T/*->local12*/): T/*->local12*/ } = ???/*->scala::Predef.`???`().*/
def m4/*<-example::RecOrRefined$package.m4().*/(x/*<-example::RecOrRefined$package.m4().(x)*/: PolyHolder/*->example::PolyHolder#*/ { def foo/*<-local12*/[T/*<-local10*/](t/*<-local11*/: T/*->local10*/): T/*->local10*/ }) = ???/*->scala::Predef.`???`().*/
def m5/*<-example::RecOrRefined$package.m5().*/[Z/*<-example::RecOrRefined$package.m5().[Z]*/](x/*<-example::RecOrRefined$package.m5().(x)*/: Int/*->scala::Int#*/): PolyHolder/*->example::PolyHolder#*/ { def foo/*<-local15*/[T/*<-local13*/](t/*<-local14*/: T/*->local13*/): T/*->local13*/ } = ???/*->scala::Predef.`???`().*/

type m6/*<-example::RecOrRefined$package.m6#*/ = [X/*<-example::RecOrRefined$package.m6#[X]*/] =>> PolyHolder/*->example::PolyHolder#*/ { def foo/*<-local17*/[T/*<-local15*/](t/*<-local16*/: T/*->local15*/): T/*->local15*/ }
type m6/*<-example::RecOrRefined$package.m6#*/ = [X/*<-example::RecOrRefined$package.m6#[X]*/] =>> PolyHolder/*->example::PolyHolder#*/ { def foo/*<-local18*/[T/*<-local16*/](t/*<-local17*/: T/*->local16*/): T/*->local16*/ }

class Record/*<-example::Record#*/(elems/*<-example::Record#elems.*/: (String/*->scala::Predef.String#*/, Any/*->scala::Any#*/)*) extends Selectable/*->scala::Selectable#*/:
private val fields/*<-example::Record#fields.*/ = elems/*->example::Record#elems.*/.toMap/*->scala::collection::IterableOnceOps#toMap().*/
def selectDynamic/*<-example::Record#selectDynamic().*/(name/*<-example::Record#selectDynamic().(name)*/: String/*->scala::Predef.String#*/): Any/*->scala::Any#*/ = fields/*->example::Record#fields.*/(name/*->example::Record#selectDynamic().(name)*/)

type Person/*<-example::RecOrRefined$package.Person#*/ = Record/*->example::Record#*/ {
val name/*<-local18*/: String/*->scala::Predef.String#*/
val age/*<-local19*/: Int/*->scala::Int#*/
val name/*<-local19*/: String/*->scala::Predef.String#*/
val age/*<-local20*/: Int/*->scala::Int#*/
}

// RecType
class C/*<-example::C#*/ { type T1/*<-example::C#T1#*/; type T2/*<-example::C#T2#*/ }
type C2/*<-example::RecOrRefined$package.C2#*/ = C/*->example::C#*/ { type T1/*<-local20*/; type T2/*<-local21*/ = T1/*->local20*/ }
type C2/*<-example::RecOrRefined$package.C2#*/ = C/*->example::C#*/ { type T1/*<-local21*/; type T2/*<-local22*/ = T1/*->local21*/ }

trait SpecialRefinement/*<-example::SpecialRefinement#*/ {
def pickOne/*<-example::SpecialRefinement#pickOne().*/[T/*<-example::SpecialRefinement#pickOne().[T]*/](as/*<-example::SpecialRefinement#pickOne().(as)*/: T/*->example::SpecialRefinement#pickOne().[T]*/*): Option/*->scala::Option#*/[Any/*->scala::Any#*/]
}

class PickOneRefinement_1/*<-example::PickOneRefinement_1#*/[S/*<-example::PickOneRefinement_1#[S]*/ <: SpecialRefinement/*->example::SpecialRefinement#*/ { def pickOne/*<-local2*/[T/*<-local0*/](as/*<-local1*/: T/*->local0*/*): Option/*->scala::Option#*/[String/*->scala::Predef.String#*/] }] {
class PickOneRefinement_1/*<-example::PickOneRefinement_1#*/[S/*<-example::PickOneRefinement_1#[S]*/ <: SpecialRefinement/*->example::SpecialRefinement#*/ { def pickOne/*<-local3*/[T/*<-local1*/](as/*<-local2*/: T/*->local1*/*): Option/*->scala::Option#*/[String/*->scala::Predef.String#*/] }] {
def run/*<-example::PickOneRefinement_1#run().*/(s/*<-example::PickOneRefinement_1#run().(s)*/: S/*->example::PickOneRefinement_1#[S]*/, as/*<-example::PickOneRefinement_1#run().(as)*/: String/*->scala::Predef.String#*/*): Option/*->scala::Option#*/[String/*->scala::Predef.String#*/] = s/*->example::PickOneRefinement_1#run().(s)*/.pickOne/*->example::SpecialRefinement#pickOne().*/(as/*->example::PickOneRefinement_1#run().(as)*/:_*)
}
119 changes: 62 additions & 57 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Schema => SemanticDB v4
Uri => Advanced.scala
Text => empty
Language => Scala
Symbols => 47 entries
Symbols => 48 entries
Occurrences => 105 entries

Symbols:
Expand All @@ -58,6 +58,7 @@ advanced/C#`<init>`(). => primary ctor <init> [typeparam T ](): C[T]
advanced/C#t(). => method t => T
advanced/HKClass# => class HKClass [typeparam F [typeparam T ] <: <?>] extends Object { self: HKClass[F] => +3 decls }
advanced/HKClass#[F] => typeparam F [typeparam T ] <: <?>
advanced/HKClass#[F][T] => typeparam T
advanced/HKClass#`<init>`(). => primary ctor <init> [typeparam F [typeparam T ] <: <?>](): HKClass[F]
advanced/HKClass#`<init>`().[F][T] => typeparam T
advanced/HKClass#`<init>`().[F][U] => typeparam U
Expand Down Expand Up @@ -2675,17 +2676,19 @@ Schema => SemanticDB v4
Uri => RecOrRefined.scala
Text => empty
Language => Scala
Symbols => 66 entries
Symbols => 69 entries
Occurrences => 110 entries

Symbols:
example/C# => class C extends Object { self: C => +3 decls }
example/C#T1# => type T1
example/C#T2# => type T2
example/C#`<init>`(). => primary ctor <init> (): C
example/PickOneRefinement_1# => class PickOneRefinement_1 [typeparam S <: SpecialRefinement { abstract method pickOne [typeparam T ](param as: T*): Option[String] <: example/SpecialRefinement#pickOne(). }] extends Object { self: PickOneRefinement_1[S] => +3 decls }
example/PickOneRefinement_1#[S] => typeparam S <: SpecialRefinement { abstract method pickOne [typeparam T ](param as: T*): Option[String] <: example/SpecialRefinement#pickOne(). }
example/PickOneRefinement_1#`<init>`(). => primary ctor <init> [typeparam S <: SpecialRefinement { abstract method pickOne [typeparam T ](param as: T*): Option[String] <: example/SpecialRefinement#pickOne(). }](): PickOneRefinement_1[S]
example/PickOneRefinement_1# => class PickOneRefinement_1 [typeparam S <: SpecialRefinement { abstract method pickOne [typeparam T ](param as: T*): Option[String] }] extends Object { self: PickOneRefinement_1[S] => +3 decls }
example/PickOneRefinement_1#[S] => typeparam S <: SpecialRefinement { abstract method pickOne [typeparam T ](param as: T*): Option[String] }
example/PickOneRefinement_1#[S](as) => param as: T*
example/PickOneRefinement_1#[S][T] => typeparam T
example/PickOneRefinement_1#`<init>`(). => primary ctor <init> [typeparam S <: SpecialRefinement { abstract method pickOne [typeparam T ](param as: T*): Option[String] }](): PickOneRefinement_1[S]
example/PickOneRefinement_1#run(). => method run (param s: S, param as: String*): Option[String]
example/PickOneRefinement_1#run().(as) => param as: String*
example/PickOneRefinement_1#run().(s) => param s: S
Expand Down Expand Up @@ -2723,51 +2726,52 @@ example/SpecialRefinement#`<init>`(). => primary ctor <init> (): SpecialRefineme
example/SpecialRefinement#pickOne(). => abstract method pickOne [typeparam T ](param as: T*): Option[Any]
example/SpecialRefinement#pickOne().(as) => param as: T*
example/SpecialRefinement#pickOne().[T] => typeparam T
local0 => typeparam T
local1 => param as: T*
local2 => abstract method pickOne [typeparam T ](param as: T*): Option[String] <: example/SpecialRefinement#pickOne().
local3 => abstract val method x Int
local0 => abstract method pickOne [typeparam T ](param as: T*): Option[String]
local1 => typeparam T
local2 => param as: T*
local3 => abstract method pickOne [typeparam T ](param as: T*): Option[String] <: example/SpecialRefinement#pickOne().
local4 => abstract val method x Int
local5 => abstract method y => Int
local6 => abstract val method x Int
local7 => abstract method y => Int
local8 => type z
local9 => typeparam T
local10 => param t: T
local11 => abstract method foo [typeparam T ](param t: T): T <: example/PolyHolder#foo().
local12 => typeparam T
local13 => param t: T
local14 => abstract method foo [typeparam T ](param t: T): T <: example/PolyHolder#foo().
local15 => typeparam T
local16 => param t: T
local17 => abstract method foo [typeparam T ](param t: T): T <: example/PolyHolder#foo().
local18 => abstract val method name String
local19 => abstract val method age Int
local20 => type T1 <: example/C#T1#
local21 => type T2 = T1 <: example/C#T2#
local5 => abstract val method x Int
local6 => abstract method y => Int
local7 => abstract val method x Int
local8 => abstract method y => Int
local9 => type z
local10 => typeparam T
local11 => param t: T
local12 => abstract method foo [typeparam T ](param t: T): T <: example/PolyHolder#foo().
local13 => typeparam T
local14 => param t: T
local15 => abstract method foo [typeparam T ](param t: T): T <: example/PolyHolder#foo().
local16 => typeparam T
local17 => param t: T
local18 => abstract method foo [typeparam T ](param t: T): T <: example/PolyHolder#foo().
local19 => abstract val method name String
local20 => abstract val method age Int
local21 => type T1 <: example/C#T1#
local22 => type T2 = T1 <: example/C#T2#

Occurrences:
[0:8..0:15): example <- example/
[2:4..2:6): m1 <- example/RecOrRefined$package.m1().
[2:7..2:8): a <- example/RecOrRefined$package.m1().(a)
[2:10..2:13): Int -> scala/Int#
[2:20..2:21): x <- local3
[2:20..2:21): x <- local4
[2:23..2:26): Int -> scala/Int#
[2:32..2:35): ??? -> scala/Predef.`???`().
[3:4..3:6): m2 <- example/RecOrRefined$package.m2().
[3:7..3:8): x <- example/RecOrRefined$package.m2().(x)
[3:16..3:17): x <- local4
[3:16..3:17): x <- local5
[3:19..3:22): Int -> scala/Int#
[3:28..3:29): y <- local5
[3:28..3:29): y <- local6
[3:31..3:34): Int -> scala/Int#
[3:40..3:43): ??? -> scala/Predef.`???`().
[4:4..4:6): m3 <- example/RecOrRefined$package.m3().
[4:7..4:8): x <- example/RecOrRefined$package.m3().(x)
[4:16..4:17): x <- local6
[4:16..4:17): x <- local7
[4:19..4:22): Int -> scala/Int#
[4:28..4:29): y <- local7
[4:28..4:29): y <- local8
[4:31..4:34): Int -> scala/Int#
[4:41..4:42): z <- local8
[4:41..4:42): z <- local9
[4:48..4:51): ??? -> scala/Predef.`???`().
[5:6..5:16): PolyHolder <- example/PolyHolder#
[6:6..6:9): foo <- example/PolyHolder#foo().
Expand All @@ -2778,31 +2782,31 @@ Occurrences:
[9:4..9:6): m4 <- example/RecOrRefined$package.m4().
[9:7..9:8): x <- example/RecOrRefined$package.m4().(x)
[9:10..9:20): PolyHolder -> example/PolyHolder#
[9:27..9:30): foo <- local11
[9:31..9:32): T <- local9
[9:34..9:35): t <- local10
[9:37..9:38): T -> local9
[9:41..9:42): T -> local9
[9:27..9:30): foo <- local12
[9:31..9:32): T <- local10
[9:34..9:35): t <- local11
[9:37..9:38): T -> local10
[9:41..9:42): T -> local10
[9:48..9:51): ??? -> scala/Predef.`???`().
[10:4..10:6): m5 <- example/RecOrRefined$package.m5().
[10:7..10:8): Z <- example/RecOrRefined$package.m5().[Z]
[10:10..10:11): x <- example/RecOrRefined$package.m5().(x)
[10:13..10:16): Int -> scala/Int#
[10:19..10:29): PolyHolder -> example/PolyHolder#
[10:36..10:39): foo <- local14
[10:40..10:41): T <- local12
[10:43..10:44): t <- local13
[10:46..10:47): T -> local12
[10:50..10:51): T -> local12
[10:36..10:39): foo <- local15
[10:40..10:41): T <- local13
[10:43..10:44): t <- local14
[10:46..10:47): T -> local13
[10:50..10:51): T -> local13
[10:56..10:59): ??? -> scala/Predef.`???`().
[12:5..12:7): m6 <- example/RecOrRefined$package.m6#
[12:11..12:12): X <- example/RecOrRefined$package.m6#[X]
[12:18..12:28): PolyHolder -> example/PolyHolder#
[12:35..12:38): foo <- local17
[12:39..12:40): T <- local15
[12:42..12:43): t <- local16
[12:45..12:46): T -> local15
[12:49..12:50): T -> local15
[12:35..12:38): foo <- local18
[12:39..12:40): T <- local16
[12:42..12:43): t <- local17
[12:45..12:46): T -> local16
[12:49..12:50): T -> local16
[14:6..14:12): Record <- example/Record#
[14:13..14:18): elems <- example/Record#elems.
[14:21..14:27): String -> scala/Predef.String#
Expand All @@ -2819,18 +2823,18 @@ Occurrences:
[16:48..16:52): name -> example/Record#selectDynamic().(name)
[18:5..18:11): Person <- example/RecOrRefined$package.Person#
[18:14..18:20): Record -> example/Record#
[19:6..19:10): name <- local18
[19:6..19:10): name <- local19
[19:12..19:18): String -> scala/Predef.String#
[20:6..20:9): age <- local19
[20:6..20:9): age <- local20
[20:11..20:14): Int -> scala/Int#
[24:6..24:7): C <- example/C#
[24:15..24:17): T1 <- example/C#T1#
[24:24..24:26): T2 <- example/C#T2#
[25:5..25:7): C2 <- example/RecOrRefined$package.C2#
[25:10..25:11): C -> example/C#
[25:19..25:21): T1 <- local20
[25:28..25:30): T2 <- local21
[25:33..25:35): T1 -> local20
[25:19..25:21): T1 <- local21
[25:28..25:30): T2 <- local22
[25:33..25:35): T1 -> local21
[27:6..27:23): SpecialRefinement <- example/SpecialRefinement#
[28:6..28:13): pickOne <- example/SpecialRefinement#pickOne().
[28:14..28:15): T <- example/SpecialRefinement#pickOne().[T]
Expand All @@ -2841,10 +2845,10 @@ Occurrences:
[31:6..31:25): PickOneRefinement_1 <- example/PickOneRefinement_1#
[31:26..31:27): S <- example/PickOneRefinement_1#[S]
[31:31..31:48): SpecialRefinement -> example/SpecialRefinement#
[31:55..31:62): pickOne <- local2
[31:63..31:64): T <- local0
[31:66..31:68): as <- local1
[31:70..31:71): T -> local0
[31:55..31:62): pickOne <- local3
[31:63..31:64): T <- local1
[31:66..31:68): as <- local2
[31:70..31:71): T -> local1
[31:75..31:81): Option -> scala/Option#
[31:82..31:88): String -> scala/Predef.String#
[32:6..32:9): run <- example/PickOneRefinement_1#run().
Expand Down Expand Up @@ -3773,7 +3777,7 @@ Schema => SemanticDB v4
Uri => nullary.scala
Text => empty
Language => Scala
Symbols => 16 entries
Symbols => 17 entries
Occurrences => 29 entries

Symbols:
Expand All @@ -3784,6 +3788,7 @@ _empty_/Concrete#nullary3(). => method nullary3 => List[Int] <: _empty_/NullaryT
_empty_/NullaryTest# => abstract class NullaryTest [typeparam T , typeparam m [typeparam s ]] extends Object { self: NullaryTest[T, m] => +9 decls }
_empty_/NullaryTest#[T] => typeparam T
_empty_/NullaryTest#[m] => typeparam m [typeparam s ]
_empty_/NullaryTest#[m][s] => typeparam s
_empty_/NullaryTest#`<init>`(). => primary ctor <init> [typeparam T , typeparam m [typeparam s ]](): NullaryTest[T, m]
_empty_/NullaryTest#`<init>`().[m][s] => typeparam s
_empty_/NullaryTest#nullary(). => method nullary => String
Expand Down

0 comments on commit 91f243c

Please sign in to comment.