UCDetector: Unnecessary Code Detector
Select menu: Window/Preferences.../UCDetector
Source folders, Packages, Classes, Methods, Fields
It is possible to ignore java elements (and all its children),
which should not be checked by UCDetector. A simple regular expression is used:
You can enter more than 1 entry, using the separator ","
- All ignore filters are "case sensitive"
- ?: Match one character
- *: Match 0 or more characters
Classes implementing or extendening mentioned class or interface will be ignored during detection. Full class name necessary.
Code with annotations
Code marked with these annotations, will be ignored during detection (full class name recommended). Use class name without @.
@UsedBy is automatically excluded, see also ignore code
Classes containing string:
Classes containing one of this strings, will be ignored during detection - usefull for generated code.
Be careful! Entering 'class' will exclude all classes!
Ignore bean methods:
Ignore methods, which use the java bean convention. For example
public String getName();
public void setName(String name);
public boolean isValid();
Ignore code with javadoc @deprecated or annotation @Deprecated.
Ignore code with 'NO_UCD' comments or @SuppressWarnings("ucd")
Ignore UCDetector specific tags/annotions. Useful when running a full detection, to verify if tags/annotations are still ok.
What to detect
Detect code with max number of references:
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
In classes, in methods, in fields:
Select how problems should 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:
Classes: Select error level for classes
Methods: Select error level for methods
Fields: Select error level for fields
Detect code only called by tests
Markers are created when a class, method or filed is only called by test code.
Test code means:
- Class name ends with "Test"
- Source folder name contains "test" or "junit"
- Method is a JUnit 3 test method:
public void testName()
@org.junit.Test annotations are ignored.
Search class names in text files:
Select file extension, which should be searched for class name.
For example "*.xml,*.jsp"
Use full qualified class name :
The character before and after the match is included in search.
Searching for "Application" will NOT match "MyApplication" neither
Searching for "Application" will match:
- "org.ucdetector.example_1.Application" and
For nested classes use $ as separator: org.ucdetector.example.Application$NestedClass
File name pattern to search:
If a class is found by text search, this class will have NO markers.
Even for unused methods or fields!
It is possible to add a file pattern. Full qualified class names (org.ucdetector.Example)
found in this files will get no marker for "0 references found". But text
search is slow, if there are many text files!
Possible use of final
for methods (don't override methods):
This option will create markers for methods, which could be
This are methods, which:
Possible use of final
for fields (read-only fields):
This option will create markers for fields, which could be
This are fields, which have no write access.
- Don't implement interfaces
- Don't override methods
- Are not overridden
- Methods in classes, which do not extend other classes
Maybe this rules are not OK for you! Anyway: Apply changes for this rule carefully.
Reduce visibility to protected or
In some cases this may cause compile errors
for classes, if there is code like this:
Select error level for visibility. This option will create markers for code
which could be protected, default or
This is code, which has only references in same package or same class.
For more details, check bug:
Wrong default visibility marker for classes - ID: 2539795
Don't care about warning 'Access to enclosing type':
See screenshot for eclipse warnings: Preferences, Java, Compiler Warnings: Code style, 'access to a non-accessible member of an enclosing type'
It is possible to create html, xml and text reports.
Enter directory name, to create reports.
To get links to the java source locations (code pointers), copy and paste text report to Eclipse 'Java Stack Trace Console'.
Max class cycle size:
For cycle detection you can choose the "max cycle size". If there are many
cycles in your code, a big number here makes cycle detection very slow!