Skip to content
Permalink
Browse files

Merge branch 'findbugs' into spotbugs

  • Loading branch information...
mebigfatguy committed Jun 30, 2019
2 parents 6d5412e + 2bbb07e commit 300ccf70fdd33b3b28c2c939b9dede6180a7289b
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/main/java/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java
@@ -23,6 +23,7 @@

import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.InstructionHandle;

import com.mebigfatguy.fbcontrib.utils.BugType;

@@ -121,6 +122,7 @@ public void visitMethod(final Method obj) {
BasicBlock bb = bbi.next();
Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb);
int lastSwitchTargetBlockLabel = Integer.MIN_VALUE;
int lastSwitchPosition = Integer.MIN_VALUE;
while (iei.hasNext()) {
Edge e = iei.next();
int edgeType = e.getType();
@@ -132,11 +134,16 @@ public void visitMethod(final Method obj) {
branches++;
}
} else if ((edgeType == EdgeTypes.SWITCH_EDGE) || (edgeType == EdgeTypes.SWITCH_DEFAULT_EDGE)) {
int nodeTarget = e.getTarget().getLabel();
if (nodeTarget != lastSwitchTargetBlockLabel) {
BasicBlock target = e.getTarget();
int nodeTarget = target.getLabel();

InstructionHandle firstIns = target.getFirstInstruction();
int pos = firstIns == null ? -1 : firstIns.getPosition();
if (nodeTarget != lastSwitchTargetBlockLabel && pos != lastSwitchPosition) {
branches++;
}
lastSwitchTargetBlockLabel = nodeTarget;
lastSwitchPosition = pos;
} else {
branches++;
}

0 comments on commit 300ccf7

Please sign in to comment.
You can’t perform that action at this time.