OpenMRS code follows a specific format. To set up Eclipse properly, so that your code can be formatted automatically, follow the instructions below.
Table of Contents
Download and Install Eclipse
...
- Open Eclipse, select Window > Preferences.
- In the search box, enter formatter, then select Java > Code Style > Formatter.
- In the left right pane, select Import.
An Import Profile dialog displays. - In the dialog, browse to: openmrs-core/tools/src/main/resources/eclipse, and select OpenMRSFormatter.xml.
- Select Open.
The OpenMRS Formatter shows as the Active profile. See the picture below: - Select Apply and Close.
Now you can let Eclipse format any java class with the shortcut:
...
- Select Window > Preferences. In the search box enter organize imports.
- Select Java > Code Style > Organize Imports.
The result is as following: - Make sure the order of the import groups is as what you see above (java, javax, org, com).
It is the Eclipse default, so you might not have to change anything. - Check both Number of imports needed for * and Number of static imports needed for * are set to 99.
The numbers need to be high enough so that Eclipse will not replace your imports with the so called "star imports" using *. 99 is the default value for Eclipse and is usually high enough. - Select the Do not create imports for types starting with a lowercase letter checkbox.
- Select Apply and Close.
Now you can let Eclipse format and remove unused imports with the shortcut:
Ctrl+Shift+O (Command+Shift+O on Mac)
Note |
---|
Important: Please apply this command to clean up your imports before you create a pull request on Github since the imports are not cleaned up by the maven formatter plugin we use when you run the build command ! |
...
- Select Window > Preferences.
- In the search box, enter save actions.
- Select Java > Editor > SaveActions.
- Select radio buttons and checkboxes to match the image above.
- Select Configure.
The Additional Save Actions dialog displays. - Select the Missing Code tab, select ALL the checkboxes and select OK.
- Select the Unnecessary Code tab, and select the checkboxes as the picture below:
- Make sure that NOTHING is selected in the Code Organizing, Code Style, and Member Accesses tabs. Select OK to close each tab.
- Select Apply and Close.
Now when you change a class and save it, Eclipse will format the code for you according to your formatter settings and organize the imports according to the import settings.
Import OpenMRS Code Templates
...
- Select Window > Preferences.
- In the search box, enter maven (Or search for User Interface).
- Select Maven > User Interface.
- Select the Open XML page in the POM editor by default check box.
- Select Apply and Close.
...
- Select Window > Preferences.
- In the search box, enter maven.
- Select Download Artifact Sources and Download Artifact JavaDoc.
- Select Apply and Close.
Now you’ve completed the setup for Eclipse.
To learn more about Eclipse go to: How to Set Up and Use Eclipse.