![](/img/trans.png)
[英]How to configure code Formatter in Eclipse to add new line after each element in enum?
[英]Configure enum constants on its own line using Eclipse Code Formatter
我將Spotless與 Gradle 一起使用。我已將其配置為使用 Eclipse 的 JDT 代碼格式化程序:
spotless {
groovyGradle {
greclipse("4.21.0").configFile("${rootDir}/config/spotless/eclipe_groovy_formatter.xml")
}
java {
eclipse("4.21.0").configFile("${rootDir}/config/spotless/eclipe_jdt_formatter.xml")
endWithNewline()
importOrder("", "javax", "java")
indentWithSpaces(2)
lineEndings(LineEnding.UNIX)
removeUnusedImports()
trimTrailingWhitespace()
}
}
eclipe_jdt_formatter.xml
的內容就是:
<?xml version="1.0" encoding="UTF-8" ?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="Fulgore Team" version="12">
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="80" />
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="false" />
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert" />
</profile>
</profiles>
問題是我想在 (Eclipse) XML 文件中配置正確的設置,以便每個enum
值都在自己的行中。
例如,這是它當前格式化源代碼的方式:
public enum Type {
VALUE, OTHER, ANOTHER,
}
...但我想:
public enum Type {
VALUE,
OTHER,
ANOTHER,
}
如果有人知道我可以在 XML 文件中使用的設置組合來完成此操作,我將非常感激。 我已經嘗試了.formatter
和/或.indent
的幾種組合,但沒有成功。
試試<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="49"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.