JMU JMU - Department of Computer Science
Help Tools
Lab: Skills - Eclipse Formatters


Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.

Getting Ready: Before going any further, you should:

  1. Setup your development environment.
  2. Download the following files:
    to an appropriate directory/folder. (In most browsers/OSs, the easiest way to do this is by right-clicking/control-clicking on each of the links above.)
  3. If you are unfamiliar with XML and/or Checkstyle, you should read the following documents.
  4. If you don't already have one from earlier in the semester, create a project named eclipseskills.
  5. If it isn't already in the eclipseskills project, drag the file ColorFinder.java into the default package (using the "Copy files" option).
  6. Open ColorFinder.java.

1. (Creating and) Editing a Formatter Profile in Eclipse: This part of the lab will help you learn how to edit a formatter profile within Eclipse.
  1. Right-click on the eclipseskills project, pull down to Properties, expand "Java Code Style" and select "Formatter" in the left-side pane, select "Enable project-specific settings" choose "Eclipse", and click on OK.
  2. Click on New, enter "Lab Style" in the "Profile name", select "Eclipse" as the initial settings, and click on OK.
  3. The Eclipse style and the course style differ in the indentation size. To change the behavior of the formatter, select the "Indentation" tab set the "Tab size" to 2.
  4. The Eclipse style and the course style differ in the placement of the {. To change the behavior of the formatter, select the "Braces" tab and choose "Next Line" for everything but "Array initializer".
  5. Click OK to save the changes to the profile. Click OK again to use the "Lab Style" profile.
  6. Click Source+Format to re-format ColorFinder.java.
2. Editing XML Profiles: This part of the lab will help you learn how to edit an XML profile.
  1. Right-click on the eclipseskills project, pull down to Properties, expand "Java Code Style" and select "Formatter" in the left-side pane, select "Lab Style" and click on Edit....
  2. Click on Export and save the profile as lab_formatter.xml.
  3. Open the file in the editor of your choose. (If you use Eclipse click on the "Source" tab to edit the raw XML.)
  4. This root element is profiles which contains a a single profile which, in turns, contains one setting element for each option in the profile.
  5. The Eclipse style and the course style differ in the maximum line width. To change the behavior of the formatter, find the setting element with an id of "org.eclipse.jdt.core.formatter.lineSplit" and change its value to "100".
  6. Right-click on the eclipseskills project, pull down to Properties, expand "Java Code Style" and select "Formatter" in the left-side pane, select "Lab Style" as the "Active profile", click on Import, navigate to lab_formatter.xml, select "Overwrite the existing profile" click on OK, and click on OK.
  7. Click Source+Format to re-format ColorFinder.java.
3. Creating a Formatter for a Style Configuration: If you completed the lab on Checkstyle then you created a Checkstyle configuration. You could manually create a formatter profile that is consistent with this configuration but this can be fairly tedious. This part of the lab will help you learn how to create a formatter profile that is consistent with a Checkstyle configuration.
  1. Right-click on the eclipseskills project, pull down to Checkstyle and over to Create Formatter-Profile.
  2. Right-click on the eclipseskills project, pull down to Properties, expand Java Code Style, select Formatter, choose the "Active profile" named "eclipse-cs eclipseskills", click on Edit, enter a profile name, click on Export, navigate to an appropriate directory, enter a file name, click Save, click OK, and click OK.
  3. You can then edit this file as needed and/or use it as above.

Copyright 2020