New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Cyclo metric should count conditions of for statements correctly #1483

Closed
oowekyala opened this Issue Nov 27, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@oowekyala
Copy link
Member

oowekyala commented Nov 27, 2018

E.g.

           class Foo {
                private static int compareImports(String import1, String import2) {
                    for (int i = 0; i != import1Tokens.length && i != import2Tokens.length; i++) {
                    }
                }
            }

The current implementation counts the complexity of the expression in the initializer int i = 0 instead of the boolean expression:

int boolCompFor = CycloMetric.booleanExpressionComplexity(node.getFirstDescendantOfType(ASTExpression.class));

@oowekyala oowekyala added this to the 6.10.0 milestone Nov 27, 2018

oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 27, 2018

@adangel

This comment has been minimized.

Copy link
Member

adangel commented Nov 28, 2018

Ah, I see: The fix is to use node.getFirstChildOfType(ASTExpression.class) instead of getFirstDescendantOfType.... Just for reference: This is now handled in ASTForStatement.getGuardExpressionNode().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment