Select 在 Android Studio 中被自动缩进忽略的代码
Select code to be ignored by auto indent in Android Studio
当我 运行 自动缩进文件时,我可以格式化代码并告诉 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 部分 "Formatter Control"。
当我 运行 自动缩进文件时,我可以格式化代码并告诉 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 部分 "Formatter Control"。