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 |
---|---|---|---|
| Wraps an expression in a function call. |
fun foo(s: String) {
s.arg
}
|
fun foo(s: String) {
call(s)
}
|
| Wraps an expression in an arrayOf() call. |
fun foo(s: String) {
val x = s.arrayOf
}
|
fun foo(s: String) {
val x = arrayOf(s)
}
|
| Creates an assertion from a boolean expression. |
fun foo(x: Boolean) {
x.assert
}
|
fun foo(x: Boolean) {
assert(x) { "" }
}
|
| Adds a check verifying that a boolean expression is false. |
fun foo(x: Boolean) {
x.else
}
|
fun foo(x: Boolean) {
if (!x) {
}
}
|
| Creates for statement from given iterable expression |
fun foo(list: List<String>) {
list.for
}
|
fun foo(list: List<String>) {
for (s in list) {
}
}
|
| Creates for statement from a given number |
fun foo() {
10.fori
}
|
fun foo() {
for (i in 0 until 10) {
}
}
|
| 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()) {
}
}
|
| Creates inverted for statement from a given number |
fun foo() {
10.forr
}
|
fun foo(list: List<String>) {
for (i in 10 downTo 0) {
}
}
|
| 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()) {
}
}
|
| Adds a check verifying that a boolean expression is true. |
fun foo(x: Boolean) {
x.if
}
|
fun foo(x: Boolean) {
if (x) {
}
}
|
| Creates for statement from given iterable expression |
fun foo(list: List<String>) {
list.iter
}
|
fun foo(list: List<String>) {
for (s in list) {
}
}
|
| Wraps an expression in a listOf() call. |
fun foo(s: String) {
val x = s.listOf
}
|
fun foo(s: String) {
val x = listOf(s)
}
|
| Adds a check verifying that an expression is not null. |
fun foo(x: Any?) {
x.nn
}
|
fun foo(x: Any?) {
if (x != null) {
}
}
|
| Negates an expression. |
fun foo(x: Boolean) {
if (x.not) {
}
}
|
fun foo(x: Boolean) {
if (!x) {
}
}
|
| Adds a check verifying that an expression is not null. |
fun foo(x: Any?) {
x.notnull
}
|
fun foo(x: Any?) {
if (x != null) {
}
}
|
| Adds a check verifying that an expression is null. |
fun foo(x: Any?) {
x.null
}
|
fun foo(x: Any?) {
if (x == null) {
}
}
|
| Parenthesizes an expression. |
fun foo(x: Any) {
x.par
}
|
fun foo(x: Any) {
(x)
}
|
| Inserts a return statement. |
fun foo(x: Any): Any {
x.return
}
|
fun foo(x: Any): Any {
return x
}
|
| Wraps an expression in a sequenceOf() call. |
fun foo(s: String) {
val x = s.sequenceOf
}
|
fun foo(s: String) {
val x = sequenceOf(s)
}
|
| Wraps an expression in a setOf() call. |
fun foo(s: String) {
val x = s.setOf
}
|
fun foo(s: String) {
val x = setOf(s)
}
|
| Wraps an expression in a println() call. |
fun foo(x: Any) {
x.sout
}
|
fun foo(x: Any) {
println(x)
}
|
| 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) {}
|
| Surrounds an expression with a try-catch block. |
fun foo(x: Any?) {
x.try
}
|
fun foo(x: Any?) {
try {
x
} catch (e: Exception) {
}
}
|
| Creates a variable from a given expression. |
fun bar() = 1
fun foo() {
bar().val
}
|
fun bar() = 1
fun foo() {
val bar = bar()
}
|
| Creates a variable from a given expression. |
fun bar() = 1
fun foo() {
bar().var
}
|
fun bar() = 1
fun foo() {
val bar = bar()
}
|
| Wraps an expression in a when statement. |
fun foo(x: String) {
x.when
}
|
fun foo(x: String) {
when (x) {
}
}
|
| Creates a while statement from a boolean expression. |
fun foo(x: Boolean) {
x.while
}
|
fun foo(x: Boolean) {
while(x) {
}
}
|
| Wraps an expression in 'with()'. |
fun foo(x: String) {
x.with
}
|
fun foo(x: String) {
with(x) {
}
}
|