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 格式化:保留行但修复缩进


- 如何使用WebFilter实现授权头检查 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01