Emacs minor mode for editing and browsing Java source code
The Emacs package jtags-mode is a minor mode that provides an improved tags lookup function compared to the ordinary etags package. The improved tags lookup function is only implemented for Java source code.
The jtags code acts as a middleware between Emacs and the etags program that is distributed with Emacs. Unlike the ordinary etags package, jtags parses the Java source code to find the correct scope (i.e. the class around point). It then looks up and shows the declaration of the identifier, after finding the source code file in the tags table file. This is possible since jtags knows some Java syntax and deals only with Java source code.
Showing the declaration of an identifier
Consider the following line of Java code:
Bar.getInstance().foo().toString()
When showing the declaration of the method toString(),
jtags will parse the Java code above, and with the help of the
tags lookup functions, find and parse the source code for the class
Bar, and the methods getInstance() and
foo(). Using this information, jtags finds out in which
source code file the method toString() is declared, loads
the file, and displays the declaration.
Showing the Javadoc for an identifier
When showing the Javadoc for the method toString(), jtags
will look up the declaration as above. Then, an HTML file with the
Javadoc for the method toString() will be generated and
displayed in the system browser.
Completing an identifier
Consider the following unfinished statement:
myFile.li
When completing the statement above, jtags will parse the Java code and
lookup the variable myFile. It will then find all members in
the corresponding class, and suggest completions like below.
Found 3 completions: list listFiles listRoots
Final and static members can be displayed using a different face, e.g. italics. Inherited members can also be displayed using a different face.
Adding and organizing import statements
When the compiler reports that it "cannot resolve symbol" because an import statement is missing, jtags can add the import statement for you. Place the point in the identifier and type C-c +. This will make jtags parse the Java code and the tags table files to find the package name, and add an import statement for the identifier.
You can also order and format the import statements in the current source
code file. Type C-c =, and jtags will order the import statements and
insert blank lines where apropriate. The sort order can be changed using
customize.
These functions are placed in a separate package called jtags-extras since they are not part of the jtags-mode core functionality.
Updating tags table files
To find where in the source code an identifier is declared, jtags uses tags table files generated by the etags program. Included in the jtags package, is a function that automatically runs the etags program, and updates all the tags table files. You can also type C-c , to update only the tags table file for the project you are working on.
The latest version of jtags-mode has been tested in GNU Emacs 21.3, GNU Emacs 22.1, and XEmacs 21.4.21 on Windows XP, Windows Vista, and Ubuntu Linux. All features are not available in GNU Emacs 21.3. Most notable, jtags will always sort import statements in alphabetical order.
Download the latest version of jtags-mode here. The package is available as a zip file, and as a gzipped tar file. Installation notes are included within the Emacs Lisp file itself.
GNU Emacs users can also download and install jtags-mode from the Emacs Lisp Package Archive.
| © Johan Dykström 2009 |
|
Last modified: 2009-05-30 21:04:48 |