Start
Preferences
More
Releases
FAQ
Custom
License
Contact & Links

UCDetector UCDetector: Unnecessary Code Detector

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:
  • Unnecessary (dead) code
  • Code where the visibility could be changed to protected, default or private
  • Methods of fields, which can be final
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:
  • Download org.ucdetector_x.y.z.jar
  • Put org.ucdetector_x.y.z.jar into ECLIPSE_HOME/dropins directory
  • Restart Eclipse
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:
  • Reflection
  • Frameworks like Spring, Hibernate or Eclipse which declare dependencies in property files, xml files (extension-points) ...
  • Third party code, which is using your API
  • Jars in your workspace
  • To be continued...

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:
  • Delete code: When UCDetector tells you that there are no references
  • Move code: When UCDetector tells you that there is only 1 reference (change UCDetector preference "Detect code with max number of references" to 1
  • Change visibility: Use protected , default or private
  • Use final
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 "polute" 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")"

Last Update: 2013-10-22Jörg Spieler    Show profile of Jörg Spieler in LinkedInCopyright © 2013, by Jörg Spieler

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