JetBrains Fleet 1.33 Help

List of Kotlin postfix completion templates

This table summarizes the postfix completion templates that you can use with your Kotlin code.

Name

Description

Example. Before

Example. After

arg

Wraps an expression in a function call.

fun foo(s: String) { s.arg }
fun foo(s: String) { call(s) }

arrayOf

Wraps an expression in an arrayOf() call.

fun foo(s: String) { val x = s.arrayOf }
fun foo(s: String) { val x = arrayOf(s) }

assert

Creates an assertion from a boolean expression.

fun foo(x: Boolean) { x.assert }
fun foo(x: Boolean) { assert(x) { "" } }

else

Adds a check verifying that a boolean expression is false.

fun foo(x: Boolean) { x.else }
fun foo(x: Boolean) { if (!x) { } }

for

Creates for statement from given iterable expression

fun foo(list: List<String>) { list.for }
fun foo(list: List<String>) { for (s in list) { } }

fori

Creates for statement from a given number

fun foo() { 10.fori }
fun foo() { for (i in 0 until 10) { } }

fori

Creates for indexed statement from given iterable expression

fun foo(list: List<String>) { list.fori }
fun foo(list: List<String>) { for ((index, s) in list.withIndex()) { } }

forr

Creates inverted for statement from a given number

fun foo() { 10.forr }
fun foo(list: List<String>) { for (i in 10 downTo 0) { } }

forr

Creates reversed for statement from given iterable expression

fun foo(list: List<String>) { list.forr }
fun foo(list: List<String>) { for (s in list.reversed()) { } }

if

Adds a check verifying that a boolean expression is true.

fun foo(x: Boolean) { x.if }
fun foo(x: Boolean) { if (x) { } }

iter

Creates for statement from given iterable expression

fun foo(list: List<String>) { list.iter }
fun foo(list: List<String>) { for (s in list) { } }

listOf

Wraps an expression in a listOf() call.

fun foo(s: String) { val x = s.listOf }
fun foo(s: String) { val x = listOf(s) }

nn

Adds a check verifying that an expression is not null.

fun foo(x: Any?) { x.nn }
fun foo(x: Any?) { if (x != null) { } }

not

Negates an expression.

fun foo(x: Boolean) { if (x.not) { } }
fun foo(x: Boolean) { if (!x) { } }

notnull

Adds a check verifying that an expression is not null.

fun foo(x: Any?) { x.notnull }
fun foo(x: Any?) { if (x != null) { } }

null

Adds a check verifying that an expression is null.

fun foo(x: Any?) { x.null }
fun foo(x: Any?) { if (x == null) { } }

par

Parenthesizes an expression.

fun foo(x: Any) { x.par }
fun foo(x: Any) { (x) }

return

Inserts a return statement.

fun foo(x: Any): Any { x.return }
fun foo(x: Any): Any { return x }

sequenceOf

Wraps an expression in a sequenceOf() call.

fun foo(s: String) { val x = s.sequenceOf }
fun foo(s: String) { val x = sequenceOf(s) }

setOf

Wraps an expression in a setOf() call.

fun foo(s: String) { val x = s.setOf }
fun foo(s: String) { val x = setOf(s) }

sout

Wraps an expression in a println() call.

fun foo(x: Any) { x.sout }
fun foo(x: Any) { println(x) }

spread

Adds the * spread operator to a call.

fun foo(list: List<String>) { bar(list.toTypedArray().spread) } fun bar(vararg args: String) {}
fun foo(list: List<String>) { bar(*list.toTypedArray()) } fun bar(vararg args: String) {}

try

Surrounds an expression with a try-catch block.

fun foo(x: Any?) { x.try }
fun foo(x: Any?) { try { x } catch (e: Exception) { } }

val

Creates a variable from a given expression.

fun bar() = 1 fun foo() { bar().val }
fun bar() = 1 fun foo() { val bar = bar() }

var

Creates a variable from a given expression.

fun bar() = 1 fun foo() { bar().var }
fun bar() = 1 fun foo() { val bar = bar() }

when

Wraps an expression in a when statement.

fun foo(x: String) { x.when }
fun foo(x: String) { when (x) { } }

while

Creates a while statement from a boolean expression.

fun foo(x: Boolean) { x.while }
fun foo(x: Boolean) { while(x) { } }

with

Wraps an expression in 'with()'.

fun foo(x: String) { x.with }
fun foo(x: String) { with(x) { } }
Last modified: 15 April 2024