diff --git a/plugin/src/main/scala/com/typesafe/genjavadoc/AST.scala b/plugin/src/main/scala/com/typesafe/genjavadoc/AST.scala index ba8c15c..ef46f53 100644 --- a/plugin/src/main/scala/com/typesafe/genjavadoc/AST.scala +++ b/plugin/src/main/scala/com/typesafe/genjavadoc/AST.scala @@ -29,17 +29,22 @@ trait AST { this: TransformCake => var firstConstructor: Boolean) extends Templ { def sig: String = { - s""" - |${addAnnotations} - |${pattern(name, access)}""".stripMargin + s"$addAnnotations${pattern(name, access)}" } def file = filepattern(name) - private def addAnnotations: String = sym.annotations - .filter(a => allowedAnnotations.contains(a.symbol.fullName('.'))) - .map { a => s"@${a.symbol.fullName('.')}" } - .mkString(System.lineSeparator()) + private def addAnnotations: String = { + val annotations = sym.annotations + .filter(a => allowedAnnotations.contains(a.symbol.fullName('.'))) + .map { a => s"@${a.symbol.fullName('.')}" } + .mkString(System.lineSeparator()) + if (!annotations.isEmpty) { + annotations + System.lineSeparator() + } else { + annotations + } + } def addMember(t: Templ) = copy(members = members :+ t) @@ -105,16 +110,21 @@ trait AST { this: TransformCake => case class MethodInfo(access: String, pattern: String => String, ret: String, name: String, comment: Seq[String], d: Option[DefDef] = None) extends Templ { def sig: String = { - s""" - |${addAnnotations} - |${pattern(s"$ret $name")}""".stripMargin + s"$addAnnotations${pattern(s"$ret $name")}" } private def addAnnotations: String = d match { - case Some(definition) => definition.symbol.annotations - .filter(a => allowedAnnotations.contains(a.symbol.fullName('.'))) - .map { a => s"@${a.symbol.fullName('.')}" } - .mkString(System.lineSeparator()) + case Some(definition) => { + val annotations = definition.symbol.annotations + .filter(a => allowedAnnotations.contains(a.symbol.fullName('.'))) + .map { a => s"@${a.symbol.fullName('.')}" } + .mkString(System.lineSeparator()) + if (!annotations.isEmpty) { + annotations + System.lineSeparator() + } else { + annotations + } + } case None => "" } } diff --git a/plugin/src/main/scala/com/typesafe/genjavadoc/Plugin.scala b/plugin/src/main/scala/com/typesafe/genjavadoc/Plugin.scala index 6910642..37c7af6 100644 --- a/plugin/src/main/scala/com/typesafe/genjavadoc/Plugin.scala +++ b/plugin/src/main/scala/com/typesafe/genjavadoc/Plugin.scala @@ -53,6 +53,8 @@ class GenJavadocPlugin(val global: Global) extends Plugin { private object MyComponent extends PluginComponent with Transform { + import global._ + type GT = GenJavadocPlugin.this.global.type override val global: GT = GenJavadocPlugin.this.global diff --git a/plugin/src/test/resources/expected_output/basic/akka/WithAnnotation.java b/plugin/src/test/resources/expected_output/basic/akka/WithAnnotation.java new file mode 100644 index 0000000..65bfee6 --- /dev/null +++ b/plugin/src/test/resources/expected_output/basic/akka/WithAnnotation.java @@ -0,0 +1,5 @@ +package akka; +@java.lang.SuppressWarnings +public class WithAnnotation { + public WithAnnotation () { throw new RuntimeException(); } +} diff --git a/plugin/src/test/resources/input/basic/akka/WithAnnotation.scala b/plugin/src/test/resources/input/basic/akka/WithAnnotation.scala new file mode 100644 index 0000000..f783737 --- /dev/null +++ b/plugin/src/test/resources/input/basic/akka/WithAnnotation.scala @@ -0,0 +1,4 @@ +package akka + +@SuppressWarnings(value=Array("")) +class WithAnnotation \ No newline at end of file diff --git a/plugin/src/test/scala/com/typesafe/genjavadoc/BasicSpec.scala b/plugin/src/test/scala/com/typesafe/genjavadoc/BasicSpec.scala index dd1d889..782ed12 100644 --- a/plugin/src/test/scala/com/typesafe/genjavadoc/BasicSpec.scala +++ b/plugin/src/test/scala/com/typesafe/genjavadoc/BasicSpec.scala @@ -13,6 +13,7 @@ object BasicSpec { /** Test basic behaviour of genjavadoc with standard settings */ class BasicSpec extends CompilerSpec { + override def extraSettings: Seq[String] = Seq("annotations=java.lang.SuppressWarnings") override def sources = BasicSpec.sources override def expectedPath: String = { val scalaVersion = scala.util.Properties.versionNumberString.split("-").head