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.

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 Screenshot-13.

Screenshot-13. Showing a quick hierarchy
Java figs/ecps_1313.gif

You can also now open a view that shows a method call hierarchy by selecting NavigateScreenshot 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).

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 SourceScreenshot Generate Constructor Using Fields, opening the dialog you see in Screenshot-14.

Screenshot-14. Creating a constructor using a field
Java 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;
 }
}


Creating Factory Methods

You can go further as well—you can convert your constructor into a factory method with the new RefactoringScreenshot 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 RefactoringScreenshot Introduce Factory item opens the dialog you see in Screenshot-15.

Screenshot-15. Creating a factory method
Java 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;
 }
}


Screenshot

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 RefactoringScreenshot Change Method Signature now lets you rename parameters in overridden methods as well.


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 SourceScreenshot 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 SourceScreenshot Generate Getter and Setter, SourceScreenshot Override/Implement Methods, and SourceScreenshot Generate Delegate Methods. You can indicate where the generated method will be inserted and—for getters and setters—the sort order.

Screenshot

While discussing getter/setter generation, it's worth noting that you can find new templates for getters and setters in the WindowScreenshot PreferencesScreenshot JavaScreenshot Code GenerationScreenshot Code and Comments preference page.


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 Screenshot-8). To configure smart insert mode, select WindowScreenshot PreferencesScreenshot JavaScreenshot EditorScreenshot Typing, opening the dialog you see in Screenshot-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.

Screenshot-16. Configuring smart insert mode
Java figs/ecps_1316.gif

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 SourceScreenshot Add Block Comment (note that the SourceScreenshot 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 SourceScreenshot Remove Block Comment.

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 WindowScreenshot Show View. For example, the Error log view, which holds errors in the Eclipse .log file, appears in Screenshot-17.

Screenshot-17. The Error log view
Java figs/ecps_1317.gif

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 NavigateScreenshotOpen 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 WindowScreenshotPreferencesScreenshotJavaScreenshotCompilerScreenshotStyle.
  • 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 editor—Split 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 WindowScreenshotPreferencesScreenshotJavaScreenshotCompilerScreenshotBuild 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 WindowScreenshotPreferencesScreenshotJavaScreenshotCompilerScreenshotUnused 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.
      
Comments