net.sourceforge.pmd.lang.java.rule.codesize

## Class NPathComplexityRule

- java.lang.Object
- - net.sourceforge.pmd.AbstractPropertySource
  - - net.sourceforge.pmd.lang.rule.AbstractRule
    - - net.sourceforge.pmd.lang.java.rule.AbstractJavaRule
      - - net.sourceforge.pmd.lang.java.rule.AbstractStatisticalJavaRule
        - - net.sourceforge.pmd.lang.java.rule.codesize.NPathComplexityRule

All Implemented Interfaces:
  JavaParserVisitor, ImmutableLanguage, StatisticalRule, PropertySource, Rule

    public class NPathComplexityRule
    extends AbstractStatisticalJavaRule

NPath complexity is a measurement of the acyclic execution paths through a function. See Nejmeh, Communications of the ACM Feb 1988 pp 188-200.

Author:
  Jason Bennett

### Field Summary

### Fields inherited from class net.sourceforge.pmd.AbstractPropertySource

`propertyDescriptors, propertyValuesByDescriptor`

### Fields inherited from interface net.sourceforge.pmd.lang.rule.stat.StatisticalRule

`MINIMUM_DESCRIPTOR, SIGMA_DESCRIPTOR, TOP_SCORE_DESCRIPTOR`

### Fields inherited from interface net.sourceforge.pmd.Rule

`VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR`

### Constructor Summary

Constructors
Constructor and Description
`NPathComplexityRule()`

### Method Summary

Methods
`Object[]` `getViolationParameters(DataPoint point)`
`static int` `sumExpressionComplexity(ASTExpression expr)` Calculate the boolean complexity of the given expression.
`Object` `visit(ASTConditionalExpression node, Object data)`
`Object` `visit(ASTDoStatement node, Object data)`
`Object` `visit(ASTForStatement node, Object data)`
`Object` `visit(ASTIfStatement node, Object data)`
`Object` `visit(ASTMethodDeclaration node, Object data)`
`Object` `visit(ASTReturnStatement node, Object data)`
`Object` `visit(ASTSwitchStatement node, Object data)`
`Object` `visit(ASTTryStatement node, Object data)`
`Object` `visit(ASTWhileStatement node, Object data)`
`Object` `visit(JavaNode node, Object data)`

### Methods inherited from class net.sourceforge.pmd.lang.java.rule.AbstractStatisticalJavaRule

`addDataPoint, apply`

### Methods inherited from class net.sourceforge.pmd.lang.java.rule.AbstractJavaRule

`getDeclaringType, importsPackage, isQualifiedName, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitAll`

### Methods inherited from class net.sourceforge.pmd.lang.rule.AbstractRule

`addExample, addRuleChainVisit, addRuleChainVisit, addViolation, addViolation, addViolation, addViolationWithMessage, addViolationWithMessage, addViolationWithMessage, deepCopyValuesTo, end, equals, getDescription, getExamples, getExternalInfoUrl, getLanguage, getMaximumLanguageVersion, getMessage, getMinimumLanguageVersion, getName, getParserOptions, getPriority, getRuleChainVisits, getRuleClass, getRuleSetName, getSince, hashCode, isDeprecated, setDeprecated, setDescription, setExternalInfoUrl, setLanguage, setMaximumLanguageVersion, setMessage, setMinimumLanguageVersion, setName, setPriority, setRuleClass, setRuleSetName, setSince, setUsesDFA, setUsesTypeResolution, start, usesDFA, usesRuleChain, usesTypeResolution`

### Methods inherited from class net.sourceforge.pmd.AbstractPropertySource

`copyPropertyDescriptors, copyPropertyValues, definePropertyDescriptor, dysfunctionReason, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, setProperty, useDefaultValueFor, usesDefaultValues`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.sourceforge.pmd.Rule

`addExample, addRuleChainVisit, addRuleChainVisit, end, getDescription, getExamples, getExternalInfoUrl, getLanguage, getMaximumLanguageVersion, getMessage, getMinimumLanguageVersion, getName, getParserOptions, getPriority, getRuleChainVisits, getRuleClass, getRuleSetName, getSince, isDeprecated, setDeprecated, setDescription, setExternalInfoUrl, setLanguage, setMaximumLanguageVersion, setMessage, setMinimumLanguageVersion, setName, setPriority, setRuleClass, setRuleSetName, setSince, setUsesDFA, setUsesTypeResolution, start, usesDFA, usesRuleChain, usesTypeResolution`

### Methods inherited from interface net.sourceforge.pmd.PropertySource

`definePropertyDescriptor, dysfunctionReason, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, setProperty, useDefaultValueFor, usesDefaultValues`

### Constructor Detail

#### NPathComplexityRule

    public NPathComplexityRule()

### Method Detail

#### visit

    public Object visit(ASTMethodDeclaration node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(JavaNode node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTIfStatement node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTWhileStatement node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTDoStatement node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTForStatement node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTReturnStatement node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTSwitchStatement node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTTryStatement node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### visit

    public Object visit(ASTConditionalExpression node,
               Object data)

Specified by:
  `visit` in interface `JavaParserVisitor`
Overrides:
  `visit` in class `AbstractJavaRule`

#### sumExpressionComplexity

    public static int sumExpressionComplexity(ASTExpression expr)

Calculate the boolean complexity of the given expression. NPath boolean complexity is the sum of && and || tokens. This is calculated by summing the number of children of the &&'s (minus one) and the children of the ||'s (minus one).

Note that this calculation applies to Cyclomatic Complexity as well.

Parameters:
  `expr` - control structure expression
Returns:
  complexity of the boolean expression

#### getViolationParameters

    public Object[] getViolationParameters(DataPoint point)

Specified by:
  `getViolationParameters` in interface `StatisticalRule`
Overrides:
  `getViolationParameters` in class `AbstractStatisticalJavaRule`