gpt4 book ai didi

java - 在 Eclipse 中为 Java try-with-resources 设置括号之间的缩进

转载 作者:行者123 更新时间:2023-11-30 06:59:45 25 4
gpt4 key购买 nike

我喜欢将 Java 的 try-with-resources 格式化如下:

try
(
FileInputStream input = new FileInputStream("data.txt");
BufferedInputStream buffer = new BufferedInputStream(input);
InputStreamReader convert = new InputStreamReader(buffer);
LineNumberReader parse = new LineNumberReader(convert);
)
{
// process the data in the file
}

首先,我用括号之间的插入符号编写以下内容:

try
(|)

然后我按下回车键,Eclipse 将代码格式化为:

try
(
)

右括号在右边9个空格。我的缩进设置设置为使用 3 个空格。如何配置 Eclipse 在按下回车键时执行以下操作?

try
(

)

最佳答案

这由 Java -> 代码样式 -> 格式化程序 -> 换行 -> 换行的默认缩进控制。 (设置为0可以达到想要的效果)

不幸的是,AFAIK 不可能根据上下文设置不同的缩进(即你不能只为 try 设置它,它将用于所有包装)。

查看几个相关问题:
Can the Eclipse formatter be configured to indent multiple lines between parenthesis properly?
Can Eclipse's Java formatter indent wrapped lines differently than new blocks?

关于java - 在 Eclipse 中为 Java try-with-resources 设置括号之间的缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31166752/

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