Skip to content

Commit 69f3d60

Browse files
committed
exclude use occurrences of annotation constructors
1 parent d774f5a commit 69f3d60

File tree

6 files changed

+23
-34
lines changed

6 files changed

+23
-34
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class ExtractSemanticDB extends Phase with
9797
/** Uses of this symbol where the reference has given span should be excluded from semanticdb */
9898
private def excludeUse(qualifier: Option[Symbol], sym: Symbol)(given Context): Boolean =
9999
excludeDefOrUse(sym)
100+
|| sym.isConstructor && sym.owner.isAnnotation
100101
|| sym == defn.Any_typeCast
101102
|| qualifier.exists(excludeQual)
102103

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ object Scala3 with
123123
def isSyntheticWithIdent(given Context): Boolean =
124124
sym.is(Synthetic) && !sym.isAnonymous && !sym.name.isEmptyNumbered
125125

126+
def isAnnotation(given Context): Boolean =
127+
sym.derivesFrom(defn.AnnotationClass)
128+
126129
end SymbolOps
127130

128131
object LocalSymbol with

tests/semanticdb/expect/Annotations.expect.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@ import com.javacp.annot._
44
import scala.annotation.meta._
55
import scala.language/*->scalaShadowing::language.*/.experimental/*->scalaShadowing::language.experimental.*/.macros/*->scalaShadowing::language.experimental.macros.*/
66

