13.4 Changes to the Java Development Tools

     

The 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 Views

You 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 hierarchy
figs/ecps_1313.gif

You 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 Fields

You 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 field
figs/ecps_1314.gif

You 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 Methods

You can go further as wellyou 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 method
figs/ecps_1315.gif

Clicking 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;         } } 

More on refactoring: now you can also move public static final fields between classes and interfaces, as well as static inner types between classes. The Refactoring Change Method Signature now lets you rename parameters in overridden methods as well.


This is the general trend in Eclipse 3.0giving 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 andfor getters and settersthe sort order.

While discussing getter/setter generation, it's worth noting that you can find new templates for getters and setters in the Window Preferences Java Code Generation Code and Comments preference page.


13.4.4 Smart Insert Mode

There'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 mode
figs/ecps_1316.gif

13.4.5 Creating Block Comments

Besides 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 Views

Eclipse 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 view
figs/ecps_1317.gif

13.4.7 Additional Changes

Besides the changes to the JDT already discussed, there are plenty of other smaller changes. Here's an overview of the most significant of these:

  • When you select a local variable in the JDT editor and press F3 (or select Navigate Open Declaration), the JDT editor displays the variable's declaration.

  • The JDT compiler now adds more checks to find and mark styling issues. To turn them on, see Window Preferences Java Compiler Style.

  • Instead of adding a closing brace as soon as an opening brace has been entered, the JDT editor now waits until a new line is added after the closing brace .

  • There are some new Quick Assists in the JDT editorSplit and join variable declaration, and Create field from parameter.

  • The launch configuration page now lets you set environment variables .

  • The JDT compiler can now indicate when projects are compiled against a binary library whose version is incompatible with what is being generated. For example, you might be trying to generate 1.1-compatible class files while compiling using a Java 1.3 library. See Window Preferences Java Compiler Build Path.

  • You can now implement searches to include projects that enclose the current project.

  • The JDT editor's Go To Next/Previous Error toolbar buttons were replaced by Go To Next/Previous Annotation drop-down style buttons , which allow you to choose which annotations you want to move to.

  • The JDT compiler can find and mark unused exceptions that are declared but not thrown. Enable this with Window Preferences Java Compiler Unused Code.

There are plenty of plans for new improvements to Eclipse 3.0 in upcoming releases. Here's a sampling:

  • Generalize the JDT editor to handle other Java-like source files, such as SQLj and JSP.

  • Mark overridden methods with override indicators.

  • Handle new J2SE 1.5 functionality and extensions to Java, such as generic types, autoboxing, static imports, and so on. The final version of Eclipse 3.0 will probably ship before J2SE 1.5 does, but the Eclipse team is working on including support for it already.



Eclipse
Eclipse
ISBN: 0596006411
EAN: 2147483647
Year: 2006
Pages: 114
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net