GeezerVison is showing github.com — [java] Cognitive Complexity Metric by borovikovd · Pull Request #3293 · pmd/pmd
Conversation
borovikovd
commented
May 23, 2021
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Describe the PR
This PR implements a Cognitive Complexity metric for Java. The work is based on a similar metric for Apex language: https://pmd.github.io/pmd/pmd_rules_apex_design.html#cognitivecomplexity. Tests and implementation have been ported + some additional modification have been done:
- Added handling for anonymous classes
- Added handling for lambdas
Accordingly to the spec, we should increase nesting level for such structures but structural complexity should stay the same (see state.increaseNestingLevelWithoutStructuralComplexity method).
Notes
-
ASTIfStatement handling seems to be a bit convoluted but it's due to the way how java AST parser handles else if - it's both one of the blocks of the parent if and a new ASTIfStatement at the same time.
-
Also, a method call handling is a bit tricky since there is no separate java node for this case and I had to do a bunch of checks in ASTPrimaryPrefix callback.
-
I hope this PR can be integrated quickly since we really want to start using this metric in our Java projects on regular basis :)
Related issues
Ready?
- Added unit tests for fixed bug/feature
- Passing all unit tests
- Complete build
./mvnw clean verify passes (checked automatically by github actions)
- Added (in-code) documentation (if needed)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your contribution! The metric looks fine, however, it should also have tests and documentation.
For tests:
For documentation, please add a section to this file
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
borovikovd reacted with thumbs up emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ghost
commented
May 26, 2021
•
edited by ghost
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
1 Message
|
| 📖 |
This changeset changes 0 violations,
introduces 758 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report |
| ✅ |
This changeset changes 0 violations,
introduces 765 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report |
Generated by 🚫 Danger
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@borovikovd No I think this looks fine. Thanks for your diligence on this!
If @adangel doesn't have any objections, I'll fix the outstanding conversation and merge this tomorrow, to include it in pmd 6.35.0.
|
borovikovd reacted with hooray emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
borovikovd reacted with laugh emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
borovikovd reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
adangel
adangel approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|