A.4. Eclipse FeaturesEclipse has too many interesting features to really do them justice here, but we'll mention a few to show you why people love this IDE. A.4.1. Coding ShortcutsOf course, you've noticed all the color coding and meta-information present when viewing Java source code in Eclipse. You can customize all of this behavior to suit your taste through the Window What may not be immediately obvious is that editing is also enhanced. When typing, try pressing Ctrl-Space to attempt autocompletion or have Eclipse present you with relevant options. For example, instead of typing JButton, TRy typing JBu plus Ctrl-Space. Eclipse completes the name for you. If the portion of the name you type is ambiguous, a drop-down list appears, similar to that shown in Figure A-5. Figure A-5. Using completion in Eclipse![]() Eclipse also provides abbreviations for common items. Try typing sysout and pressing Crtl-Space. Eclipse expands this to System.out.println( ) and places the cursor in the parentheses automatically. If you type a quotation mark, Eclipse closes the quotation for you. Note the green bar it places after the closing quote. Pressing Tab takes you to that point so that you don't have to use the arrow keys. Pressing Tab again takes you to the next green bar spot, the end of the line. A.4.2. Auto-CorrectionEclipse can offer fixes for simple problems in your code when it detects them. To see suggested fixes, click on the red X next to a problem line. Eclipse presents a dropdown menu of possible fixes for the problem. Selecting an option shows you the code changes Eclipse will make before you choose it. For example, try changing the name of one of the JButtons in our Calculator to JBButton. Now, click the red X and a screen similar to Figure A-6 appears. Eclipse offers several possible corrections; the best one is to fix the misspelling and change it back to JButton. Of course, if we'd really meant to refer to a new kind of button, we could choose the option to create the new class right there and Eclipse would help us do that by creating a skeleton for us. Figure A-6. Autocorrection in Eclipse![]() A.4.3. RefactoringEclipse offers a number of tools under the collective title "refactoring." These include the ability to rename and move members, automatically tracking down references to them and changing them throughout the project. More advanced options allow you to do things like create an interface for your class by copying all of its public methods or add a factory pattern to your code to encapsulate all object creation for a type. You can even encapsulate access to a variable, changing the code to use an accessor method instead. These tools can save you a lot of typing (or retyping, as the case may be). For an example, let's look at our Calculator again. Click on the addGB( ) method in the outline or select the method definition yourself. We use this method a lot, so let's give it a better name. Select Refactor A.4.4. Diff'ing FilesEclipse provides the ability to quickly diff two files. Select two files simultaneously in the Package Explorer. Right-click the first file to display a context menu and select Compare With A.4.5. Organizing ImportsEclipse can tidy up the import statements in your source code. Selecting Source A.4.6. Formatting Source CodeEclipse can autoformat your source code using the Source |