Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p><table class="wysiwyg-macro" data-macro-name="excerpt" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2V4Y2VycHQ6YXRsYXNzaWFuLW1hY3JvLW91dHB1dC10eXBlPUJMT0NLfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Provides integration with the <a href="http://scala-lang.org">Scala Programming language</a></p></td></tr></table></p> <h3>Description</h3> <p>@Scalify simplifies the task of integrating Groovy and Scala code. This transformation adds the required bytecode to your Groovy classes to make them appear as native Scala classes. It also helps when implementing or extending a Scala trait/class from Groovy.</p> <h3>Usage</h3> <p>Place @Scalify at the class level, example;</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> // -- begin scala code import scala.reflect.BeanProperty trait Output { @BeanProperty var output: String } // -- end Scala code // -- begin Groovy code import groovyx.transform.Scalify @Scalify class GroovyOutput implements Output { String output } </pre></td></tr></table> <p>When the trait Output is compiled it will generate bytecode similar to</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> public interface Output { public abstract void setOutput(java.lang.String); public abstract java.lang.String getOutput(); public abstract void output_$eq(java.lang.String); public abstract java.lang.String output(); } </pre></td></tr></table> <p>The first pair of methods is your typical POJO accessors (generated by Scala's @BeanProperty) which Groovy can handle quite well. The second pair of methods represent Scala's <em>native</em> accessors, these will be written by @Scalify (if not present already in your class definition). Additionally @Scalify will make sure that your class implements <code>scala.ScalaObject</code> if it does not already.</p> <p>One last trick up the sleeve is that @Scalify will generate operator friendly methods, these are the currently supported methods:</p> <table class="confluenceTable"><tbody> <tr> <th class="confluenceTh"><p>Operator</p></th> <th class="confluenceTh"><p> Groovy </p></th> <th class="confluenceTh"><p> Scala </p></th> </tr> <tr> <td class="confluenceTd"><p>+ </p></td> <td class="confluenceTd"><p>plus() </p></td> <td class="confluenceTd"><p>$plus()</p></td> </tr> <tr> <td class="confluenceTd"><p>- </p></td> <td class="confluenceTd"><p>minus() </p></td> <td class="confluenceTd"><p>$minus()</p></td> </tr> <tr> <td class="confluenceTd"><p>* </p></td> <td class="confluenceTd"><p>multiply() </p></td> <td class="confluenceTd"><p>$times()</p></td> </tr> <tr> <td class="confluenceTd"><p>/ </p></td> <td class="confluenceTd"><p>div() </p></td> <td class="confluenceTd"><p>$div()</p></td> </tr> <tr> <td class="confluenceTd"><p>% </p></td> <td class="confluenceTd"><p>mod() </p></td> <td class="confluenceTd"><p>$percent()</p></td> </tr> <tr> <td class="confluenceTd"><p>^ </p></td> <td class="confluenceTd"><p>xor() </p></td> <td class="confluenceTd"><p>$up()</p></td> </tr> <tr> <td class="confluenceTd"><p>& </p></td> <td class="confluenceTd"><p>and() </p></td> <td class="confluenceTd"><p>$amp()</p></td> </tr> <tr> <td class="confluenceTd"><p>| </p></td> <td class="confluenceTd"><p>or() </p></td> <td class="confluenceTd"><p>$bar()</p></td> </tr> <tr> <td class="confluenceTd"><p>** </p></td> <td class="confluenceTd"><p>power() </p></td> <td class="confluenceTd"><p>$times$times()</p></td> </tr> <tr> <td class="confluenceTd"><p><< </p></td> <td class="confluenceTd"><p>leftShift() </p></td> <td class="confluenceTd"><p>$less$less()</p></td> </tr> <tr> <td class="confluenceTd"><p>>> </p></td> <td class="confluenceTd"><p>rightShift() </p></td> <td class="confluenceTd"><p>$greater$greater()</p></td> </tr> <tr> <td class="confluenceTd"><p>- </p></td> <td class="confluenceTd"><p>negative() </p></td> <td class="confluenceTd"><p>unary_$minus()</p></td> </tr> <tr> <td class="confluenceTd"><p>+ </p></td> <td class="confluenceTd"><p>positive() </p></td> <td class="confluenceTd"><p>unary_$plus()</p></td> </tr> <tr> <td class="confluenceTd"><p>~ </p></td> <td class="confluenceTd"><p>bitwiseNegate() </p></td> <td class="confluenceTd"><p>unary_$tilde()</p></td> </tr> </tbody></table> <table class="wysiwyg-macro" data-macro-name="warning" data-macro-parameters="title=Full compatibility" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3dhcm5pbmc6dGl0bGU9RnVsbCBjb21wYXRpYmlsaXR5fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"> <p>While @Scalify can generate all the require boilerplate code it cannot (at the moment) generate a required class attribute (called pickle) that the Scala compiler uses to gather metadata information about a Scala class. This means you won't be able to call a property setter using the short notation, in other words </p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>new GroovyOutput().output = "something"</pre></td></tr></table> <p> will result in a compilation error while the following will work </p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>new GroovyOutput().output_$eq("something")</pre></td></tr></table></td></tr></table> <h3>Dependencies</h3> <p>Make sure to have the Scala compiler & libraries on your classpath. You will also need <code>asm</code>, grab the latest version available with your Groovy distribution</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced