Skip to content

Commit 30f83f7

Browse files
authored
Merge pull request #15361 from dotty-staging/scaladoc/annotations
Scaladoc annotations rework
2 parents 6a4c1fa + 75d2b52 commit 30f83f7

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

scaladoc-testcases/src/tests/annotations.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ import scala.reflect.Enum
88

99
class SomeObject(val s: String)
1010

11-
class MyAnnotation extends StaticAnnotation
11+
@java.lang.annotation.Documented
12+
class MyAnnotation extends StaticAnnotation //expected: @Documented class MyAnnotation extends StaticAnnotation
1213

13-
class AnnotationWithArg(val s: String, val o: SomeObject) extends StaticAnnotation
14+
@java.lang.annotation.Documented
15+
class AnnotationWithArg(val s: String, val o: SomeObject) extends StaticAnnotation //expected: @Documented class AnnotationWithArg(val s: String, val o: SomeObject) extends StaticAnnotation
1416

15-
class AnnotationWithMultiArg(val i: Int, val s: String, val c: Char*) extends StaticAnnotation
17+
@java.lang.annotation.Documented
18+
class AnnotationWithMultiArg(val i: Int, val s: String, val c: Char*) extends StaticAnnotation //expected: @Documented class AnnotationWithMultiArg(val i: Int, val s: String, val c: Char*) extends StaticAnnotation
1619

17-
class EnumAnnotation(val e: Enum) extends StaticAnnotation
20+
@java.lang.annotation.Documented
21+
class EnumAnnotation(val e: Enum) extends StaticAnnotation //expected: @Documented class EnumAnnotation(val e: Enum) extends StaticAnnotation
1822

19-
class ClassAnnotation[T](val c: Class[T]) extends StaticAnnotation
23+
@java.lang.annotation.Documented
24+
class ClassAnnotation[T](val c: Class[T]) extends StaticAnnotation //expected: @Documented class ClassAnnotation[T](val c: Class[T]) extends StaticAnnotation
25+
26+
class NotDocumentedAnnotation extends StaticAnnotation
2027

2128
@AnnotationWithMultiArg(2, "cda", 'a', 'b', 'c') @MyAnnotation class AnnotatedClass
2229

@@ -28,3 +35,5 @@ class AnnotatedMethods
2835
@MyAnnotation @AnnotationWithMultiArg(2, "cda", 'a', 'b', 'c') def a: String
2936
= ???
3037
}
38+
39+
/*<-*/@NotDocumentedAnnotation/*->*/class ClassWithoutAnnotation(/*<-*/@NotDocumentedAnnotation/*->*/val a: String)

scaladoc-testcases/src/tests/specializedSignature.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ package specializedSignature
44

55
import scala.{specialized}
66

7-
trait AdditiveMonoid[@specialized(Int, Long, Float, Double) A]
7+
trait AdditiveMonoid[@specialized(Int, Long, Float, Double) A] //expected: trait AdditiveMonoid[A]
88
{
99
def a: A
1010
= ???
1111

12-
def b[@specialized(Int, Float) B]: B
12+
def b[@specialized(Int, Float) B]: B //expected: def b[B]: B
1313
= ???
14-
}
14+
}

scaladoc/src/dotty/tools/scaladoc/tasty/BasicSupport.scala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,25 @@ trait BasicSupport:
4040
def documentation = parseComment(sym.docstring.getOrElse(""), sym.tree)
4141

4242
def getAnnotations(): List[Annotation] =
43-
sym.annotations.filterNot(_.symbol.packageName.startsWith("scala.annotation.internal")).map(parseAnnotation).reverse
43+
// Custom annotations should be documented only if annotated by @java.lang.annotation.Documented
44+
// We allow also some special cases
45+
val fqNameWhitelist = Set(
46+
"scala.specialized",
47+
"scala.throws",
48+
"scala.transient",
49+
"scala.volatile",
50+
"scala.annotation.experimental",
51+
"scala.annotation.contructorOnly",
52+
"scala.annotation.static",
53+
"scala.annotation.targetName",
54+
"scala.annotation.threadUnsafe",
55+
"scala.annotation.varargs"
56+
)
57+
val documentedSymbol = summon[Quotes].reflect.Symbol.requiredClass("java.lang.annotation.Documented")
58+
val annotations = sym.annotations.filter { a =>
59+
a.tpe.typeSymbol.hasAnnotation(documentedSymbol) || fqNameWhitelist.contains(a.symbol.fullName)
60+
}
61+
annotations.map(parseAnnotation).reverse
4462

4563
def isDeprecated(): Option[Annotation] =
4664
sym.annotations.find { a =>

0 commit comments

Comments
 (0)