Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Groovy State of the Union — GR8Conf Europe 2015

Groovy State of the Union — GR8Conf Europe 2015

Guillaume Laforge

June 03, 2015
Tweet

More Decks by Guillaume Laforge

Other Decks in Technology

Transcript

  1. 15 Groovy 2.4 — Android support • Write your Android

    applications fully in Groovy! • Dedicated Gradle plugin
  2. 15 Groovy 2.4 — Android support • Write your Android

    applications fully in Groovy! • Dedicated Gradle plugin
  3. 17 Groovy 2.4 — Performance & bytecode • Improved bytecode

    • cheaper comparison operations • optimization of primitive type coercions with ‘as’ • Reduced bytecode size • no MOP generated methods in static context • uneeded inner class distributor methods when no inner • timestamp removal • Reduced memory consumption
  4. 18 Groovy 2.4 — Traits @SelfType class Component {
 void

    doSomething() {
 println "Done!"
 }
 }
  5. 18 Groovy 2.4 — Traits @SelfType class Component {
 void

    doSomething() {
 println "Done!"
 }
 } import groovy.transform.* 
 @SelfType(Component)
 @TypeChecked
 trait ComponentDecorator {
 void logAndDoSomething() {
 println "Going to do something"
 doSomething()
 }
 }
  6. 18 Groovy 2.4 — Traits @SelfType class Component {
 void

    doSomething() {
 println "Done!"
 }
 } import groovy.transform.* 
 @SelfType(Component)
 @TypeChecked
 trait ComponentDecorator {
 void logAndDoSomething() {
 println "Going to do something"
 doSomething()
 }
 } class ConcreteComponent
 extends Component
 implements ComponentDecorator {}
 
 def c = new ConcreteComponent()
 c.logAndDoSomething()
  7. 19 Groovy 2.4 — GDK improvements • New methods •

    System.currentTimeSeconds() • List: removeAt(index), getIndices() • Collection: removeElement(Object) • Iterable: disjoin(), size(), dropRight(), takeRight() • More collection methods moved to iterator-based • Favor stream-like traversal methods leveraging iterables • Consistency for mutation in place vs new collection creation
  8. 20 Groovy 2.4 — AST transformations • @ToString added includeSuperProperties

    parameter • Can define compilation phase for @ASTTest • @Synchronized supports explicit static locks used by instance methods if needed • Cleaned-up code for @AutoExternalizable and @EqualsAndHashCode when used with @CompileStatic • Improved Java integration for @Builder • @PackageScope allowed on constructors
  9. 21 Groovy 2.4 — Groovysh improvements • Custom .rc and

    .profile scripts • instanceof completion • Static members completion only in a static context • Completion candidates in color • :set interpreterMode to remember locally-defined variables • :load command supports file names with spaces • Align arguments & flags with the groovy command • Script launch on startup & continue execution of Groovysh • Easier to subclass Groovysh for embedded reuse
  10. 29 Incubation — mentors • Emmanuel Lécharny • Bertrand Delacrétaz

    • Roman Shaposhnik • Jim Jagielski • Andrew Bayer
  11. 30 Incubation — initial committers • Paul King • Cédric

    Champeau • Pascal Schumacher • Jochen Theodorou • Guillaume Laforge
  12. 31 Incubation — infrastructure • Mailing-lists created • please don’t

    use the old ones! • JIRA issues imported • Sources moved to Apache’s Git • with a mirror on Github Please Star it!
  13. 32 Incubation — new committers • Officially joined the project

    as committer • Andrés Almiray • To be announced soon too! • Dierk König • Russel Winder
  14. 33 Incubation — next steps • The next key step

    is make a first release! • following the Apache guidelines
  15. 35 @Canonical becomes a meta-annotation import groovy.transform.*
 
 @Canonical(includeNames =

    true)
 class Person {
 String name
 int age
 }
 
 assert new Person('Guillaume', 37).toString() ==
 'Person(name:Guillaume, age:37)'
  16. 35 @Canonical becomes a meta-annotation import groovy.transform.*
 
 @Canonical(includeNames =

    true)
 class Person {
 String name
 int age
 }
 
 assert new Person('Guillaume', 37).toString() ==
 'Person(name:Guillaume, age:37)' includeNames from @ToString
  17. 36 More control on annotation collector DUPLICATE Annotations from the

    annotation collection will always be inserted. PREFER_COLLECTOR Annotations from the collector will be added and any existing annotations with the same name will be removed. PREFER_EXPLICIT Annotations from the collector will be ignored if any existing annotations with the same name are found. PREFER_EXPLICIT_MERGED Annotations from the collector will be ignored if any existing annotations with the same name are found but any new parameters on the collector annotation will be added to existing annotations. PREFER_COLLECTOR_MERGED Annotations from the collector will be added and any existing annotations with the same name will be removed but any new parameters found within existing annotations will be merged into the added annotation.
  18. 37 New @MapConstructor transformation import groovy.transform.*
 
 @TupleConstructor
 class Person

    {
 String first, last
 }
 
 @CompileStatic // optional
 @ToString(includeSuperProperties = true)
 @MapConstructor(pre = { super(args?.first, args?.last);
 args = args ?: [:] },
 post = { first = first?.toUpperCase() })
 class Author extends Person {
 String bookName
 } assert new Author(first: 'Dierk', last: 'Koenig', bookName: 'ReGinA').toString() == 'Author(ReGinA, DIERK, Koenig)'
 
 assert new Author().toString() == 'Author(null, null, null)'
  19. 37 New @MapConstructor transformation import groovy.transform.*
 
 @TupleConstructor
 class Person

    {
 String first, last
 }
 
 @CompileStatic // optional
 @ToString(includeSuperProperties = true)
 @MapConstructor(pre = { super(args?.first, args?.last);
 args = args ?: [:] },
 post = { first = first?.toUpperCase() })
 class Author extends Person {
 String bookName
 } assert new Author(first: 'Dierk', last: 'Koenig', bookName: 'ReGinA').toString() == 'Author(ReGinA, DIERK, Koenig)'
 
 assert new Author().toString() == 'Author(null, null, null)' Can decorate map ctor with pre / post- instructions
  20. 38 Properties validated in AST xforms import groovy.transform.AutoClone
 
 @AutoClone(excludes

    = 'sirName')
 class Person {
 String firstName
 String surName
 }
 
 new Person(firstName: "John", surName: "Doe").clone()
  21. 38 Properties validated in AST xforms import groovy.transform.AutoClone
 
 @AutoClone(excludes

    = 'sirName')
 class Person {
 String firstName
 String surName
 }
 
 new Person(firstName: "John", surName: "Doe").clone() Error during @AutoClone processing: 'excludes' property 'sirName' does not exist.
  22. 39 Prevent @TupleConstructor default ctors @TupleConstructor
 class Person {
 String

    first, last
 int age
 } Generates: Person(String first, String last, int age) { /*...*/ } Person(String first, String last) { this(first, last, 0) } Person(String first) { this(first, null) } Person() { this(null) }
  23. 40 Prevent @TupleConstructor default ctors @TupleConstructor(defaults = true)
 class Person

    { String first, last
 int age
 } Generates only: Person(String first, String last, int age) { /*...*/ }
  24. 41 @Immutable support in class hierarchy import groovy.transform.*
 
 @EqualsAndHashCode


    class Person {
 String name
 } @Immutable
 @TupleConstructor(includeSuperProperties = true)
 @EqualsAndHashCode(callSuper = true)
 @ToString(includeNames = true, includeSuperProperties = true)
 class Athlete extends Person {
 String sport
 }
  25. 41 @Immutable support in class hierarchy import groovy.transform.*
 
 @EqualsAndHashCode


    class Person {
 String name
 } @Immutable
 @TupleConstructor(includeSuperProperties = true)
 @EqualsAndHashCode(callSuper = true)
 @ToString(includeNames = true, includeSuperProperties = true)
 class Athlete extends Person {
 String sport
 } def d1 = new Athlete('Michael Jordan', 'BasketBall')
 def d2 = new Athlete(name: 'Roger Rederer', sport: ‘Tennis') assert d1 != d2
 assert d1.toString() == 
 'Athlete(sport:BasketBall, name:Michael Jordan)'
 assert d2.toString() == 
 'Athlete(sport:Tennis, name:Roger Rederer)'
  26. 42 Miscellaneous • GDK’s createSimilarCollection() and createSimilarMap() methods support all

    the JDK’s collections and maps • Improve compiler performance with an ASM class reader instead of using a class loader • New File#relativePath(file) method