code-complexity-plugin
code-complexity-plugin copied to clipboard
Plugin for Intellij IDEA to calculate complexity for your code right into the editor. Works for Java and Kotlin
Code Complexity plugin for IDEA
This plugin calculates code complexity metric right in the editor and shows the complexity in the hint next to the method/class. It's based on the Cognitive Complexity metric proposed by G. Ann Campbell in Cognitive Complexity - A new way of measuring understandability.
Works with Java, Kotlin, and Python.
Installation
-
Using IDE built-in plugin system:
Settings/Preferences > Plugins > Marketplace > Search for "code-complexity-plugin" > Install Plugin
-
Manually:
Download the latest release and install it manually using Settings/Preferences > Plugins > ⚙️ > Install plugin from disk...
Score
I chose 8 points as a medium complexity method and use it as 100%. This means that all the methods above 100% are good candidates for splitting/improving.
The formula is: percentage = points / 8 * 100
Configuration
You can find plugin configuration under Settings > Tools > Code Complexity
Inspection
There is an inspection added to support checking multiple files in your project.
All the supported languages of the plugin also work in inspection.
To run the inspection: Search everywhere > Run inspection by Name... > High code complexity
The inspection works only on methods currently and will find all the methods with the very high complexity score.
NOTE: You can enable inspection to work on the fly, but in this case it will do the same as code hints which are already in your editor - it will highlight the methods with the very high complexity score.
Release
- Update version in
gradle.properties - Update version and description in
CHANGELOG.md - Run
./gradlew publishPlugin - Push to repo with the proper tag
Plugin based on the IntelliJ Platform Plugin Template.


