< Day Day Up > |
13.4 Changes to the Java Development ToolsThe major enhancements in Eclipse 3.0 are to the JDT, as you might expect. The changes so far are mostly for usability and convenience, and they're designed to help you program Java better. It's not clear which ones will be around in the final release of Eclipse 3.0, but we'll take a look at what's available now. 13.4.1 Quick Hierarchy ViewsYou can now select a type, method, or package reference in the JDT editor and press Ctrl+T to see a quick type hierarchy view, as appears in Figure 13-13. Figure 13-13. Showing a quick hierarchyYou can also now open a view that shows a method call hierarchy by selecting Navigate Open Call Hierarchy (or by pressing Ctrl+Alt+H) in the JDT editor (or, for that matter, any of the Java views that show methods). 13.4.2 Creating Constructors from FieldsYou can also create a constructor that fills various fields easily in Eclipse 3.0. For example, say you added a String field to a class this way: public class Ch13_01 {
private String text;
public static void main(String[] args) {
System.out.println("Hello from Eclipse 3.0");
}
}
To create a constructor that fills this field in Eclipse 3.0, select Source Generate Constructor Using Fields, opening the dialog you see in Figure 13-14. Figure 13-14. Creating a constructor using a fieldYou select fields you want to fill in the constructor and click OK; in this case, here's the constructor created: public class Ch13_01 { private String text; public static void main(String[] args) { System.out.println("Hello from Eclipse 3.0"); } /** * @param text */ public Ch13_01(String text) { super( ); this.text = text; } } 13.4.3 Creating Factory MethodsYou can go further as well—you can convert your constructor into a factory method with the new Refactoring Introduce Factory item. Just select a constructor declaration or a call to the constructor in the JDT editor and select that menu item. For example, say you added this call to the Ch13_01 constructor in your code: public class Ch13_01 {
private String text;
public static void main(String[] args) {
Ch13_01 ch13_01 = new Ch13_01("Hello");
System.out.println("Hello from Eclipse 3.0");
}
/**
* @param text
*/
public Ch13_01(String text) {
super( );
this.text = text;
}
}
Selecting the constructor call and the Refactoring Introduce Factory item opens the dialog you see in Figure 13-15. Figure 13-15. Creating a factory methodClicking OK creates a new factory method, createCh13_01, replaces the call to the constructor with a call to that method, and makes the original constructor private: public class Ch13_01 { private String text; public static void main(String[] args) { Ch13_01 ch13_01 = createCh13_01("Hello"); System.out.println("Hello from Eclipse 3.0"); } public static Ch13_01 createCh13_01(java.lang.String text) { return new Ch13_01(text); } /** * @param text */ private Ch13_01(String text) { super( ); this.text = text; } }
This is the general trend in Eclipse 3.0—giving you more control over tasks you already perform. For example, the dialog for the JDT editor's Source Add Constructors from Superclass command now displays a dialog that lets you select which of the superclass's constructors should be added to the current class. Other commands now give you considerably more control, such as the code generation dialogs for the Source Generate Getter and Setter, Source Override/Implement Methods, and Source Generate Delegate Methods. You can indicate where the generated method will be inserted and—for getters and setters—the sort order.
13.4.4 Smart Insert ModeThere's a new typing mode in the JDT editor—smart insert mode—in addition to the standard overwrite and insert mode. Smart insert mode adds functionality for Java programmers, such as automatically wrapping Java strings to code lines as you type them. You can toggle between these three modes by repeatedly clicking the Insert key and watching the status bar indicator (set to Smart Insert in Figure 13-8). To configure smart insert mode, select Window Preferences Java Editor Typing, opening the dialog you see in Figure 13-16. Besides the options you see in that dialog, there are others being considered for smart insert, such as automatically inserting semicolons at the end of lines. Figure 13-16. Configuring smart insert mode13.4.5 Creating Block CommentsBesides commenting out blocks of code using single-line comments, you can also comment out code using Java block comments. For example, if you select this code: public class Ch13_01 { private String text; public static void main(String[] args) { System.out.println("Hello from Eclipse 3.0"); } } and then select the Source Add Block Comment (note that the Source Comment item is still available for commenting out blocks with single-line comments), you'll get this result: public class Ch13_01 { private String text; /* public static void main(String[] args) { System.out.println("Hello from Eclipse 3.0"); } */} To uncomment a block, select it and then select Source Remove Block Comment. 13.4.6 New ViewsEclipse 3.0 also comes with some new views: Javadoc, Error log, and Declaration. You can show these as you would any view, using Window Show View. For example, the Error log view, which holds errors in the Eclipse .log file, appears in Figure 13-17. Figure 13-17. The Error log view13.4.7 Additional ChangesBesides the changes to the JDT already discussed, there are plenty of other smaller changes. Here's an overview of the most significant of these:
There are plenty of plans for new improvements to Eclipse 3.0 in upcoming releases. Here's a sampling:
|
< Day Day Up > |