Figure 2.3: The Xref-Speller Interface within Emacs
The xref program was developed by MARIAN VITTEK [Xref-Speller] to support extending source browsing and symbol completion functionality under a variety of development environments. Later refactoring functionality was added. It seemed to be no problem at all because the source of the project to be refactored is already available as a parse tree to the xref program. And similar to the RefactoringBrower [TAPOS] it is much easier to implement refactorings to a parse tree than to pure source code.
Actually the Xref-Speller (see 2.3, p.)is just a front end for (X)Emacs and Kawa for the tool xref which runs as a separated process and communicates with the front end.
By now the Java and C language are supported by xref. The C part of the program was tested with the linux kernel sources (about 1.5 million lines of code). It includes a full featured preprocessor needed for parsing the preprocessor instructions of C-programs. The creation of the parse tree for the Java language is not done by parsing the source files but rather by decompiling the byte code of the class-files generated by the java compiler, as there the type information (e.g. symbol types, function signatures etc.) needed is already verified and non-ambiguously stored by the compiler.
The xref tools supports the notion of projects and allows the user to include/exclude specific directories to use. The needed files are parsed by an update function into a cross-references file which can be updated either by reexamining all files or by updating only modified files. This cross-references file is used for all operations as it includes a parse tree of the projects classes.
The refactoring currently implemented in xref are the extraction of marked code into a new method, inclusively creating a call to the new method at its old place. This functionality can be used to do the refactorings Extract Method, Consolidate Conditional Expression, Decompose Conditional.
Another refactoring supporting functionality is the modification of function parameters to do Add Parameter, Remove Parameter, Parameterize Method. Unfortunately the implementation of Insert Parameter lacks the ability of the Refactoring Browser to supply a default value and also does not care about the use of parameters within the method body which were deleted from the parameter list.
The renaming refactorings can be achieved by using the renaming possibilities offered by xref. As the renaming occurs at the parse tree level, it is not subject to unintendedly renaming the wrong occurrences (depending on type, method signature).
Xref is also able to generate html files for all the source code of a project, including references between all the generated files at each occurrence of variable, class or method names to the correct source of the declaration. This is very helpful when parsing through the static inheritance and association structure of the project.
In general it has to be said that the Xref-Speller is a very useful tool for users of (X)Emacs/Kawa, which allows to reduce the tedious work connected to the application of the refactorings mentioned. Besides the parsing and completion functionality at parse tree level outperforms the ctags functions available within Emacs in scope of correctness.
There are also a lot of possibilities how to extend the xref program which would make it even easier to browse the static inheritance and association structure of a project and allow the user to apply more refactorings without much manual intervention.