Java格式:保留行但修复缩进 [英] Java formatting: Keep lines but fix indentation

查看:48
本文介绍了Java格式:保留行但修复缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

  DSPOTTGuaranteedUserReachForecastModel模型=新的DSPOTTGuaranteedUserReachForecastModel(模拟缓存,要求,mockTargetingDatabaseHelper,programType,地区); 

正确的缩进应为每个不完整的行两个缩进.理想情况下,我想在文本编辑器中设置代码的格式,如下所示:

  DSPOTTGuaranteedUserReachForecastModel模型=新的DSPOTTGuaranteedUserReachForecastModel(模拟缓存,要求,mockTargetingDatabaseHelper,programType,地区); 

但是,当我尝试使用VSCode对其进行格式化时,我会把所有新行折叠成一条长行.

  DSPOTTGuaranteedUserReachForecastModel模型=新的DSPOTTGuaranteedUserReachForecastModel(mockCache,需求,mockTargetingDatabaseHelper,programType,region); 

有人知道保留行号的规则的名称是什么吗?

解决方案

关于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格式:保留行但修复缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