July 29, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Improving Code Consistency and Standards Compliance with Eclipse Preferences

  • November 6, 2008
  • 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.
   insert_space_before_comma_in_type_parameters"
   value="do not insert"/>




Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel