Karlovsky120
Karlovsky120

Reputation: 6362

Automatically set method scope in eclipse

Is there a way I can automatically make Eclipse to inspect the scope of all methods and then correct it depending on it's use?

So if I had a public method which I only use in the current class it would be autmatically changed to private.

Upvotes: 2

Views: 268

Answers (3)

Bananeweizen
Bananeweizen

Reputation: 22080

You want to use the Unnecessary Code Detector plugin for Eclipse. It can find all classes, methods and fields which have a wider visibility than necessary and you can semi-automatically change this using the provided quick fixes.

Please be careful when doing so however, as the plugin can only analyze your code, but it doesn't know anything about implicit patterns, dependencies to currently not available sources, unused API methods in your code, reflection and so.

Upvotes: 3

classicjonesynz
classicjonesynz

Reputation: 4042

Maybe, I'm not really sure, but it wouldn't be specific to the Eclipse IDE (such as extensions, plugins and so forth).

You could look into some extensions with Apache Ant

Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.

Such as Extensible application-specific access modifiers for Java, it would require research on your part. There is stuff like PMD and Emma Code Coverage Reports for pretty indepth code analysis for concrete and dependences between methods and or classes (And then you could use the information provided to clean your code).

Upvotes: 0

Javier
Javier

Reputation: 12398

I think it is not possible with Eclipse (and if it were, it would have some corner cases, for instance, how would you distinguish unused but valid public methods from public methods that should be converted to private?).

If you are interested on a few methods, you can use find method references in Eclipse, and correct the scope if no references were found.

If you are interested on fixing a big source base, my tool of choice for that kind of things is Recoder, but you would have to write the analysis by yourself.

Upvotes: 0

Related Questions