By default, IntelliJ IDEA shows all classes, methods, and other elements of the current file. To toggle the elements you want to show, click the corresponding buttons on the Structure tool window toolbar. to show class fields. to have protected class members shown in the tree.
CTRL + ALT + O ---> to remove the unused imports in windows. However, you can also change the keymap of "Optimize Imports" in settings. Show activity on this post. Show activity on this post. File/Settings/Inpsections/Imports and change "Unused import" to Error.
In IntelliJ, in a . java file, some unused code is greyed out indicating that the declared variable or function is never used. Unused imports are removed using Ctrl+Alt+O.
Settings will pop up
Settings closes
Search starts
I don't think this is doable. I suspect this feature is intentionally left out of IDEs because it can't be used safely the way that other "remove unused XXX" refactorings can.
The unused declarations IDEA (and AFAIK, NetBeans) looks for are for private members and local variables: things that are not accessible, even dynamically, from outside that class or scope. (Well, at least without doing things with Reflection or JVM hacking that you're not supposed to.) No matter what outside code does with your library, it won't cause those things to be used, because their scope is limited and the IDE can see all of it. The compiler can determine this by looking at just your code.
For classes, even if they don't have public
access, they can be referenced dynamically with Class.forName()
, and this actually happens in live code. So even if they're not apparently used within the code of your project, they might be used depending on what you or external code using your library runs. So the IDE can't guarantee that removing those classes won't change externally observable behavior.
Which is why I think IDEA just doesn't provide this behavior: it might give users false expectations of safety, and removing them is not a safe refactoring.
Maybe you should look into the Unused Symbol
inspection with the following settings:
I am not sure if this will answer your question but I used a tool in past as Fortify to run code review rules on the project, that precisely points to the unused imports, dead code, unused classes etc. It is a paid software but I am sure there will be some free plugins/software will be available for same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With