Find dead class in Java with Eclipse - java

I am new ( and only person ) on old Java project. Couple guys have developed this before me. Is there any tool ( plugin for Eclipse would be nice ) which can find in project dead classes ( classes that are declared but they don't use anymore anywhere ?

You could use the Emma plugin to determine code coverage and look for the classes with 0% coverage after a full run.
To make sure before you remove classes, use the eclipse function that shows all references to the class in case it is used in exception handling.

Looks like similar question already asked on Stackoverfow check out the following links already asked on SO
How to find unused/dead code in java projects
Find unused classes in a Java Eclipse project
Check out the answers

http://eclipsenuggets.blogspot.com/2007/05/here-is-quick-way-to-eliminate-dead.html
This worked for me (although I tried it several years ago)

IntelliJ has a "Find Usages" that you can apply to classes, methods, strings - anything. Perhaps the Eclipse help can turn up such a thing.
Or maybe you should switch to IntelliJ.
IntelliJ can also generate UML that includes dependencies. Any class or package without a dependency would be a good candidate for removal. You'd get a quick visual that way.

Related

#Data from lombok in Android Studio doesn't work

I have proper dependencies
And lombok plugin was installed, so Android Studio know where generation was applied but i still got an error
Please can anyone give me idea what is happening?
EDIT:
from kotlin 1.7.20 with K2 compiler it is possible.
https://kotlinlang.org/docs/whatsnew1720.html#support-for-kotlin-k2-compiler-plugins
OLD:
Ok, I guess my problem somewhat solved. My project have mixed Kotlin\Java code, I found this closed issue in project lombok: https://github.com/projectlombok/lombok/issues/1169
Corresponding to this lombok cant work in Kotlin\Java code normal way cause reasons... and there is two solutions:
Multi module project where all Java code with lobmok separated from Kotlin code and java module should using only java compiler.
Use special plugin from Kotlin which in part solving issue https://kotlinlang.org/docs/lombok.html
Another dum-dum solution: drop lombok annotation on java class and then using some instruments delombok it.This way no javac will be required.

Get ClassNames acroos Java Projects

I need to develop a Tool for checking certain Java Code conventions for all the java classes present in a Java Project.
For one of the rules(i.e;Checking the Class Name Convention)I need to get all the Class Names given the Folder Name.Instead of parsing it line by line,can anybody suggest me a better way to do the same.
NOTE 1: Reflection is not an option because it doesn't work across java projects.I can not use build path as well since there would be many projects at run time for which i need to check the code conventions.
NOTE 2: Currently,I ma using eclipse IDE to build this,but in run time I am not even sure whether they would be using only eclipse IDE.Hence,when you suggest any eclipse plugin ,please bear this in mind.
Thanks in advance:)

Testing updated jar in project [duplicate]

We have a lot of jars which have been added over a period of years to the project and their usage has not been documented anywhere. I want to figure out references of any class in the jar in java or jsp files.
Now for our new jars we don't have this issue as we use Maven and it helps us maintain dependency etc much better. But I am trying to determine some of the old jars
Is there any way in Eclipse, or any other tool, to do this?
One way which I can think of:
You can use Relief to get a view of your whole java project. I haven't used it though, but have heard good things about it.
Update:
Finding unused jars used in an eclipse project

Eclipse find which files reference this jar

We have a lot of jars which have been added over a period of years to the project and their usage has not been documented anywhere. I want to figure out references of any class in the jar in java or jsp files.
Now for our new jars we don't have this issue as we use Maven and it helps us maintain dependency etc much better. But I am trying to determine some of the old jars
Is there any way in Eclipse, or any other tool, to do this?
One way which I can think of:
You can use Relief to get a view of your whole java project. I haven't used it though, but have heard good things about it.
Update:
Finding unused jars used in an eclipse project

How do you figure out with Eclipse which JARs depend on which one?

I've trying to use Eclipse JDT AST parsing classes. After including the initial JAR, and sorting out a couple more dependencies, it is with 7+ JARs and I still having NoClassDefFoundError exceptions. This situation arises whenever I'm trying to test libraries with little or no documentation. Trial and error seems a very dumb (and annoying) approach to solve this problem.
Is there a way to automatically sort this out using Eclipse?
Update: Later I found that adding all the JARs you have, and using Ctrl-T (to view/locate types), lets you manually locate the JAR. That was the solution that Google provided so far. Is there a better way?
If you refer to this SO question Finding unused jars used in an eclipse project, you also have:
ClassPathHelper, which can quickly focus on unresolved classes:
It automatically identifies orphan jars, blocked (obscured) classes, and much more.
The only limit is dependencies that are not defined in classes, e.g. in dependency injection framework configuration files.
I have found setting up a workspace exclusively for browsing the eclipse source code incredibly useful. In this manner, you can use PDE tools like the Plug-in Spy, bundle dependency analysis, browsing the documentation, etc much like you would your own plugin projects. I found this article at Vogella a very useful guide.
If you know which bundle your desired class is you can generate the transitive closure of dependencies by creating a new OSGi launch configuration, with just the single bundle selected. By hitting the Add Required button, you can see all bundles necessary to use the one you're interested in.
Edit:
From your question it wasn't clear as to the environment you want to run the compiler in. If you're interested in an embeddable Java compiler to be run outside of an OSGi environment, may I suggest Janino.
You could use a dependency analyzer like:
JarAnalyzer
This will parse a directory full of Jars and give you an XML output dependency map, for which there are several tools for displaying in either graphical or text form.

Categories

Resources