Eclipse was smart about this; IntelliJ not yet. Of course if a function is unused (and untested, I guess I should feel bad for that - even if it's just returning a simple variable, or implementing someone else's interface) but public, it may be used elsewhere. Looking under Inspections and searching for "unused," I don't see visibility settings. Does this granularity exist?
If you want to highlight unused public methods, please enable the "Settings|Inspections|Declaration redundancy|Unused declaration" global inspection.
If you want to highlight unused private methods, please enable the "Settings|Inspections|Declaration redundancy|Unused symbol" local inspection.
So, if you want to highlight unused private members, but do not highlight unused public members, turn off "Unused declaration" and turn on "Unused symbol".
Source
I've just tested it using IDEA 13.1.4, and it worked exactly as described.
as of IntelliJ IDEA 2017.3.4 (and probably earlier versions), the corresponding setting is:
File | Settings | Editor | Code Style | Inspections | Kotlin | Redundant constructs | Unused symbol
documentation:
This inspection reports classes, functions or properties in the specified inspection scope that are not used or not reachable from entry points.
There is no setting for Unused declaration anymore, so this setting is not for private
and public
symbols alike.
Instead of completely turning off warnings about unused symbols, you could use an annotation (possibly defined by yourself), for example @PublicApi
, to mark all function sand classes that you do not want to get warnings for. You then have to add this annotation as an entry point under:
File | Settings | Editor | Code Style | Inspections | Kotlin | Redundant constructs | Unused symbol | Options | Annotations...
You may have to restart the IDE after that.
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