@@ -3,7 +3,7 @@ package sbt
3
3
4
4
import ast .{Trees , tpd }
5
5
import core ._ , core .Decorators ._
6
- import Contexts ._ , Flags ._ , Phases ._ , Trees ._ , Types ._ , Symbols ._
6
+ import Annotations . _ , Contexts ._ , Flags ._ , Phases ._ , Trees ._ , Types ._ , Symbols ._
7
7
import Names ._ , NameOps ._ , StdNames ._
8
8
import typer .Inliner
9
9
@@ -333,7 +333,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
333
333
// TODO: Never dealias. We currently have to dealias because
334
334
// sbt main class discovery relies on the signature of the main
335
335
// method being fully dealiased. See https://github.com/sbt/zinc/issues/102
336
- val tp2 = if (! tp.isHK) tp.dealias else tp
336
+ val tp2 = if (! tp.isHK) tp.dealiasKeepAnnots else tp
337
337
tp2 match {
338
338
case NoPrefix | NoType =>
339
339
Constants .emptyType
@@ -411,9 +411,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
411
411
case ConstantType (constant) =>
412
412
new api.Constant (apiType(constant.tpe), constant.stringValue)
413
413
case AnnotatedType (tpe, annot) =>
414
- // TODO: Annotation support
415
- ctx.debuglog(i " sbt-api: skipped annotation in $tp2" )
416
- apiType(tpe)
414
+ new api.Annotated (apiType(tpe), Array (apiAnnotation(annot)))
417
415
case tp : ThisType =>
418
416
apiThis(tp.cls)
419
417
case tp : ParamType =>
@@ -498,7 +496,6 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
498
496
sym.is(Implicit ), sym.is(Lazy ), sym.is(Macro ), sym.is(SuperAccessor ))
499
497
}
500
498
501
- // TODO: Support other annotations
502
499
def apiAnnotations (s : Symbol ): List [api.Annotation ] = {
503
500
val annots = new mutable.ListBuffer [api.Annotation ]
504
501
@@ -513,6 +510,27 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
513
510
annots += marker(Inliner .bodyToInline(s).show(printTypesCtx).toString)
514
511
}
515
512
513
+ // In the Scala2 ExtractAPI phase we only extract annotations that extend
514
+ // StaticAnnotation, but in Dotty we currently pickle all annotations so we
515
+ // extract everything (except inline body annotations which are handled
516
+ // above).
517
+ s.annotations.filter(_.symbol != defn.BodyAnnot ) foreach { annot =>
518
+ annots += apiAnnotation(annot)
519
+ }
520
+
516
521
annots.toList
517
522
}
523
+
524
+ def apiAnnotation (annot : Annotation ): api.Annotation = {
525
+ // FIXME: To faithfully extract an API we should extract the annotation tree,
526
+ // sbt instead wants us to extract the annotation type and its arguments,
527
+ // to do this properly we would need a way to hash trees and types in dotty itself,
528
+ // instead we pretty-print the annotation tree.
529
+ // However, we still need to extract the annotation type in the way sbt expect
530
+ // because sbt uses this information to find tests to run (for example
531
+ // junit tests are annotated @org.junit.Test).
532
+ new api.Annotation (
533
+ apiType(annot.tree.tpe), // Used by sbt to find tests to run
534
+ Array (new api.AnnotationArgument (" FULLTREE" , annot.tree.show.toString)))
535
+ }
518
536
}
0 commit comments