Visualization and GraphicsInteractionDept ICSFaculty of ScienceUU

//webspace.science.uu.nl/~telea001/Site/TopBar

Visual code refactoring

Source code refactoring, or the modification of an existing code base according to a set of custom rules, is one of the most frequent, but also most difficult, activities in software maintenance. Refactoring ranges from simple changes such as renaming a variable up to complex transformations such as replacing code fragments with a more compact design pattern or automatic replacement of code duplicates with a single fragment.

Visual code refactoring in KDevelop

KDevelop is one of the most powerful and best known integrated development environments (IDEs) in existence today for C and C++. Similar to Eclipse and QtCreator, it allows editing, organization, browsing, compilation, and debugging of large and complex C/C++ code bases.

In this project, we added visual rule-based refactoring to C/C++ code bases using KDevelop, as follows. First, we extended the existing C/C++ parser to extract the information from a code base needed for refactoring (syntax, semantic, and location information). Second, we added a rule-based system that allows easy specification of program transformations, or refactoring rules. Third, we designed a visual interface for easy selection of the refactoring actions, visualizing their impact on the code, and step-by-step examination of a refactoring plan.

Installation

KDevelop as well as our extension are released under free licenses. KDevelop can be downloaded and installed from this location. We only tested development on linux distributions but you might be able to get KDevelop and our plugin running on other platforms as well (patches and howtos welcome). There are distro packages available for KDevelop, but for compiling our plugin you'll need at least the source of KDevelop (not kdevplatform). Version 1.0 of our plugin is developed to work with the 4.0.x releases of KDevelop. The master version of our plugin works against the development version of KDevelop. To install our plugin:

  1. Download and unpack the KDevelop sources (4.0.1 Sources)
  2. Checkout the 1.0 branch from our plugin with git:
    # git clone git://gitorious.org/kdevcpptools/kdevcpptools.git
    # cd kdevcpptools
    # git checkout -b 1.0 origin/1.0
  3. Link the languages subdirectory of the kdevelop source into the plugins src directory:
    # ln -sf ~/path/to/src/kdevelop/languages src/languages
  4. Build and install the plugin:
    # mkdir build
    # cd build/
    # cmake .. -DCMAKE_INSTALL_PREFIX=/same/prefix/as/kdevplatform/and/kdevelop
    # make && make install

Getting started

The first thing to do to get started is opening the C++ project subject to querying and/or porting. KDevelop has native support for the CMake build system, for other build systems one first need to perform the steps that generate the Makefile (e.g. ./configure).

Secondly, on first use, our plugin must be enabled explicitly (TODO: find out and add the exact menu's to perform this action).

Next, an XML file must be created which at least contains queries and optionally the transforms for a specific query. An example of this, which we used in the context of porting Qt based C++ applications can be found here.

Publications

The KDevelop C++ code refactoring tool is described in this paper. Full details are given in the MSc thesis of B. Broeksema available here.

Results

To view the refactor visual tool in use, select one of the following links.

Refactoring demo 2

Refactoring demo 3