Use WebSphere's Java Editor tools Click here to see all the Developer/Admin Tips

Date tip published:12/01/2003
Description:When writing Java code in WebSphere Studio 5.1 there are several tools to help you format your code, fill-in syntax, and suggest fixes for errors. This tip will show you how to use these tools.


To learn more about using WebSphere Studio use the following links:

Introduction to WebSphere Studio 5
Introduction to WebSphere 5 for Domino Developers



WebSphere Studio's Java Editor Tips

When writing Java code in WebSphere Studio 5.1 there are several tools to help you format your code, fill-in syntax, and suggest fixes for errors. This tip will show you how to use these tools.



Format Java Code

After editing a Java source file, it may be useful to format the code according to the Code Formatter settings in the WebSphere Studio Preferences dialog. Follow these steps to format new or modified code:

  1. Add or modify the code in a Java source file.
  2. Right click in the editor area to access its context menu.
  3. Select Source | Format from the context menu to format the code according to the Code Formatter settings.




Procedure: Setting Code Formatting Preferences for the Java Editor

The code format options of the Java editor can be customized. Follow these steps to customize the format settings:

  1. Select Window | Preferences from the menu bar.
  2. In the left navigator in the Preferences dialog, expand Java and select Code Formatter. On the right, check the desired new line settings. The code sample window is updated to reflect the current settings. Click the [Apply] button to apply the chosen code formatter settings or [Restore Defaults] to revert to the default settings.






Using Content Assist

The WebSphere Studio Content Assist feature, also known as Code Assist, is used to display a popup dialog of possible completion values for the current incomplete code. The desired completion code can be selected from the dialog list and added to the current Java source file. The Hover Help dialog is also displayed for the selected completion code in the Content Assist dialog.





Using Content Assist from the Keyboard

Since you are entering code from the keyboard, it is easier to access and use content assist using the keyboard. Follow these steps to use content assist from the keyboard:

  1. Enter some incomplete code in the Java editor up to the period <.> separator.
  2. After the delay defined in the "Code Assist" tab of the Java Editor preferences, the code assist pop up box will appear.
  3. You can also press <CTRL><SPACE> on the keyboard to open the Content Assist dialog for the current incomplete code.
  4. Use the <DOWN ARROW> and <UP ARROW> keys to scroll the list of presented completion values and stop at the desired value.
  5. Press the <ENTER> key to complete the code with the selected value in the Content Assist dialog box.

Using Content Assist with Your Mouse

Follow these steps to use content assist with your mouse:

  1. Enter some incomplete code in the Java editor.
  2. Select Edit | Content Assist from the menu bar or select Content Assist from the context menu.
  3. Scroll the list of presented completion values and double click the desired completion value.



Quick Fix Syntax Checking

As you type code in the Java editor, the Quick Fix syntax checker is monitoring your input. If incorrect syntax is entered, the Quick Fix icon ( ) is displayed beside the line of incorrect code. You can click on the Quick Fix icon to display a list of choices for correcting the code. Highlight one of the choices from the list and press the <ENTER> key to accept the change. The Hover Help dialog is also displayed for the selected correction code in the Quick Fix dialog.




Quick Fix is enabled by default. The Quick Fix settings can be accessed and changed on the "Annotations" tab of the Java Editor preferences.