Skip to content

Commit 65c715a

Browse files
committed
visit symbol annotations if not from scala.annotation.internal package
1 parent 889a59c commit 65c715a

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ class Definitions {
739739
@tu lazy val RefiningAnnotationClass: ClassSymbol = ctx.requiredClass("scala.annotation.RefiningAnnotation")
740740

741741
// Annotation classes
742+
@tu lazy val ScalaAnnotationInternal: ClassSymbol = ctx.requiredClass("scala.annotation.internal")
742743
@tu lazy val AliasAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.Alias")
743744
@tu lazy val AnnotationDefaultAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.AnnotationDefault")
744745
@tu lazy val BodyAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.Body")

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ class ExtractSemanticDB extends Phase {
167167

168168
case _ =>
169169

170+
for annot <- tree.symbol.annotations do
171+
if annot.tree.span.exists
172+
&& annot.symbol.owner != defn.ScalaAnnotationInternal
173+
then
174+
traverse(annot.tree)
175+
170176
tree match
171177
case tree: ValDef if tree.symbol.is(Module) => // skip module val
172178
case tree: NamedDefTree
@@ -196,6 +202,8 @@ class ExtractSemanticDB extends Phase {
196202
case tree: Inlined =>
197203
traverse(tree.call)
198204
case tree: PackageDef => tree.stats.foreach(traverse)
205+
case tree: Annotated => // skip the annotation (see `@param` in https://github.com/scalameta/scalameta/blob/633824474e99bbfefe12ad0cc73da1fe064b3e9b/tests/jvm/src/test/resources/example/Annotations.scala#L37)
206+
traverse(tree.arg)
199207
case _ =>
200208
traverseChildren(tree)
201209
}

tests/semanticdb/Annotations.expect.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ 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
8-
class /*=>>java.lang.Object#`<init>`().*/Annotations/*<<=annot.Annotations#*/[@Type/*<<=annot.Annotations#`<init>`().*/ParameterAnnotation T/*<<=annot.Annotations#`<init>`().(T)*//*<<=annot.Annotations#(T)*/](@ParameterAnnotation x/*<<=annot.Annotations#`<init>`().(x)*//*<<=annot.Annotations#(x)*/: T/*=>>annot.Annotations#`<init>`().(T)*/) { self/*<<=local0*/: AnyRef/*=>>scala.AnyRef#*/ =>
9-
@FieldAnnotation
7+
@ClassAnnotation/*=>>com.javacp.annot.ClassAnnotation#*/
8+
class /*=>>java.lang.Object#`<init>`().*/Annotations/*<<=annot.Annotations#*/[@Type/*<<=annot.Annotations#`<init>`().*/ParameterAnnotation/*=>>com.javacp.annot.TypeParameterAnnotation#*/ T/*<<=annot.Annotations#`<init>`().(T)*//*<<=annot.Annotations#(T)*/](@ParameterAnnotation/*=>>com.javacp.annot.ParameterAnnotation#*/ x/*<<=annot.Annotations#`<init>`().(x)*//*<<=annot.Annotations#(x)*/: T/*=>>annot.Annotations#`<init>`().(T)*/) { self/*<<=local0*/: AnyRef/*=>>scala.AnyRef#*/ =>
9+
@FieldAnnotation/*=>>com.javacp.annot.FieldAnnotation#*/
1010
val field/*<<=annot.Annotations#field.*/ = 42
1111

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

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

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

33-
@TraitAnnotation
33+
@TraitAnnotation/*=>>com.javacp.annot.TraitAnnotation#*/
3434
trait T/*<<=annot.T#*/
3535

3636
object /*=>>java.lang.Object#`<init>`().*/Alias/*<<=annot.Alias.*/ {
37-
/*=>>scala.package.Serializable#*//*=>>scala.*//*=>>_root_*//*=>>annot.Alias.*/type A/*<<=annot.Alias.A#*/ = ClassAnnotation/*=>>com.javacp.annot.ClassAnnotation#*/ @param/*=>>scala.annotation.meta.param#*//*=>>scala.annotation.meta.param#`<init>`().*/
37+
/*=>>scala.package.Serializable#*//*=>>scala.*//*=>>_root_*//*=>>annot.Alias.*/type A/*<<=annot.Alias.A#*/ = ClassAnnotation/*=>>com.javacp.annot.ClassAnnotation#*/ @param
3838
}

0 commit comments

Comments
 (0)