: Learning GNU Emacs, 3rd Edition

9.5.6 Editing with the JDEE

9.5.6 Editing with the JDEE

First off, you're still in Emacs, so the usual motion commands described for Java mode (and C mode) still apply. But the JDEE adds two really great features to your editing cycle: command completion and class browsing.

The idea behind command completion is that the JDEE can (usually) predict which methods and variables are valid choices to make at certain points in your Java program. For example, if you start typing System. in your program, there are a finite number of choices for what follows that period. JDEE can display a list of those choices.

The command to show your list of completions is C-c C-v C-. (for jde-complete), which defaults to showing you a menu of completions. (You can change that behavior by customizing the jde-complete-function variable.) The completions are generated by looking at all of the classes listed in the jde-global-classpath variable (or the CLASSPATH environment variable if no global classpath was defined).

The class browser can be accessed quickly from the JDE menu and launches a BeanShell browser for the class your cursor was on. It's like a context-sensitive documentation tool, but a bit more powerful. Figure 9-3 shows what you get when starting the browser while your cursor is on the word System.

Figure9-3.The BeanShell class browser launched from the JDEE

You can also launch the class browser with the M-x jde-browse-class-at-point command.

One other edit-time feature worth pointing out is the Code Generation item in the JDE menu. It has some great timesavers built-in, as shown in Table 9-7.

Table9-7.Code Generation menu options

Keystrokes Menu option (M-x command) Action
C-c C-v C-l (lowercase L) Println Wizard(jde-gen-println) Prompts for the contents to print and inserts a complete System.out.println() method for you.
C-c C-v C-z Import Class(jde-import-find-and-import) Prompts for the (simple) class name to import and automatically adds the proper import line to the top of your file.
C-c C-v i Implement Interface(jde-wiz-implement-interface) Prompts you for the name of the interface to implement. Adds any missing import statements (including dependent imports, such as imports required for method arguments). Provides commented skeletons for each of the methods in the interface.

Other helpers are available from the JDE menu. Generate Get/Set Pairs in particular is great for working with JavaBeans design patterns. Just create your list of attributes and then run the wizard. It even checks to see if you already have an existing get/set pair. If you do, it notes that get/set pair as "existing" and keeps on trucking so you can use the wizard to update existing classes.

: 0.140. /Cache: 0 / 0