Is there a tool to analyze the access layer of Java classes and methods?

In the Java code for our application, I'm sure there are many classes and methods that have public

access, but probably only need package level access.

What I would like to do is clean up our code on a package by package level, doing only what really needs to be seen outside of each package public

, as that should make it easier for other refactorings I want to do.

I was wondering if there is a tool available that could help me with this. Ideally, it analyzes all the code and generates a report on which classes and methods are publicly available, but only called from the same package.

The Find Usage option in Netbeans might help me with this, but running it manually for each class and method and parsing the output line by line will take all the time.

0


a source to share


3 answers


I used ProGuard which is a byte code manipulation tool to find dead code in the past. Here's an example in the ProGuard manual on how to use it. Note that there are a lot of other things in the tool as well, and this is not really a common use of it, but this is the only thing I know of that it is possible to scan an entire application for dead code.



Edit: So I misunderstood the question. Perhaps UCDetector is what you want. It claims to be capable of detecting "code in which visibility can be changed to protected, default, or private. However, it is tied to Eclipse. I just tried using UCDetector on my codebase and it seems to have made it work. Classes that could would reduce their visibility.

+3


a source


The cheapest (and most likely faster than single-pass tool setup) is to find and replace public class

in class

and in a similar manner for abstract

, final

and interface

. Recompile. Fix what breaks until it compiles.



+1


a source


The Netbeans SQE plugin can help.

It integrates FindBugs, PMD, CheckStyle and Lint4j into netbeans. This should include warnings that public methods can be made private and others.

0


a source







All Articles