includeGenerated()).
Example usage:
import groovy.transform.NullCheck
import static groovy.test.GroovyAssert.shouldFail
@NullCheck
class Greeter {
private String audience
Greeter(String audience) {
this.audience = audience.toLowerCase()
}
String greeting(String salutation) {
salutation.toUpperCase() + ' ' + audience
}
}
assert new Greeter('World').greeting('hello') == 'HELLO world'
def ex = shouldFail(IllegalArgumentException) { new Greeter(null) }
assert ex.message == 'audience cannot be null'
ex = shouldFail(IllegalArgumentException) { new Greeter('Universe').greeting(null) }
assert ex.message == 'salutation cannot be null'
The produced code for the above example looks like this:
class Greeter {
private String audience
Foo(String audience) {
if (audience == null) throw new IllegalArgumentException('audience cannot be null')
this.audience = audience.toLowerCase()
}
String greeting(String salutation) {
if (salutation == null) throw new IllegalArgumentException('salutation cannot be null')
salutation.toUpperCase() + ' ' + audience
}
}
| Modifier and Type | Method and Description |
|---|---|
| public boolean | includeGenerated()
Whether to try to add null checking to generated methods/constructors such as those added by other transforms. |
| includeGenerated | back to summary |
|---|---|
| public boolean includeGenerated() Whether to try to add null checking to generated methods/constructors such as those added by other transforms.
Using this option may lead to surprising results, e.g. it will only apply to methods/constructors added prior
to when the
| |