Extract type alias
Type aliases are used to provide alternative names for existing types. With the Extract type alias refactoring, you can easily create new type aliases.
Place the caret at the type you want to extract to an alias and press Ctrl+Alt+Shift+A or select
from the main menu.If there are several expression to choose from, select one from the list that opens and press Enter:
In the dialog that opens, you can specify the a new type alias name or use the name suggested by AppCode:
Select the visibility modifier for the new type alias from the Visibility list.
Click OK.
If AppCode finds any usages of the extracted code in the current file, it will suggest you to replace them with the type alias reference. In the dialog that opens, click Yes to process the duplicates or No to leave the code as it is.
Code example
Before | After |
---|---|
// (Int) -> Boolean will be extracted
fun foo(p: (Int) -> Boolean) = p(42)
fun main() {
val f: (Int) -> Boolean = { it > 0 }
println(foo(f))
val p: (Int) -> Boolean = { it > 0 }
println(listOf(1, -2).filter(p))
}
|
// New type alias added
typealias IntToBoolean = (Int) -> Boolean
// All the occurrences of (Int) -> Boolean
// replaced with IntToBoolean
fun foo(p: IntToBoolean) = p(42)
fun main() {
val f: IntToBoolean = { it > 0 }
println(foo(f))
val p: IntToBoolean = { it > 0 }
println(listOf(1, -2).filter(p))
}
|