UCDetector UCDetector: Unnecessary Code Detector

UCDetector (Unnecessary Code Detector) is a eclipse PlugIn to find unnecessary (dead) public java code, like classes/members/methods which are public or protected and which have no references.

Unnecessary code is marked in eclipse using problem markers. Code which could be changed to protected or private is also marked. This markers appear in the eclipse problem view, like other java problems.

UCDetector also finds cyclic dependencies between classes in your code. This cycle classes are shown in s special cycle view.

Installation

Download the org.ucdetector_X_Y_Z.jar from here and put it into your ECLIPSE_HOME\plugins directory. Restart Eclipse (version >= 3.2).

Quick start

  • Instead of clicking Shift+Ctrl+G (search references in workspace) all the time follow the next steps:
  • right click on a package in the eclipse package explorer
  • select the context menu: UCDetector/detect unnecessary code
  • wait, the classes in the selected package will be checked
  • check warnings in the eclipse java editor and the eclipse problem view

Run UCDetectorRun UCDetector

Select the code which should be checked. It is possible to select (multi select) the following java elements:
  • projects
  • packages
  • classes
  • methods
  • members
Select one ore more of this elements and run UCDetector by right clicking on the elements.
Select context menu: "UCDetector/detect unnecessary code"
Wait, while UCDetector is checking your code. If your selection contains many classes this could take some minutes.
UCDetector pop up menu


Not found visibilityCheck results

  • Check the eclipse problem view
  • Group the problems: Use the menu "Group By/Type" in the Problems View
  • Double click on a problem to find problem in code

Limitations

The problems found by UCDetector, are only suggestions.
Before deleting or changing your code you should really know what you are doing!
If UCDetector tells you, that there are no references of your class, method or field your code still may be used by:
  • Reflection
  • Declaration in no java files like property files, xml files...
  • Third party code, which is using your code
  • Jars in your workspace
  • To be continued...
Change visibility to private or protected may have side effects to inheritance, reflection...

It is a good idea to do a full text search in your whole workspace, for the piece of code you want to change.

Change your code

After checking carefully all the limitations above, maybe you decide to change your code:
  • Delete code, when UCDetector tells you that there are no references
  • Move your code, when UCDetector tells you that there is only 1 reference (change "Limit" to 1 in "Window/Preferences")
  • Change visibility to protected or private

Ignore code


/**
 * Class is only used by reflection.
 * Write a "NO_UCD" comment at the end of the line which should be ignored by UCDector.
 */
public class Example { // NO_UCD
  

removeClean markers

Delete UCDetector markers by right clicking on a java element which contains the markers and select:
"UCDetector/Clean markers"
UCDetector

countCount code checked by UCDetector

It is possible to count code checked by UCDetector. Select context menu: "UCDetector/count elements"
UCDetector count

Preferences

Select menu "Window/Preferences..."
Select "UCDetector"

Filter

It is possible to filter java elements (and all its children), which should not be checked by UCDetector.
  • Ignore source folders
  • Ignore packages:
  • Ignore classes:
A simple regular expression is used:
?: Match one Character
*: Matching 0 or more characters.

Detect

Select in this group, what kind of code should be checked, and how should the problems be marked: There are 3 possibilities:
  • Error: Mark the problem using error markers
  • Warning: Mark the problem using warning markers
  • Ignore: Don't create markers for the problem
Select what kind of code should be marked:
  • Limit: Number of found references, which are necessary to mark java code as problem. 0 means: If a class has no references, mark it with UCDetector
  • Classes: Select error level for classes
  • Methods: Select error level for methods
  • Fields: Select error level for fields
  • Visibility: Select error level for visibility. This option will create markers for code which could be private or protected

Cycles

For cycle detection you can choose the "max cycle size". If there are many cycles in your code, this option can make UCDetector very slow.
UCDetector preferences

cycleDetect class cycles

Right click on classes, packages or projects, Select context menu: "UCDetector/detect cycles". The class cycles will appear in the Cycle View. Browse the class cycles by exploring the cycle tree.
UCDetector cycle

Releases

Contact & Links


Last Update: 2008-04-03 Copyright © 2008, by Jörg Spieler

Page views since 2008-03-01: Page views since 2008-03-01 Hosted by: SourceForge.net Logo