Java formatting: Keep lines but fix indentation(Java 格式化:保留行但修复缩进)
问题描述
我有以下代码:
DSPOTTGuaranteedUserReachForecastModel 模型 = 新的 DSPOTTGuaranteedUserReachForecastModel(模拟缓存,要求,mockTargetingDatabaseHelper,程序类型,地区);
正确的缩进应该是每个不完整行的两个缩进.理想情况下,我希望我的文本编辑器像这样格式化我的代码:
DSPOTTGuaranteedUserReachForecastModel 模型 = 新的 DSPOTTGuaranteedUserReachForecastModel(模拟缓存,要求,mockTargetingDatabaseHelper,程序类型,地区);
但是,当我尝试使用 VSCode 对其进行格式化时,我将所有新行合并成一个长行.
DSPOTTGuaranteedUserReachForecastModel 模型 = 新的 DSPOTTGuaranteedUserReachForecastModel(mockCache, 需求,mockTargetingDatabaseHelper,programType,区域);
有谁知道保留行号的规则的名称是什么?
关于java格式化,
I have the following code:
DSPOTTGuaranteedUserReachForecastModel model = new DSPOTTGuaranteedUserReachForecastModel(
mockCache,
demand,
mockTargetingDatabaseHelper,
programType,
region);
The correct indentation should be two indents for each incomplete line. Ideally I would want to my text editor to format my code as such:
DSPOTTGuaranteedUserReachForecastModel model = new DSPOTTGuaranteedUserReachForecastModel(
mockCache,
demand,
mockTargetingDatabaseHelper,
programType,
region);
However, when I try to format it using VSCode, I am getting all the new lines collapsing into one long line instead.
DSPOTTGuaranteedUserReachForecastModel model = new DSPOTTGuaranteedUserReachForecastModel(mockCache, demand,
mockTargetingDatabaseHelper, programType, region);
Does anyone know what is the name of the rule for preserving line numbers?
About java formatting, VSCode-Java provides an Eclipse formatter file like Google Style.
The setting you wanted should be something like java_method_parameters_wrap = split_into_lines
, but unfortunately it's not included in GoogleStyle.xml.
If you're still interested in java formatting, you may figure it out in DefaultCodeFormatterOptions.
[EDIT]
Download googlestyle.xml and edit the following settings:
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="1" />
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
Then in vscode settings.json, set
"java.format.settings.url": "<local path to java-google-style.xml>",
You can get the formatting style that you want:
这篇关于Java 格式化:保留行但修复缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java 格式化:保留行但修复缩进
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01