Eclipse - SPLessons

Eclipse Java Automated Formatting

Home > Lesson > Chapter 15
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Eclipse Java Automated Formatting

Eclipse Java Automated Formatting

shape Introduction

This chapter Eclipse Java Automated Formatting demonstrate about the capability of source code formatting in more detail. The Eclipse makes a distinction between formatting and coloring but act as two sides of the same coin. Automated formatting is an excellent feature that formats according to the coding standards. Following are the concepts covered.
  • Java Automated Formatting

Java Automated Formatting

shape Description

Setting colors that affect the code editor are configured in multiple areas but user don’t have to memorize this list and is very easy for eclipse to get created. Setting the non-color related portions of code formatting is done in only one place called Code Style Formatter. In order to look at various coloring options in JDT follow the procedure mentioned. Click on Window menu -> Select Preferences as shown in the image below. Now, a popup window appears known as Preferences providing some options, type colors in the filter box available. Select Colors and Fonts from Appearance under General section. Click on Java from the box available on the left side of the window in order to see the options for editing default java editors for text fonts as shown in the image below. Click Editors section in order to view the settings for editors and there are three levels of settings available in Editors section namely Text Editors, Annotations and Quick Diff as shown in the image below. Clicking the parent one i.e. Text Editor will provide a list of Appearance for various options as shown in the image above. In order to view the language specific settings, click on Java which again contains some levels of settings, click on Syntax Coloring under the Editor setting as shown in the image below. To the left side user can find a box provided with list of Elements for Java, Javadoc and Comments select the preferred element and check the color settings.

Code Style Formatter

shape Description

In order to deal with Code Style Formatter, go to the Window menu and click Preferences and type format in the Filter box. Now, select the Formatter option under the Java section as shown in the image below. Select active profile from the drop-down box or create new profile using the New button as indicated in the image. A popup window appears known as New Profile by Clicking the New button, provide a profile name in the name box and select Eclipse [built-in] from the drop down box and Click OK button as shown in the image below. Now, a new Code Style Formatter dialog opens with the given profile name provided with a series of tabs as follows. All this tabs work reasonably similarly, user can make changes on the left and the preview can be seen on the right for the given changes. Generally the preview pane consist of an option to show or hide invisible characters as shown in the image below.

Summary

shape Key Points

  • Automated formatting is an excellent feature which formats according to the coding standards.
  • Coloring and formatting in Eclipse act quite similar.
  • User can create the new Profile for making own Code Style Formatter.
  • User can change the color appearance for editor text font.