Eclipse代码格式化器缩进使用了双倍空格 - Intellij IDE

4

我已经配置了Eclipse代码格式化程序以使用4个空格缩进,但运行代码格式化程序后,我得到了两倍数量的空格。

enter image description here

当我使用Intellij的标准设置进行缩进时,我会得到正确数量的空格。
Checkstyle规则:
<module name="Indentation">
    <property name="basicOffset" value="4"/>
    <property name="braceAdjustment" value="0"/>
    <property name="caseIndent" value="4"/>
    <property name="throwsIndent" value="4"/>
    <property name="lineWrappingIndentation" value="4"/>
    <property name="arrayInitIndent" value="4"/>
</module>

<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="4"/>

IDE的设置: 在此输入图片描述

运行代码格式化程序后,什么原因会导致缩进大小加倍?


2
因为在我们的团队中有一些开发人员使用Intellij,而另一些则使用Eclipse。我们需要一个可以在两个IDE中使用的代码格式化程序。问题是,Eclipse代码格式化程序的设置没有将缩进更改为4个空格,而是8个空格。这个错误也被checkstyle检测到了。 - Beacze
1
抱歉,如果我在你的团队中,我会正确使用IntelliJ并忽略其他的。 - duffymo
为了让事情变得更加奇怪,Intellij IDE 将这 8 个空格显示为 4 个(第 16 行 - 4 个空格,第 18 行 - 8 个空格)。 - Beacze
最新版本的IntelliJ对我来说并没有这样的功能。我会恢复标准代码风格,删除该格式化程序,然后再试一次。 - duffymo
2
多么无知的回答。如果团队需要相同的代码风格,那么插件是唯一的选择。 - Meo
显示剩余7条评论
1个回答

4

我在使用Eclipse代码格式化程序时,遇到了相同的问题,"continuation indents"(续行缩进)的空格数量从4个变成了8个。我的Eclipse代码格式化文件中有以下几行:

<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>

最后一行的“continuation_indentation”被设置为2,这让我得出结论这可能是2的因素(4 x 2 = 8, 对吧)。我将该值更改为“1”,就可以正常工作了。也许这会有所帮助。
顺便说一句,我的Intellij设置看起来和你的一样 enter image description here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接