Skip to content

Commit

Permalink
Add occurrences of secondary constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishiking committed Jul 28, 2021
1 parent 6529e8f commit ba8140f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
11 changes: 9 additions & 2 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,15 @@ class ExtractSemanticDB extends Phase:
if content.lift(span.end - 1).map(_ == '`').getOrElse(false) then
(span.start + 1, span.end - 1)
else (span.start, span.end)
val target = if sym.isPackageObject then sym.owner else sym
content.slice(start, end).mkString == target.name.stripModuleClassSuffix.lastPart.toString
val nameInSource = content.slice(start, end).mkString
// for secondary constructors `this`
if sym.isConstructor && nameInSource == nme.THISkw.toString then
true
else
val target =
if sym.isPackageObject then sym.owner
else sym
nameInSource == target.name.stripModuleClassSuffix.lastPart.toString

private def spanOfSymbol(sym: Symbol, span: Span, treeSource: SourceFile)(using Context): Span =
val contents = if treeSource.exists then treeSource.content() else Array.empty[Char]
Expand Down
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/Annotations.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Annotations/*<-annot::Annotations#*/[@TypeParameterAnnotation/*->com::java

class B/*<-annot::B#*/ @ConstructorAnnotation/*->com::javacp::annot::ConstructorAnnotation#*/()(x/*<-annot::B#x.*/: Int/*->scala::Int#*/) {
@ConstructorAnnotation/*->com::javacp::annot::ConstructorAnnotation#*/
def this() = this(42)
def this/*<-annot::B#`<init>`(+1).*/() = this(42)
}

@ObjectAnnotation/*->com::javacp::annot::ObjectAnnotation#*/
Expand Down
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/EndMarkers.expect.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package endmarkers:

class MultiCtor/*<-endmarkers::MultiCtor#*/(val i/*<-endmarkers::MultiCtor#i.*/: Int/*->scala::Int#*/):
def this() =
def this/*<-endmarkers::MultiCtor#`<init>`(+1).*/() =
this(23)
end this
end this/*->endmarkers::MultiCtor#`<init>`(+1).*/
end MultiCtor/*->endmarkers::MultiCtor#*/

def topLevelMethod/*<-endmarkers::EndMarkers$package.topLevelMethod().*/: String/*->scala::Predef.String#*/ =
Expand Down
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/semanticdb-Flags.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package object p/*<-flags::p::package.*/ {
def z/*<-flags::p::package.z().*/(pp/*<-flags::p::package.z().(pp)*/: Int/*->scala::Int#*/) = 3
def m/*<-flags::p::package.m().*/[TT/*<-flags::p::package.m().[TT]*/]: Int/*->scala::Int#*/ = macro ???/*->scala::Predef.`???`().*/
abstract class C/*<-flags::p::package.C#*/[+T/*<-flags::p::package.C#[T]*/, -U/*<-flags::p::package.C#[U]*/, V/*<-flags::p::package.C#[V]*/](x/*<-flags::p::package.C#x.*/: T/*->flags::p::package.C#[T]*/, y/*<-flags::p::package.C#y.*/: U/*->flags::p::package.C#[U]*/, z/*<-flags::p::package.C#z.*/: V/*->flags::p::package.C#[V]*/) {
def this() = this(???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
def this(t/*<-flags::p::package.C#`<init>`(+2).(t)*/: T/*->flags::p::package.C#[T]*/) = this(t/*->flags::p::package.C#`<init>`(+2).(t)*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
def this/*<-flags::p::package.C#`<init>`(+1).*/() = this(???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
def this/*<-flags::p::package.C#`<init>`(+2).*/(t/*<-flags::p::package.C#`<init>`(+2).(t)*/: T/*->flags::p::package.C#[T]*/) = this(t/*->flags::p::package.C#`<init>`(+2).(t)*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
def w/*<-flags::p::package.C#w().*/: Int/*->scala::Int#*/
}
type T1/*<-flags::p::package.T1#*/ = Int/*->scala::Int#*/
Expand Down
11 changes: 8 additions & 3 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Uri => Annotations.scala
Text => empty
Language => Scala
Symbols => 22 entries
Occurrences => 47 entries
Occurrences => 48 entries

Symbols:
annot/Alias. => final object Alias extends Object { self: Alias.type => +2 decls }
Expand Down Expand Up @@ -271,6 +271,7 @@ Occurrences:
[21:33..21:34): x <- annot/B#x.
[21:36..21:39): Int -> scala/Int#
[22:3..22:24): ConstructorAnnotation -> com/javacp/annot/ConstructorAnnotation#
[23:6..23:10): <- annot/B#`<init>`(+1).
[26:1..26:17): ObjectAnnotation -> com/javacp/annot/ObjectAnnotation#
[27:7..27:8): M <- annot/M.
[28:3..28:18): MacroAnnotation -> com/javacp/annot/MacroAnnotation#
Expand Down Expand Up @@ -660,7 +661,7 @@ Uri => EndMarkers.scala
Text => empty
Language => Scala
Symbols => 24 entries
Occurrences => 35 entries
Occurrences => 37 entries

Symbols:
endmarkers/Container# => class Container extends Object { self: Container => +5 decls }
Expand Down Expand Up @@ -693,6 +694,8 @@ Occurrences:
[2:8..2:17): MultiCtor <- endmarkers/MultiCtor#
[2:22..2:23): i <- endmarkers/MultiCtor#i.
[2:25..2:28): Int -> scala/Int#
[3:8..3:12): <- endmarkers/MultiCtor#`<init>`(+1).
[5:8..5:12): this -> endmarkers/MultiCtor#`<init>`(+1).
[6:6..6:15): MultiCtor -> endmarkers/MultiCtor#
[8:6..8:20): topLevelMethod <- endmarkers/EndMarkers$package.topLevelMethod().
[8:22..8:28): String -> scala/Predef.String#
Expand Down Expand Up @@ -3881,7 +3884,7 @@ Uri => semanticdb-Flags.scala
Text => empty
Language => Scala
Symbols => 50 entries
Occurrences => 71 entries
Occurrences => 73 entries

Symbols:
flags/p/package. => final package object p extends Object { self: p.type => +23 decls }
Expand Down Expand Up @@ -3963,9 +3966,11 @@ Occurrences:
[9:39..9:40): U -> flags/p/package.C#[U]
[9:42..9:43): z <- flags/p/package.C#z.
[9:45..9:46): V -> flags/p/package.C#[V]
[10:8..10:12): <- flags/p/package.C#`<init>`(+1).
[10:22..10:25): ??? -> scala/Predef.`???`().
[10:27..10:30): ??? -> scala/Predef.`???`().
[10:32..10:35): ??? -> scala/Predef.`???`().
[11:8..11:12): <- flags/p/package.C#`<init>`(+2).
[11:13..11:14): t <- flags/p/package.C#`<init>`(+2).(t)
[11:16..11:17): T -> flags/p/package.C#[T]
[11:26..11:27): t -> flags/p/package.C#`<init>`(+2).(t)
Expand Down

0 comments on commit ba8140f

Please sign in to comment.