Home > Software design >  Configure enum constants on its own line using Eclipse Code Formatter
Configure enum constants on its own line using Eclipse Code Formatter

Time:03-09

I'm using Spotless with Gradle. I've configured it to use Eclipse's JDT Code Formatter:

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()
  }
}

The content of eclipe_jdt_formatter.xml is just:

<?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>

The problem is that I would like to configure the correct setting(s) within the (Eclipse) XML file in order to have the enum values each on its own line.

For instance, this is how it's currently formatting the source code:

public enum Type {
  VALUE, OTHER, ANOTHER,
}

...but I would like:

public enum Type {
  VALUE,
  OTHER,
  ANOTHER,
}

If anyone knows the combination of settings I can use within the XML file to accomplish this I would really appreciate it. I've tried a couple of combinations from .formatter and/or .indent without luck.

CodePudding user response:

Try <setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="49"/>

  • Related