UCDetectorUCDetector

Start

About

UCDetector (Unnecessary Code Detector - pronounced "You See Detector") is a eclipse PlugIn tool to find unnecessary (dead) public java code. For example public classes, methods or fields which have no references. UCDetector creates markers for the following problems, which appear in the eclipse problem view: UCDetector popup
If you can't see the pop menu above, read FAQ

Get UCDetector

UCDetector needs Eclipse >= 3.4 and java >= 5.0.
(For older versions: Eclipse 3.2, RAD, Eclipse 3.3 )
Download: Eclipse update site:
http://ucdetector.sourceforge.net/update

Quick start

Instead of clicking Shift+Ctrl+G (search references in workspace) all the time, follow the next steps:
  1. In the package explorer right click on one ore more projects, packages or classes
  2. Select the context menu: UCDetector/detect unnecessary code run UCDetector
  3. Check warnings in java editor and Problems View not found use private use default use protected use final test only few found
  4. Use the menu "Group By/Type" in Problems View
  5. Change code carefully. Use QuickFixes (right click on markers)
  6. Change preference "Detect code with max number of references" from 0 to 1, run UCDetector again
  7. Repeat step 1. to 5.

Really want to change code?

The problems found by UCDetector, are only suggestions. Before changing code, you should really know what you are doing! If UCDetector tells you, that there are no references your code still may be used by:

Change visibility may cause problems with inheritance, reflection, instantiation...

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

UCDetector markers

Change code, use QuickFixes!

After checking carefully all the possibilities above, maybe you decide to change your code. Click on the marker to see QuickFixes's to change code: It is possible to change several problems at once using quick fix dialog.

UCDetector QuickFix

Ignore code

// NO_UCD

/**
 * Class is only used by reflection.
 * Write a // NO_UCD comment at the end of the line.
 * This line will be ignored by UCDetector.
 */
public class BeanExample { // NO_UCD

@SuppressWarnings("ucd")

/**
 * Class is only used by reflection.
 * Add a @SuppressWarnings("ucd") annotation.
 * This class/method/field will be ignored by UCDetector.
 */
@SuppressWarnings("ucd")
public class BeanExample {

@UsedBy("reflection")

I don't like this one, but users asked for it:
If you want to "pollute" your code, you can use the @org.ucdetector.util.UsedBy annotation located inside ucdetector-annotations.jar which is inside org.ucdetector.source_x.y.z.zip.
/**
 * Class is only used by reflection.
 * Add a @SuppressWarnings("ucd") annotation.
 * This class/method/field will be ignored by UCDetector.
 */
@UsedBy("reflection")
public class BeanExample {

Settings for: Unhandled token in @SuppressWarnings

Set eclipse compiler setting "Unhandled token in '@SuppressWarnings'" to Ignore
To avoid eclipse Warnings "Unsupported @SuppressWarnings("ucd")"