Skip to content

Commit

Permalink
lightbendGH-97 Bring back import global._, output annotations on same…
Browse files Browse the repository at this point in the history
… line as Java class stubs and write a simple test that demonstrates how to create Java stub with some annotation
  • Loading branch information
ilx committed Apr 23, 2019
1 parent be7edbb commit 1f6ab9e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
38 changes: 24 additions & 14 deletions plugin/src/main/scala/com/typesafe/genjavadoc/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 => ""
}
}
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/main/scala/com/typesafe/genjavadoc/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package akka;
@java.lang.SuppressWarnings
public class WithAnnotation {
public WithAnnotation () { throw new RuntimeException(); }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package akka

@SuppressWarnings(value=Array(""))
class WithAnnotation
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f6ab9e

Please sign in to comment.