当我运行自动缩进文件时,我可以格式化代码并告诉 Android Studio 不要重新格式化它吗?
例如,我可能想像这样构造我的代码:
returnFragment = when (questionKind) {
QuestionKind.TEXT.int -> GenericTextFragment.newInstance(question, pagerDelegate) //TEXT = 0
QuestionKind.FREE_TEXT.int -> GenericTextFragment.newInstance(question, pagerDelegate) //TEXTAREA = 1
QuestionKind.CHECKBOX.int -> SelectFragment.newInstance(question, pagerDelegate) //CHECKBOX = 2
QuestionKind.RADIO.int -> SelectFragment.newInstance(question, pagerDelegate) //RADIO = 3
QuestionKind.IMAGE.int -> ImagePickerFragment.newInstance(question, pagerDelegate) //FILE = 4
QuestionKind.NUMERICAL.int -> GenericTextFragment.newInstance(question, pagerDelegate) //NUMERICAL = 5
QuestionKind.MULTISELECT.int -> SelectFragment.newInstance(question, pagerDelegate) //MULTISELECT = 6
QuestionKind.SELECT.int -> SelectFragment.newInstance(question, pagerDelegate) //SELECT = 7
else -> GenericFragment.newInstance(question, pagerDelegate) // CUSTOM
}
但是一旦我运行自动缩进(将由 lint 预构建运行),代码就会恢复为
returnFragment = when (questionKind) {
QuestionKind.TEXT.int -> GenericTextFragment.newInstance(question, pagerDelegate) //TEXT = 0
QuestionKind.FREE_TEXT.int -> GenericTextFragment.newInstance(question, pagerDelegate) //TEXTAREA = 1
QuestionKind.CHECKBOX.int -> SelectFragment.newInstance(question, pagerDelegate) //CHECKBOX = 2
QuestionKind.RADIO.int -> SelectFragment.newInstance(question, pagerDelegate) //RADIO = 3
QuestionKind.IMAGE.int -> ImagePickerFragment.newInstance(question, pagerDelegate) //FILE = 4
QuestionKind.NUMERICAL.int -> GenericTextFragment.newInstance(question, pagerDelegate) //NUMERICAL = 5
QuestionKind.MULTISELECT.int -> SelectFragment.newInstance(question, pagerDelegate) //MULTISELECT = 6
QuestionKind.SELECT.int -> SelectFragment.newInstance(question, pagerDelegate) //SELECT = 7
else -> GenericFragment.newInstance(question, pagerDelegate) // CUSTOM
}
它是否更清洁无关紧要。 有没有办法告诉 IDE 忽略预先缩进的代码并只格式化其余代码?
最佳答案
您可以使用以下内容:
// @formatter:off
...
...
<Code for which you want to turn off formatting>
...
...
// @formatter:on
引用https://www.jetbrains.com/help/idea/settings-code-style.html “格式化程序控制”部分了解更多信息。
关于android - 选择要在 Android Studio 中自动缩进忽略的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50248704/