use of net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel in project pmd by pmd.
the class StdCyclomaticComplexityRule method visit.
@Override
public Object visit(ASTSwitchStatement node, Object data) {
Entry entry = entryStack.peek();
int childCount = node.jjtGetNumChildren();
int lastIndex = childCount - 1;
for (int n = 0; n < lastIndex; n++) {
Node childNode = node.jjtGetChild(n);
if (childNode instanceof ASTSwitchLabel) {
// default is generally not considered a decision (same as
// "else")
ASTSwitchLabel sl = (ASTSwitchLabel) childNode;
if (!sl.isDefault()) {
childNode = node.jjtGetChild(n + 1);
if (childNode instanceof ASTBlockStatement) {
entry.bumpDecisionPoints();
}
}
}
}
super.visit(node, data);
return data;
}
use of net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel in project pmd by pmd.
the class CycloBaseVisitor method visit.
@Override
public Object visit(ASTSwitchStatement node, Object data) {
int childCount = node.jjtGetNumChildren();
int lastIndex = childCount - 1;
for (int n = 0; n < lastIndex; n++) {
Node childNode = node.jjtGetChild(n);
if (childNode instanceof ASTSwitchLabel) {
// default is not considered a decision (same as "else")
ASTSwitchLabel sl = (ASTSwitchLabel) childNode;
if (!sl.isDefault()) {
// check the label is not empty
childNode = node.jjtGetChild(n + 1);
if (childNode instanceof ASTBlockStatement) {
((MutableInt) data).increment();
}
}
}
}
super.visit(node, data);
return data;
}
use of net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel in project pmd by pmd.
the class NpathBaseVisitor method visit.
@Override
public Object visit(ASTSwitchStatement node, Object data) {
// bool_comp of switch + sum(npath(case_range))
int boolCompSwitch = CycloMetric.booleanExpressionComplexity(node.getFirstChildOfType(ASTExpression.class));
int npath = 0;
int caseRange = 0;
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
JavaNode n = (JavaNode) node.jjtGetChild(i);
// Fall-through labels count as 1 for complexity
if (n instanceof ASTSwitchLabel) {
npath += caseRange;
caseRange = 1;
} else {
Integer complexity = (Integer) n.jjtAccept(this, data);
caseRange *= complexity;
}
}
// add in npath of last label
npath += caseRange;
return boolCompSwitch + npath;
}
use of net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel in project pmd by pmd.
the class InsufficientStringBufferDeclarationRule method getSwitchParent.
/**
* Determine which SwitchLabel we belong to inside a switch
*
* @param parentNode
* The parent node we're looking at
* @param lastNode
* The last node processed
* @return The parent node for the switch statement
*/
private static Node getSwitchParent(Node parentNode, Node lastNode) {
int allChildren = parentNode.jjtGetNumChildren();
ASTSwitchLabel label = null;
for (int ix = 0; ix < allChildren; ix++) {
Node n = parentNode.jjtGetChild(ix);
if (n instanceof ASTSwitchLabel) {
label = (ASTSwitchLabel) n;
} else if (n.equals(lastNode)) {
parentNode = label;
break;
}
}
return parentNode;
}
use of net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel in project pmd by pmd.
the class ConsecutiveLiteralAppendsRule method getSwitchParent.
/**
* Determine which SwitchLabel we belong to inside a switch
*
* @param parentNode
* The parent node we're looking at
* @param lastNode
* The last node processed
* @return The parent node for the switch statement
*/
private Node getSwitchParent(Node parentNode, Node lastNode) {
int allChildren = parentNode.jjtGetNumChildren();
Node result = parentNode;
ASTSwitchLabel label = null;
for (int ix = 0; ix < allChildren; ix++) {
Node n = result.jjtGetChild(ix);
if (n instanceof ASTSwitchLabel) {
label = (ASTSwitchLabel) n;
} else if (n.equals(lastNode)) {
result = label;
break;
}
}
return result;
}
Aggregations