public final class NPathComplexityCheck extends AbstractCheck
Modifier and Type | Class and Description |
---|---|
private static class |
NPathComplexityCheck.TokenEnd
Coordinates of token end.
|
private static class |
NPathComplexityCheck.Values
Class that store range value and expression value.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
branchVisited
True, when branch is visited, but not leaved.
|
private java.math.BigInteger |
currentRangeValue
NP value for current range.
|
private static int |
DEFAULT_MAX
Default allowed complexity.
|
private java.util.Deque<java.lang.Integer> |
expressionValues
Stack of NP values for expressions.
|
private static java.math.BigInteger |
INITIAL_VALUE
The initial current value.
|
private java.util.Deque<java.lang.Boolean> |
isAfterValues
Stack of belongs to range values for question operator.
|
private int |
max
Threshold to report error for.
|
static java.lang.String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
private NPathComplexityCheck.TokenEnd |
processingTokenEnd
Range of the last processed expression.
|
private java.util.Deque<java.math.BigInteger> |
rangeValues
Stack of NP values for ranges.
|
Constructor and Description |
---|
NPathComplexityCheck() |
Modifier and Type | Method and Description |
---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
private static int |
countCaseTokens(DetailAST ast)
Counts number of case tokens subject to a case group token.
|
private static int |
countConditionalOperators(DetailAST ast)
Calculates number of conditional operators, including inline ternary operatior, for a token.
|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
private static DetailAST |
getLastToken(DetailAST ast)
Finds a leaf, which is the most distant from the root.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
private void |
leaveAddingConditional()
Leaves catch.
|
private void |
leaveBranch()
Leaves else, default or case group tokens.
|
private void |
leaveConditional()
Leaves while, do, for, if, ternary (?::), return or switch.
|
private void |
leaveMethodDef(DetailAST ast)
Process the end of a method definition.
|
private void |
leaveMultiplyingConditional()
Leaves try.
|
void |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
private void |
leaveUnitaryOperator()
Leaves ternary operator (?:) and return tokens.
|
private NPathComplexityCheck.Values |
popValue()
Pops values from both stack of expression values and stack of range values.
|
private void |
pushValue(java.lang.Integer expressionValue)
Pushes the current range value on the range value stack.
|
void |
setMax(int max)
Set the maximum threshold allowed.
|
private void |
visitConditional(DetailAST ast,
int basicBranchingFactor)
Visits if, while, do-while, for and switch tokens - all of them have expression in
parentheses which is used for calculation.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
private void |
visitUnitaryOperator(DetailAST ast,
int basicBranchingFactor)
Visits ternary operator (?:) and return tokens.
|
destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public static final java.lang.String MSG_KEY
private static final int DEFAULT_MAX
private static final java.math.BigInteger INITIAL_VALUE
private final java.util.Deque<java.math.BigInteger> rangeValues
private final java.util.Deque<java.lang.Integer> expressionValues
private final java.util.Deque<java.lang.Boolean> isAfterValues
private final NPathComplexityCheck.TokenEnd processingTokenEnd
private java.math.BigInteger currentRangeValue
private int max
private boolean branchVisited
public void setMax(int max)
max
- the maximum thresholdpublic int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void beginTree(DetailAST rootAST)
AbstractCheck
beginTree
in class AbstractCheck
rootAST
- the root of the treepublic void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processpublic void leaveToken(DetailAST ast)
AbstractCheck
leaveToken
in class AbstractCheck
ast
- the token leavingprivate void visitConditional(DetailAST ast, int basicBranchingFactor)
ast
- visited token.basicBranchingFactor
- default number of branches added.private void visitUnitaryOperator(DetailAST ast, int basicBranchingFactor)
ast
- visited token.basicBranchingFactor
- number of branches inherently added by this token.private void leaveUnitaryOperator()
private void leaveConditional()
private void leaveBranch()
private void leaveMethodDef(DetailAST ast)
ast
- the token type representing the method definitionprivate void leaveAddingConditional()
private void pushValue(java.lang.Integer expressionValue)
expressionValue
- value of expression calculated for current token.private NPathComplexityCheck.Values popValue()
private void leaveMultiplyingConditional()
private static int countConditionalOperators(DetailAST ast)
ast
- inspected token.private static DetailAST getLastToken(DetailAST ast)
ast
- the root of tree.private static int countCaseTokens(DetailAST ast)
ast
- case group token.