gpt4 book ai didi

android - 选择要在 Android Studio 中自动缩进忽略的代码

转载 作者:行者123 更新时间:2023-11-29 16:41:59 28 4
gpt4 key购买 nike

当我运行自动缩进文件时,我可以格式化代码并告诉 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com