DTGC

From Intoj.org

Jump to: navigation, search

Contents

[edit] Purpose

to check code for possible generalizations of declared types; to detect the smell of not using suitable abstractions


[edit] System requirements

  • Eclipse 3.2
  • Java 5 (recommended)
  • Infer Type (optional)


[edit] Rationale

It is considered good programming practice that variables are typed with interfaces (or abstract classes) rather than concrete classes. For instance, rather than having

 HashSet set = new HashSet();

one should write

 Set set = new HashSet();

where Set is an interface of HashSet.

Now Eclipse comes with two standard refactorings, Generalize Declared Type (formerly called Generalize Type) and Use Supertype Where Possible, that provide for automatic replacement of a declared type with an existing supertype. To complement these, we provide a third refactoring, Infer Type, that can compute and insert a new supertype (interface or abstract class) based on a declaration element by automatically extracting precisely the members that are needed from the declaration element in the program. However, all refactorings must be initiated by hand, i.e., the programmer must reckon that the type used in a declaration could be generalized.


[edit] How it works

The Declared Type Generalization Checker is an auditor that scans the code for declarations whose types could be generalized. For this, it uses one of currently two algorithms, Generalize Declared Type and Infer Type, to compute for every declaration element of a program whether its declared type can be generalized. If so, it issues a warning, as in

Image:DTGC Warning.png

which can be resolved by a corresponding Quick Fix, as in

New: If the declared type is to remain as is, with no warning shown, a corresponding annotation, called @Sic (Latin for so!), can be inserted. This is also offered by the Quick Fix (see above), but requires the project to build on Java 5.

The algorithm to be used, as well as whether generalization checking is to be performed, can be set in a project's preferences, as in

Image:DTGC Properties.png

[edit] Known issues

  • The Declared Type Generalization Checker is implemented as a builder. Activating it in a project's property sheet alone does not cause it to be started.
  • Depending on the size of the project and the used algorithm, a full check can be quite costly (approx. 90 seconds producing 77 warnings for a full check of JUnit 3.8, and approx. 11 minutes producing 166 warnings for JHotDraw 6.0b1; all on an IBM ThinkPad 2668-74 run at 2 GHz using Eclipse 3.2.1 and Sun Java 1.5.0).
  • Eclipse's Generalize Declared Type Refactoring still suffers from a number of bugs.

[edit] Installation

 Eclipse Update Site: http://www.fernuni-hagen.de/ps/prjs/DTGC/update/


[edit] Publications


[edit] Team

  • Markus Bach
  • Friedrich Steimann