I'm searching for a refactoring in Android Studio ...
# android-studio
t
I'm searching for a refactoring in Android Studio that I loved in the original Refactoring Browser in the Smalltalk world. I'm curious if I'm just holding the IDE wrong, or it's not possible. Given the following statement:
Copy code
MaterialTheme.typography.bodyMedium.copy(color = (backgroundColor.luminance() > 0.5).opt(Color._TextDark, Color.White))
I'd like to be able to select the
.copy(...)
half and "extract method" so I ended up with a new function:
Copy code
fun TextStyle.coloredFor(backgroundColor:Color)  = this.copy(color = (backgroundColor.luminance() > 0.5).opt(Color._TextDark, Color.White))
and the original rewritten as:
Copy code
MaterialTheme.typography.bodyMedium.coloredFor(backgroundColor)
I have tried selecting different parts and tried different refactoring menu options, but none some to have the ability to infer the receiver as the target of the extracted behavior.
b
• Select the whole expression • Extract to method (cmd option m) • On the extracted method, move your cursor to the parameter, and alt-enter • "Convert parameter to receiver"
👆 1