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;
}
}
The term you are looking for is "cyclomatic complexity".
Cyclomatic complexity is a software metric (measurement), used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code.
If you are using Eclipse as your IDE there is a plugin called Eclipse Metrics that can give this kind of information.
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