Note that there are some explanatory texts on larger screens.

plurals
  1. POEclipse formatter settings for the Builder pattern
    primarykey
    data
    text
    <p>I'm extremely frustrated with the Eclipse formatting rules for a series of qualified invocations (i.e., the Builder pattern style). For example, here is my preferred formatting for some code that creates a new Apache Commons CLI <code>Options</code> object:</p> <pre><code> Options options = new Options() .addOption(OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information") .addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false, "print version and exit") .addOption(OptionBuilder.withLongOpt(OPTION_PROPERTIES) .hasArg() .withArgName("FILE") .withType(File.class) .withDescription("specify a user properties file") .create()); </code></pre> <p>I.e., parameters are wrapped and indented if necessary and all qualified invocations except the first, unless necessary, are wrapped and indented if there is more than one. If a parameter list wraps inside a qualified invocation, the invocation should wrap first.</p> <p>The default formatting in Eclipse ("Wrap only when necessary" for arguments and invocations) yields the following mess:</p> <pre><code> Options options = new Options().addOption( OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information") .addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false, "print version and exit").addOption( OptionBuilder.withLongOpt(OPTION_PROPERTIES).hasArg().withArgName( "FILE").withType(File.class).withDescription( "specify a user properties file").create()); </code></pre> <p>Going into "Java Code Style -> Formatter -> Line Wrapping" and the line wrapping setting to "Wrap all elements, except first element if not necessary" for invocations yields:</p> <pre><code> Options options = new Options().addOption( OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information") .addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false, "print version and exit") .addOption( OptionBuilder.withLongOpt(OPTION_PROPERTIES).hasArg().withArgName( "FILE").withType(File.class).withDescription( "specify a user properties file").create()); </code></pre> <p>I don't like that the <code>OptionBuilder</code> expression isn't being wrapped, or that <code>"FILE"</code> gets wrapped without also wrapping <code>withArgName</code>.</p> <p>Changing the indentation to "Indent on column" yields:</p> <pre><code> Options options = new Options().addOption(OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information") .addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false, "print version and exit") .addOption( OptionBuilder.withLongOpt( OPTION_PROPERTIES) .hasArg() .withArgName("FILE") .withType(File.class) .withDescription( "specify a user properties file") .create()); </code></pre> <p>The is breaking the lines where I'd prefer, but pushing things over much too far to the right.</p> <p>Is there any way to convince Eclipse to apply my preferred formatting style or something closer to it than any of the above?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload