How to count the number of branches in a Java class

Is there a tool or a way to count the number of branches in a given Java class? For example, I want to count the number of branches in the following simple Java class:

public class Testt {

    public boolean getTest(int x) {
        if (x > 5) {
            return true;
        } else {
            return false;
        }
    }

    public int getTest1(int x) {
        int t = 0;
        if (x == 10) {
            t = 1;
        } else if (x == 8) {
            t = 3;
        } else {
            t = 11;
        }
        return t;
    }
}
+4
source share
1 answer

The term you are looking for is " cyclic complexity ."

Cyclomatic complexity is a software metric (measurement) used to indicate the complexity of a program. This is a quantitative measure of the number of linearly independent paths through a software source code.

If you use Eclipse as your development environment, there is a plugin called Eclipse Metrics that can provide such information.

+8
source

Source: https://habr.com/ru/post/1689748/


All Articles