-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-97 Add basic support for passing annotations to the generated Java stubs #171
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
129d7a2
GH-97 Add basic support for passing annotations to generated Java stubs
ilx be7edbb
GH-97 Remove xebialabs specific annotations
ilx 1f6ab9e
GH-97 Bring back import global._, output annotations on same line as …
ilx a2aa9b1
GH-97 Add an example how to invoke plugin from gradle
ilx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,24 @@ trait AST { this: TransformCake => | |
static: Boolean, | ||
var firstConstructor: Boolean) extends Templ { | ||
|
||
def sig = pattern(name, access) | ||
def sig: String = { | ||
s"$addAnnotations${pattern(name, access)}" | ||
} | ||
|
||
def file = filepattern(name) | ||
|
||
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) | ||
|
||
def constructor: Boolean = { | ||
|
@@ -49,7 +64,7 @@ trait AST { this: TransformCake => | |
object ClassInfo { | ||
def apply(c: ImplDef, comment: Seq[String], topLevel: Boolean): ClassInfo = { | ||
c match { | ||
case ClassDef(mods, _, tparams, impl) => | ||
case cd@ClassDef(mods, _, tparams, impl) => | ||
val name = c.name.toString | ||
val acc = access(mods, topLevel) | ||
val fl = flags(mods) | ||
|
@@ -93,9 +108,27 @@ trait AST { this: TransformCake => | |
} | ||
} | ||
|
||
case class MethodInfo(access: String, pattern: String => String, ret: String, name: String, comment: Seq[String]) extends Templ { | ||
def sig = pattern(s"$ret $name") | ||
case class MethodInfo(access: String, pattern: String => String, ret: String, name: String, comment: Seq[String], d: Option[DefDef] = None) extends Templ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might have been nice to only include the annotations here rather than the full |
||
def sig: String = { | ||
s"$addAnnotations${pattern(s"$ret $name")}" | ||
} | ||
|
||
private def addAnnotations: String = d match { | ||
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 | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit simpler might be:
perhaps? |
||
case None => "" | ||
} | ||
} | ||
|
||
object MethodInfo { | ||
def apply(d: DefDef, interface: Boolean, comment: Seq[String], hasVararg: Boolean, deprecation: Option[DeprecationInfo]): MethodInfo = { | ||
val acc = methodAccess(d.symbol, interface) + methodFlags(d.mods, interface) | ||
|
@@ -139,7 +172,7 @@ trait AST { this: TransformCake => | |
case Some(deprec) => deprec.appendToComment(commentWithParams) | ||
case _ => commentWithParams | ||
} | ||
MethodInfo(acc, pattern, ret, name, commentWithParamsAndDeprec) | ||
MethodInfo(acc, pattern, ret, name, commentWithParamsAndDeprec, Some(d)) | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
plugin/src/test/resources/expected_output/basic/akka/WithAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | ||
} |
4 changes: 4 additions & 0 deletions
4
plugin/src/test/resources/input/basic/akka/WithAnnotation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package akka | ||
|
||
@SuppressWarnings(value=Array("")) | ||
class WithAnnotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Could've been a separate PR but 👍 :)