7-
@ClassAnnotation/*->com::javacp::annot::ClassAnnotation#*//*->com::javacp::annot::ClassAnnotation#`<init>`().*/
8-
class Annotations/*<-annot::Annotations#*/[@TypeParameterAnnotation/*->com::javacp::annot::TypeParameterAnnotation#*//*->com::javacp::annot::TypeParameterAnnotation#`<init>`().*/ T/*<-annot::Annotations#[T]*/](@ParameterAnnotation/*->com::javacp::annot::ParameterAnnotation#*//*->com::javacp::annot::ParameterAnnotation#`<init>`().*/ x/*<-annot::Annotations#x.*/: T/*->annot::Annotations#[T]*/) { self/*<-local0*/: AnyRef/*->scala::AnyRef#*/ =>
9-
@FieldAnnotation/*->com::javacp::annot::FieldAnnotation#*//*->com::javacp::annot::FieldAnnotation#`<init>`().*/
7+
@ClassAnnotation/*->com::javacp::annot::ClassAnnotation#*/
8+
class Annotations/*<-annot::Annotations#*/[@TypeParameterAnnotation/*->com::javacp::annot::TypeParameterAnnotation#*/ T/*<-annot::Annotations#[T]*/](@ParameterAnnotation/*->com::javacp::annot::ParameterAnnotation#*/ x/*<-annot::Annotations#x.*/: T/*->annot::Annotations#[T]*/) { self/*<-local0*/: AnyRef/*->scala::AnyRef#*/ =>
9+
@FieldAnnotation/*->com::javacp::annot::FieldAnnotation#*/
1010
val field/*<-annot::Annotations#field.*/ = 42
1111

12-
@MethodAnnotation/*->com::javacp::annot::MethodAnnotation#*//*->com::javacp::annot::MethodAnnotation#`<init>`().*/
12+
@MethodAnnotation/*->com::javacp::annot::MethodAnnotation#*/
1313
def method/*<-annot::Annotations#method().*/ = {
14-
@LocalAnnotation/*->com::javacp::annot::LocalAnnotation#*//*->com::javacp::annot::LocalAnnotation#`<init>`().*/
14+
@LocalAnnotation/*->com::javacp::annot::LocalAnnotation#*/
1515
val local/*<-local1*/ = 42
1616
local/*->local1*/
1717
}
18-
@TypeAnnotation/*->com::javacp::annot::TypeAnnotation#*//*->com::javacp::annot::TypeAnnotation#`<init>`().*/
18+
@TypeAnnotation/*->com::javacp::annot::TypeAnnotation#*/
1919
type S/*<-annot::Annotations#S#*/
2020
}
2121

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

27-
@ObjectAnnotation/*->com::javacp::annot::ObjectAnnotation#*//*->com::javacp::annot::ObjectAnnotation#`<init>`().*/
27+
@ObjectAnnotation/*->com::javacp::annot::ObjectAnnotation#*/
2828
object M/*<-annot::M.*/ {
29-
@MacroAnnotation/*->com::javacp::annot::MacroAnnotation#*//*->com::javacp::annot::MacroAnnotation#`<init>`().*/
29+
@MacroAnnotation/*->com::javacp::annot::MacroAnnotation#*/
3030
def m/*<-annot::M.m().*/[TT/*<-annot::M.m().[TT]*/]: Int/*->scala::Int#*//*->scala::Predef.`???`().*/ = macro ???
3131
}
3232

33-
@TraitAnnotation/*->com::javacp::annot::TraitAnnotation#*//*->com::javacp::annot::TraitAnnotation#`<init>`().*/
33+
@TraitAnnotation/*->com::javacp::annot::TraitAnnotation#*/
3434
trait T/*<-annot::T#*/
3535

3636
object Alias/*<-annot::Alias.*/ {

tests/semanticdb/expect/Flags.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package object p {
2020
final class Y/*<-flags::p::package.Y#*/
2121
sealed trait Z/*<-flags::p::package.Z#*/
2222
class AA/*<-flags::p::package.AA#*/(x/*<-flags::p::package.AA#x.*/: Int/*->scala::Int#*/, val y/*<-flags::p::package.AA#y.*/: Int/*->scala::Int#*/, var z/*<-flags::p::package.AA#z().*/: Int/*->scala::Int#*/)
23-
class S/*<-flags::p::package.S#*/[@specialized/*->scala::specialized#*//*->scala::specialized#`<init>`(+2).*/ T/*<-flags::p::package.S#[T]*/]
23+
class S/*<-flags::p::package.S#*/[@specialized/*->scala::specialized#*/ T/*<-flags::p::package.S#[T]*/]
2424
val List/*->scala::package.List.*//*->scala::collection::SeqFactory#unapplySeq().*/(xs1/*<-flags::p::package.xs1.*//*<-local0*/)/*->local0*/ = ???/*->scala::Predef.`???`().*/
2525
???/*->scala::Predef.`???`().*/ match { case List/*->scala::package.List.*//*->scala::collection::SeqFactory#unapplySeq().*/(xs2/*<-local1*/) => ???/*->scala::Predef.`???`().*/ }
2626
???/*->scala::Predef.`???`().*/ match { case _: List/*->scala::package.List#*/[t/*<-local2*/] => ???/*->scala::Predef.`???`().*/ }

tests/semanticdb/expect/Types.expect.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package types
33
import scala.language/*->scalaShadowing::language.*/.existentials/*->scalaShadowing::language.existentials.*/
44
import scala.language/*->scalaShadowing::language.*/.higherKinds/*->scalaShadowing::language.higherKinds.*/
55

6-
class ann/*<-types::ann#*//*->scala::annotation::Annotation#`<init>`().*/[T/*<-types::ann#[T]*/](x/*<-types::ann#x.*/: T/*->types::ann#[T]*/) extends scala.annotation.StaticAnnotation/*->scala::annotation::StaticAnnotation#*/
7-
class ann1/*<-types::ann1#*//*->scala::annotation::Annotation#`<init>`().*/ extends scala.annotation.StaticAnnotation/*->scala::annotation::StaticAnnotation#*/
8-
class ann2/*<-types::ann2#*//*->scala::annotation::Annotation#`<init>`().*/ extends scala.annotation.StaticAnnotation/*->scala::annotation::StaticAnnotation#*/
6+
class ann/*<-types::ann#*/[T/*<-types::ann#[T]*/](x/*<-types::ann#x.*/: T/*->types::ann#[T]*/) extends scala.annotation.StaticAnnotation/*->scala::annotation::StaticAnnotation#*/
7+
class ann1/*<-types::ann1#*/ extends scala.annotation.StaticAnnotation/*->scala::annotation::StaticAnnotation#*/
8+
class ann2/*<-types::ann2#*/ extends scala.annotation.StaticAnnotation/*->scala::annotation::StaticAnnotation#*/
99

1010
class B/*<-types::B#*/
1111

tests/semanticdb/metac.expect

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Uri => Annotations.scala
193193
Text => empty
194194
Language => Scala
195195
Symbols => 22 entries
196-
Occurrences => 63 entries
196+
Occurrences => 51 entries
197197

198198
Symbols:
199199
annot/Alias. => final object Alias
@@ -232,53 +232,41 @@ Occurrences:
232232
[4:22..4:34): experimental -> scalaShadowing/language.experimental.
233233
[4:35..4:41): macros -> scalaShadowing/language.experimental.macros.
234234
[6:1..6:16): ClassAnnotation -> com/javacp/annot/ClassAnnotation#
235-
[6:16..6:16): -> com/javacp/annot/ClassAnnotation#`<init>`().
236235
[7:6..7:17): Annotations <- annot/Annotations#
237236
[7:17..7:72): <- annot/Annotations#`<init>`().
238237
[7:19..7:42): TypeParameterAnnotation -> com/javacp/annot/TypeParameterAnnotation#
239-
[7:42..7:42): -> com/javacp/annot/TypeParameterAnnotation#`<init>`().
240238
[7:43..7:44): T <- annot/Annotations#[T]
241239
[7:47..7:66): ParameterAnnotation -> com/javacp/annot/ParameterAnnotation#
242-
[7:66..7:66): -> com/javacp/annot/ParameterAnnotation#`<init>`().
243240
[7:67..7:68): x <- annot/Annotations#x.
244241
[7:70..7:71): T -> annot/Annotations#[T]
245242
[7:75..7:79): self <- local0
246243
[7:81..7:87): AnyRef -> scala/AnyRef#
247244
[8:3..8:18): FieldAnnotation -> com/javacp/annot/FieldAnnotation#
248-
[8:18..8:18): -> com/javacp/annot/FieldAnnotation#`<init>`().
249245
[9:6..9:11): field <- annot/Annotations#field.
250246
[11:3..11:19): MethodAnnotation -> com/javacp/annot/MethodAnnotation#
251-
[11:19..11:19): -> com/javacp/annot/MethodAnnotation#`<init>`().
252247
[12:6..12:12): method <- annot/Annotations#method().
253248
[13:5..13:20): LocalAnnotation -> com/javacp/annot/LocalAnnotation#
254-
[13:20..13:20): -> com/javacp/annot/LocalAnnotation#`<init>`().
255249
[14:8..14:13): local <- local1
256250
[15:4..15:9): local -> local1
257251
[17:3..17:17): TypeAnnotation -> com/javacp/annot/TypeAnnotation#
258-
[17:17..17:17): -> com/javacp/annot/TypeAnnotation#`<init>`().
259252
[18:7..18:8): S <- annot/Annotations#S#
260253
[21:6..21:7): B <- annot/B#
261254
[21:7..21:40): <- annot/B#`<init>`().
262255
[21:9..21:30): ConstructorAnnotation -> com/javacp/annot/ConstructorAnnotation#
263-
[21:30..21:30): -> com/javacp/annot/ConstructorAnnotation#`<init>`().
264256
[21:33..21:34): x <- annot/B#x.
265257
[21:36..21:39): Int -> scala/Int#
266258
[22:3..22:24): ConstructorAnnotation -> com/javacp/annot/ConstructorAnnotation#
267-
[22:24..22:24): -> com/javacp/annot/ConstructorAnnotation#`<init>`().
268259
[23:6..23:12): <- annot/B#`<init>`(+1).
269260
[23:20..23:20): -> annot/B#`<init>`().
270261
[26:1..26:17): ObjectAnnotation -> com/javacp/annot/ObjectAnnotation#
271-
[26:17..26:17): -> com/javacp/annot/ObjectAnnotation#`<init>`().
272262
[27:7..27:8): M <- annot/M.
273263
[28:3..28:18): MacroAnnotation -> com/javacp/annot/MacroAnnotation#
274-
[28:18..28:18): -> com/javacp/annot/MacroAnnotation#`<init>`().
275264
[29:6..29:7): m <- annot/M.m().
276265
[29:8..29:10): TT <- annot/M.m().[TT]
277266
[29:13..29:16): Int -> scala/Int#
278267
[29:16..29:16): -> scala/Predef.`???`().
279268
[32:0..32:0): <- annot/T#`<init>`().
280269
[32:1..32:16): TraitAnnotation -> com/javacp/annot/TraitAnnotation#
281-
[32:16..32:16): -> com/javacp/annot/TraitAnnotation#`<init>`().
282270
[33:6..33:7): T <- annot/T#
283271
[35:7..35:12): Alias <- annot/Alias.
284272
[36:7..36:8): A <- annot/Alias.A#
@@ -1022,7 +1010,7 @@ Uri => Flags.scala
10221010
Text => empty
10231011
Language => Scala
10241012
Symbols => 51 entries
1025-
Occurrences => 85 entries
1013+
Occurrences => 84 entries
10261014

10271015
Symbols:
10281016
flags/p/package. => final package object p
@@ -1146,7 +1134,6 @@ Occurrences:
11461134
[22:8..22:9): S <- flags/p/package.S#
11471135
[22:9..22:25): <- flags/p/package.S#`<init>`().
11481136
[22:11..22:22): specialized -> scala/specialized#
1149-
[22:22..22:22): -> scala/specialized#`<init>`(+2).
11501137
[22:23..22:24): T <- flags/p/package.S#[T]
11511138
[23:6..23:10): List -> scala/package.List.
11521139
[23:10..23:10): -> scala/collection/SeqFactory#unapplySeq().
@@ -2732,7 +2719,7 @@ Uri => Types.scala
27322719
Text => empty
27332720
Language => Scala
27342721
Symbols => 125 entries
2735-
Occurrences => 246 entries
2722+
Occurrences => 243 entries
27362723

27372724
Symbols:
27382725
local0 => abstract method k
@@ -2870,7 +2857,6 @@ Occurrences:
28702857
[3:13..3:21): language -> scalaShadowing/language.
28712858
[3:22..3:33): higherKinds -> scalaShadowing/language.higherKinds.
28722859
[5:6..5:9): ann <- types/ann#
2873-
[5:6..5:6): -> scala/annotation/Annotation#`<init>`().
28742860
[5:9..5:18): <- types/ann#`<init>`().
28752861
[5:10..5:11): T <- types/ann#[T]
28762862
[5:13..5:14): x <- types/ann#x.
@@ -2879,13 +2865,11 @@ Occurrences:
28792865
[5:33..5:43): annotation -> scala/annotation/
28802866
[5:44..5:60): StaticAnnotation -> scala/annotation/StaticAnnotation#
28812867
[6:6..6:10): ann1 <- types/ann1#
2882-
[6:6..6:6): -> scala/annotation/Annotation#`<init>`().
28832868
[6:19..6:19): <- types/ann1#`<init>`().
28842869
[6:19..6:24): scala -> scala/
28852870
[6:25..6:35): annotation -> scala/annotation/
28862871
[6:36..6:52): StaticAnnotation -> scala/annotation/StaticAnnotation#
28872872
[7:6..7:10): ann2 <- types/ann2#
2888-
[7:6..7:6): -> scala/annotation/Annotation#`<init>`().
28892873
[7:19..7:19): <- types/ann2#`<init>`().
28902874
[7:19..7:24): scala -> scala/
28912875
[7:25..7:35): annotation -> scala/annotation/
@@ -3573,3 +3557,4 @@ Occurrences:
35733557
[2:46..2:47): z -> _empty_/toplevel$package.combine(+1).(z)
35743558
[3:4..3:11): combine <- _empty_/toplevel$package.combine(+2).
35753559
[4:4..4:7): foo <- _empty_/toplevel$package.foo().
3560+

0 commit comments

Comments
 (0)