You Qi
You Qi

Reputation: 9231

Prevent Elvis Operator from breaking into next line on reformatting

On certain occasions, Android Studio will break elvis operator into the next line when I reformat my code. I couldn't find the option to turn it off in the Code Style settings (or I could have missed them). I personally find it cleaner to have it on the same line.

Any helps would be appreciated.


sealed class ConnectionError(val messageResId: Int, val message: String) : NetworkError() {
            data class ConnectError(val msg: String?) : ConnectionError(R.string.network_connect_exception, msg
                    ?: "")

            data class SocketTimeoutError(val msg: String?) : ConnectionError(R.string.network_sockettimeout_exception, msg
                    ?: "")
}

Upvotes: 0

Views: 397

Answers (1)

Lena Bru
Lena Bru

Reputation: 13947

You need to set the length of the formatted line in android studio:

You see your line is very long. enter image description here

You usually have a code separator line that indicates where the break will happen if needed.

enter image description here

Upvotes: 2

Related Questions