How to prevent fully qualified names in Java code

Is it possible to check with checkstyle if the java project uses full names in the code. We want to prevent code like

if (org.apache.commons.lang3.StringUtils.isBlank(name)) { .... .... } 

and you want packages to be imported instead.

Are there other tools that can help us with this?

+6
source share
2 answers

As far as I know, Checkstyle cannot do this. However, there is a PMD rule called UnnecessaryFullyQualifiedName , which may be worth a look. IntelliJ plugins for PMD exist, such as QAPlug PMD , which can be downloaded for free.

Get ready to see a lot of false positives. For example, two classes that have the same simple name cannot be referenced without the full class name (for example, foo.A and bar.A ). It is also possible that the PMD does verify this case, it may be worth a try.

+2
source

FTR I just raised https://github.com/sevntu-checkstyle/sevntu.checkstyle/issues/462 about potential adding this to Checkstyle for a while .. contributions are welcome !; -)

+2
source

All Articles