IntelliJ IDEA Community Edition has a nice feature called intentions. Intentions offer a way to simplify our code. In our editor we can select an intention with Alt+Enter and IntelliJ IDEA shows a popup with available intensions. Let's take a look at some useful intentions when developing Groovy code.
def s = "Simple test ${obj.ide}"
def s = "Simple test $obj.ide"
|
def output = s != null ? s : ''
def output = s ?: ''
|
def list = [ 'a' , 'b' , 'c' ]
for (c in list) {
println c.toUpperCase()
}
def list = [ 'a' , 'b' , 'c' ]
list. each { c ->
println c.toUpperCase()
}
|
def c = list.getAt( 0 )
def c = list[ 0 ]
|
def printObj(date, text, list) {
println "" "
Print on $date $text and list has size ${list. size ()}
"" "
}
def printObj(params) {
println "" "
Print on $params.date $params.text and list has size ${params.list. size ()}
"" "
}
|
list. contains ( 'd' )
list. contains 'b'
|
class User { String name }
def u = new User()
u.setName( 'mrhaki' )
class User { String name }
def u = new User()
u.name = 'mrhaki'
|
def s = 'Simple test with ' + obj.ide
def s = "Simple test with $obj.ide"
|