January 25, 2021
Hot Topics:

Improving Code Consistency and Standards Compliance with Eclipse Preferences

  • By Scott Nelson
  • Send Email »
  • More Articles »

The menus are very intuitive, so if you already have coding standards written you should be able to configure the profile in less than an hour. Of course, if you don't, now is the perfect time to establish them. When you have completed each section, click Apply to save it to your profile.

Once your profile is completed, many aspects will take immediate effect, such as the formatting of braces when using wizard-generated code such as getters and setters. Other options, such as Align fields in columns, require using the Source\Format option from the menu.

Click here for a larger image.

Figure 4: Source\Format Option

This option can also be used on code written before the creation of the profile to quickly format using your profile.

Click here for a larger image.

Figure 5: Before: Old, Unformatted Code

Click here for a larger image.

Figure 6: After: Standardized Formatting in an Instant

Once you have your formatting profile defined, you can export it from the Formatter Edit menu.

Click here for a larger image.

Figure 7: Exporting Custom Format Profile

This XML file can be imported into a team member's installations from the initial Formatter dialog screen. For the curious, below is an example of the exported XML (which can be edited by hand for those who prefer that approach):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="11">
<profile kind="CodeFormatterProfile" name="Scott" version="11">
<setting id="org.eclipse.jdt.core.formatter.
   comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.
   insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.
   value="do not insert"/>

Page 2 of 3

This article was originally published on November 6, 2008

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date