Copyright © 2006-2012 Huiqing Li, Simon Thompson
Authors: Huiqing Li (H.Li@kent.ac.uk), Simon Thompson (s.j.thompson@kent.ac.uk) [web site: http://www.cs.kent.ac.uk/projects/wrangler].
Wrangler is an Erlang refactoring tool that supports interactive refactoring of Erlang programs.
Refactoring is the process of improving the design of a program without changing its external behaviour. While refactoring by hand is possible, tool support for refactoring is invaluable as it is more reliable, and allows refactoring to be done (or undone) easily. Wrangler is such a tool that supports interactive refactoring of Erlang programs. Wrangler currently supports a number of basic Erlang refactorings, such as renaming of variable/function/module names, generalisation of a function definition, function extraction, folding against a function definition, duplicated code detection, etc.
Wrangler also provides a set of process-based refactorings, including the
introduction of process naming, instead of providing access to a process
only through a dynamically-generated process id Wrangler also contains
a variety of refactorings which work with Erlang QuickCheck, introducing
and merging constructs such as ?LET
and ?FORALL
.
Transforming data types in Erlang can be difficult, as Erlang functions can take values of any type, in principle. There are situations -- particularly in implementing an Erlang behaviour , which can be thought of as an interface for a set of callback functions -- where the types are more constrained, and where data transformations are possible. In particular we have implemented transformations for state data in various kinds of generic state machine in both the OTP library and QuickCheck.
In implementing Wrangler we have chosen to respect various features of the language and related tools. Wrangler is able to process modules which use macros, including the Erlang test frameworks that are in regular use. Wrangler also respects the naming conventions in those test frameworks.
Wrangler provides a portfolio of decision support tools. The code inspector highlights local code smells and a number of reports highlight issues in the module structure of projects, including circular inclusions and other potential faults. The code clone detection facilities can be used on large multi-module projects to report on code clones and how they can be removed; clone detection can be preformed incrementally on larger code bases, for example as part of a continuous integration approach to software construction.
Wrangler has recently been extended with a framework that allows users to define for themselves refactorings and code inspection functions that suit their needs. These are defined using a template- and rule-based program transformation and analysis API. Wrangler also supports a domain-specific language that allows users to script composite refactorings, test them and apply them on the fly. User-defined refactorings and scripts are not second-class citizens: like the existing Wrangler refactorings, user-defined refactorings benefit from features such as results preview, layout preservation, selective refactoring, undo and so on.
Built on top of the functionalities provided by the Erlang syntax-tools package, Wrangler is embedded in the Emacs/Xemacs editing environment, and makes use of the functionalities provided by Distel, an Emacs-based user interface toolkit for Erlang, to manage the communication between the refactoring tool and Emacs. Wrangler is also integrated within Eclipse, as a part of the ErlIDE plugin for Erlang.
Below is a snapshot of Wrangler embedded in Emacs, which shows a particular
refactoring scenario. The user has selected the expression
io:format("Hello")
in the definition of repeat/1
, has
chosen the Generalise Function Definition command from the
Refactor sub-menu, and has just entered a new parameter name A in the
mini-buffer.
The result of this refactoring is shown in the snapshot below.
Preview of the changes to be made by a refactoring is supported, and the user could choose to commit or abort the refactoring result after preview. Wrangler's preview uses the Ediff package for Emacs.
All the implemented refactorings are module-aware. In the case that a refactoring affects more than one module in the program, a message telling which files have been modified by the refactorer will be given after the refactoring has been successfully done. The Customize Wrangler command from the Refactor sub-menu allows the user to specify the boundary of the program, i.e., the directories that will be searched and analysed by the refactorer, as shown in the example snapshot below.
Undo is supported by the refactorer. Applying undo once will revert the program back to the status right before the last refactoring performed. However, PLEASE NOTE that the refactorer undo is currently separate from the Emacs undo, and undoing a refactoring will lose all the editing activities after the refactoring.
Below is a snapshot of Wrangler embedded in Eclipse + Erlide.
Wrangler makes use of functionalities provided by the epp_dodger
module
from the Erlang syntax_tools
library to parse Erlang source code, and
should be able to refactor Erlang modules containing preprocessor directives
and macro applications, as long as the macro definitions are syntactically
"well-behaved".
Wrangler accepts Erlang programs with syntax errors or macro definitions
that cannot be parsed by epp_dodger
. In the case that the program under
consideration has syntax errors or unparsable macros, functions/attributes
to which these syntax errors belong are not affected by the refactoring
process; however, warning messages asking for manual inspection of those
parts of the program are given after the refactoring.
Wrangler is downloadable from Github: https://github.com/RefactoringTools, and also from http://www.cs.kent.ac.uk/projects/wrangler
Open an Erlang source file in the Emacs editor. You should now have a menu called Erlang, if you have configured Emacs properly to use the Erlang-mode (see the file INSTALL otherwise).
To start Wrangler, type: M-x erlang-wrangler-on
, or
alternatively Ctrl-c Ctrl-r
. After that, new menu Wrangler should appear in the
menu bar (see INSTALL otherwise).
To stop Wrangler, type M-x erlang-wrangler-off
, or
alternatively use Ctrl-c Ctrl-r
again. The Refactor and Inspector
menus will disappear from the menu bar.
You can use Ctrl-c Ctrl-r
to toggle Wrangler on or off.
For most refactorings, the editor interface will pass the current filename (should be the module name, as well), the refactoring command, and the current cursor position. For some refactorings, you'll also need to highlight an expression, or enter a new name.
The Customize Wrangler menu in the Wrangler submenu allows you to specify the boundary of the system by giving the list of directories to search for Erlang source files/header files that could be affected by a refactoring.
For most refactorings, the editor interface will pass the current filename (should be the module name, as well), the refactoring command, and the current cursor position. For some refactorings, you'll also need to highlight an expression, or enter a new name.
How to use:Generated by EDoc, Nov 5 2015, 16:30:22.