blob: caaee43927e63bcac16904dc011c81fa2b40a8f8 [file] [log] [blame]
[[Android]]
== Android Support
With Groovy 2.4, you can write Android applications in Groovy!
A quick link:{DOCS_BASEURL}/html/documentation/tools-groovyc.html#section-android[getting
started guide] is available on the Groovy website.
To build your Android applications with the Groovy support, youll be
able to use
the link:https://github.com/groovy/groovy-android-gradle-plugin[Gradle Groovy Android plugin].
The link:https://github.com/Arasthel/SwissKnife[SwissKnife] library builds
upon the Groovy support to offer very useful AST transformations that
kill the usual Android boilerplate code, for instance for dealing with
UI events, with logic to be run in background threads, or make objects
easily "parcelables", etc.
To further understand the new Android support, you can read the
following articles by Cédric Champeau:
* Introduction: link:http://melix.github.io/blog/2014/06/grooid.html[http://melix.github.io/blog/2014/06/grooid.html]
* Technical details: link:http://melix.github.io/blog/2014/06/grooid2.html[http://melix.github.io/blog/2014/06/grooid2.html]
And discover presentations on the Android support:
* link:https://speakerdeck.com/melix/groovy-and-android-a-winning-pair-1[Groovy and Android, a winning pair] by Cédric Champeau
* link:https://speakerdeck.com/glaforge/groovy-on-android-groovy-grails-exchange-2014[Groovy on Android] by Guillaume Laforge
The work on the Android support also lead to various optimizations in
terms of bytecode generation, as explained further down, as well as, for
instance, improving the handling of overloaded setters
(link:https://issues.apache.org/jira/browse/GROOVY-2049[GROOVY-2049],link:https://issues.apache.org/jira/browse/GROOVY-6084[GROOVY-6084],
link:https://issues.apache.org/jira/browse/GROOVY-2500[GROOVY-2500])
which are frequent in the Android SDK.
[[Groovy2.4releasenotes-Performanceimprovementsandreducedbytecode]]
== Performance improvements and reduced bytecode
This new major release of Groovy has seen various improvements across
the board to reduce the quantity of bytecode produced, to lower memory
consumption of internal data structures, fine tune bytecode for better
performance.
Here are some of the tickets related to the topic:
* Cheaper comparison operations
(link:https://issues.apache.org/jira/browse/GROOVY-7194[GROOVY-7194])
* Reduced memory consumption for `respondsTo()`
(link:https://issues.apache.org/jira/browse/GROOVY-7178[GROOVY-7178])
* For fully statically compiled classes, MOP related generated methods
are not needed
(link:https://issues.apache.org/jira/browse/GROOVY-6990[GROOVY-6990])
* Remove unneeded inner class distributor methods when no inner classes
are present (link:https://issues.apache.org/jira/browse/GROOVY-6993[GROOVY-6993])
* Removal of the timestamp in Groovy classes
(link:https://issues.apache.org/jira/browse/GROOVY-6308[GROOVY-6308])
* Optimization of primitive type conversions with the as operator
(link:https://issues.apache.org/jira/browse/GROOVY-7140[GROOVY-7140])
[[Groovy2.4releasenotes-TraitsSelfTypeannotation]]
== Traits @SelfType annotation
Sometimes, its desired to be able to restrict a traits application so
that it can only be applied to subclasses of a certain type. Thats what
the `@SelfType` annotation is for
(link:https://issues.apache.org/jira/browse/GROOVY-7134[GROOVY-7134]).
Heres a concrete example of `@SelfType` in action.
[source,groovy]
----
import groovy.transform.*
class Component {
void doSomething() {
println "Done!"
}
}
@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()
----
The `ComponentDecorator` trait is calling the `doSomething()` method from
the `Component` sub-class to which it will be applied. If you dont
specify the `@SelfType(Component)` annotation, when using static type
checking or static compilation, the compiler will throw a compilation
error as it wouldnt know where the `doSomething()` method would be coming
from. With the annotation, you instruct the compiler to figure out that
this trait will only be applied to child of Component that will have
that method available. `@SelfType` is interesting in the context of static
type checking or compilation, but is not needed if your code is dynamic
as the resolution will take place at runtime as usual.
[[Groovy2.4releasenotes-GDKimprovements]]
== GDK improvements
* `System.currentTimeSeconds()` to get the current time in seconds
(link:https://issues.apache.org/jira/browse/GROOVY-6294[GROOVY-6294])
* `List#getIndices()` to get a range representing the indices of the
elements of the list
(link:https://issues.apache.org/jira/browse/GROOVY-7171[GROOVY-7171])
* More collection related methods are moved to iterator-based variants
to apply to all iterable collection types
(link:https://issues.apache.org/jira/browse/GROOVY-6863[GROOVY-6863]) and missing
methods have been added like `init()`, `dropRight()`, `takeRight()`
(link:https://issues.apache.org/jira/browse/GROOVY-6867[GROOVY-6867])
* `Iterable` gets `disjoin()`, `minus()` and `toSpreadMap()` methods
(link:https://issues.apache.org/jira/browse/GROOVY-6920[GROOVY-6920])
* Refinements and concistency for existing collection methods,
leveraging iterable approaches for stream-like traversals, consistency
for mutation in place vs  new collection creation, minor optimizations,
etc. (link:https://issues.apache.org/jira/browse/GROOVY-6945[GROOVY-6945])
* New `List#removeAt(index)` and `Collection#removeElement(Object)` methods
(link:https://issues.apache.org/jira/browse/GROOVY-6952[GROOVY-6952])
* `Iterable` gets a `size()` method like iterators
(link:https://issues.apache.org/jira/browse/GROOVY-7085[GROOVY-7085])
[[Groovy2.4releasenotes-ASTtransformations]]
== AST transformations
* The `@ToString` transformation offers an `includeSuperProperties`
parameter so properties from the super class are also present in the
string representation
(link:https://issues.apache.org/jira/browse/GROOVY-7161[GROOVY-7161])
* You can define the compilation phase for the `@ASTTest` transformation
for testing your AST transformations
(link:https://issues.apache.org/jira/browse/GROOVY-6968[GROOVY-6968])
* `@Synchronized` supports explicit static locks to be used by instance
methods if needed
(link:https://issues.apache.org/jira/browse/GROOVY-7030[GROOVY-7030])
* Clean up generated code for `@AutoExternalizable`
(link:https://issues.apache.org/jira/browse/GROOVY-6889[GROOVY-6889]) and
`@EqualsAndHashCode`
(link:https://issues.apache.org/jira/browse/GROOVY-6893[GROOVY-6893]) the when
using `@CompileStatic`
* `@Builder`s default and initializer strategies improved Java
integration (link:https://issues.apache.org/jira/browse/GROOVY-6875[GROOVY-6875])
* `@PackageScope` allowed on constructors too
(link:https://issues.apache.org/jira/browse/GROOVY-6839[GROOVY-6839])
[[Groovy2.4releasenotes-Groovyshimprovements]]
== Groovysh improvements
The venerable Groovysh shell continues seeing some useful improvements:
* Groovysh supports custom .rc and .profile scripts to be loaded on
startup (link:https://issues.apache.org/jira/browse/GROOVY-6943[GROOVY-6943])
* completion of instanceof statements
(link:https://issues.apache.org/jira/browse/GROOVY-7200[GROOVY-7200])
* completion of static members only displayed in a static context
(link:https://issues.apache.org/jira/browse/GROOVY-6622[GROOVY-6622])
* completion candidates in color
(link:https://issues.apache.org/jira/browse/GROOVY-6563[GROOVY-6563])
* with :set interpreterMode true, you can let Groovysh to let you see
and use locally-defined variables after further line executions
(link:https://issues.apache.org/jira/browse/GROOVY-6623[GROOVY-6623])
* the :load command supports file names containing spaces
(link:https://issues.apache.org/jira/browse/GROOVY-6942[GROOVY-6942])
* make arguments and flags consistent with the groovy command and allow
the launch of a script on startup passed as argument and continue
execution of Groovysh
(link:https://issues.apache.org/jira/browse/GROOVY-6754[GROOVY-6754])
* make it easier to subclass Groovysh for reuse as an embedded shell
(link:https://issues.apache.org/jira/browse/GROOVY-6752[GROOVY-6752])
[[Groovy2.4releasenotes-Miscellaneous]]
== Miscellaneous
* Allow Ant targets declaration by AntBuilder without immediate
execution (link:https://issues.apache.org/jira/browse/GROOVY-2900[GROOVY-2900])
* Make `NamespaceBuilder` automatically detect namespace declarations
(link:https://issues.apache.org/jira/browse/GROOVY-6890[GROOVY-6890])
* Implement and register type checking extensions as subclasses of
`TypeCheckingExtension`
(link:https://issues.apache.org/jira/browse/GROOVY-6739[GROOVY-6739])
* `ConfigObject` overrides `toString()` and offers a `prettyPrint()` method
(link:https://issues.apache.org/jira/browse/GROOVY-7183[GROOVY-7183])
* Improved type checking for certain GDK methods
(link:https://issues.apache.org/jira/browse/GROOVY-6966[GROOVY-6966])
* Grape is using JCenter through HTTP first for resolving dependencies,
and now HTTPS is used for better security
(link:https://issues.apache.org/jira/browse/GROOVY-7152[GROOVY-7152])
* Parameters of `@DelegatesTo` and `@ClosureParams` are better aligned
(link:https://issues.apache.org/jira/browse/GROOVY-6956[GROOVY-6956])
* Multiple labels are supported on the same statement
(link:https://issues.apache.org/jira/browse/GROOVY-3298[GROOVY-3298])
[[Groovy2.4releasenotes-Breakingchanges]]
== Breaking changes
A few issues fixed might also be considered breaking changes in some
situations:
* Malformed class names for closures in inner classes
(link:https://issues.apache.org/jira/browse/GROOVY-5351[GROOVY-5351])
* Avoid creation of MOP methods in static compilation
(link:https://issues.apache.org/jira/browse/GROOVY-6990[GROOVY-6990])
* Reduce memory consumption for respondsTo()
(link:https://issues.apache.org/jira/browse/GROOVY-7178[GROOVY-7178])
* Making Groovysh more easily extendable and embeddable
(link:https://issues.apache.org/jira/browse/GROOVY-6752[GROOVY-6752])
[[Groovy2.4releasenotes-Moreinformation]]
== More information
You can browse all the link:../changelogs/changelog-2.4.0.html[tickets closed for Groovy 2.4 in JIRA].