1

I am looking for a way to find usage of qualified class names:

com.company.TheClass theInstance = new com.company.TheClass();

as opposed to imports:

import com.company.TheClass;
TheClass theInstance = new TheClass();

Is there a maven plugin that would help me find all usages of qualified class names against a java codabase?

edit:

Oleg kindly suggested the following link. It is very useful.

However I am just wondering how I could spot all fully qualified class name usage and not just "unnecessary" fully qualified name usage.

Some developer might for instance have for instance used private java.util.List list1; without the corresponding import statement.

This is not considered as unnecessary by pmd but is not good practice if there is no disambiguation needed....

balteo
  • 23,602
  • 63
  • 219
  • 412
  • Is your question about how to find these references in a project, or about why this exists? – Joffrey Feb 25 '14 at 10:31
  • Any chance you're using an IDE? For example, Eclipse has a file search facility that you provide the qualified name to and check only "*.java" files – Dan Temple Feb 25 '14 at 10:31
  • How many estimated qualified class names usages are there? Would a simple shell script (find + grep) help? –  Feb 25 '14 at 10:31
  • Depending on the acces you may not need to import anything, but otherway you need import , because tat is the java way http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html – Bogdan M. Feb 25 '14 at 10:32
  • My question is to find these references in a given codebase. There is also a requirement that I don't depend upon an IDE but rather that I use a maven plugin. – balteo Feb 25 '14 at 10:32
  • Fore example using a utility like checkstyle or other... – balteo Feb 25 '14 at 10:33
  • 1
    Are you looking for something like http://pmd.sourceforge.net/pmd-5.1.0/rules/java/imports.html#UnnecessaryFullyQualifiedName? – Oleg Estekhin Feb 25 '14 at 11:26
  • Thanks Oleg: spot on! – balteo Feb 25 '14 at 12:09
  • I have edited my post to reflect a limitation of this rule... – balteo Feb 25 '14 at 12:35

0 Answers0