[英]Select code to be ignored by auto indent in Android Studio
Can i format code and tell Android Studio not to reformat it when i run auto indent file? 运行自动缩进文件时,我可以格式化代码并告诉Android Studio不要重新格式化吗?
For example, i might want to structure my code like this: 例如,我可能想像这样构造我的代码:
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
}
But as soon as I run auto indent (which will be run by lint pre build) the code reverts back to 但是,一旦我运行自动缩进(将由lint pre build运行),代码就会恢复为
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
}
Whether it's cleaner or not is irrelevant. 是否更干净无关紧要。 Is there a way to tell the IDE to ignore pre-indented code and only format the rest? 有没有一种方法可以告诉IDE忽略预缩进的代码,而只格式化其余的代码?
You can use following: 您可以使用以下内容:
// @formatter:off
...
...
<Code for which you want to turn off formatting>
...
...
// @formatter:on
refer to https://www.jetbrains.com/help/idea/settings-code-style.html section "Formatter Control" for more information. 有关更多信息,请参阅https://www.jetbrains.com/help/idea/settings-code-style.html部分“格式化程序控件”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.