net.sourceforge.pmd.lang.java.rule.design

## Class ConstructorCallsOverridableMethodRule

- 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.design.ConstructorCallsOverridableMethodRule

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

      public final class ConstructorCallsOverridableMethodRule
      extends AbstractJavaRule

  Searches through all methods and constructors called from constructors. It marks as dangerous any call to overridable methods from non-private constructors. It marks as dangerous any calls to dangerous private constructors from non-private constructors.
  Author:
    CL Gilbert (dnoyeb@users.sourceforge.net) TODO match parameter types. Aggressively strips off any package names. Normal compares the names as is. TODO What about interface declarations which can have internal classes

- - ### Field Summary

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

      `propertyDescriptors, propertyValuesByDescriptor`

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

      `VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConstructorCallsOverridableMethodRule()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `visit(ASTClassOrInterfaceDeclaration node, Object data)` This check must be evaluated independently for each class.
    `Object` | `visit(ASTCompilationUnit node, Object data)`
    `Object` | `visit(ASTConstructorDeclaration node, Object data)` Non-private constructor's methods are added to a list for later safety evaluation.
    `Object` | `visit(ASTEnumDeclaration node, Object data)`
    `Object` | `visit(ASTMethodDeclarator node, Object data)` Create a MethodHolder to hold the method.

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

      `apply, 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, 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.PropertySource

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

- - ### Constructor Detail

    - #### ConstructorCallsOverridableMethodRule

          public ConstructorCallsOverridableMethodRule()

  - ### Method Detail

    - #### visit

          public Object visit(ASTCompilationUnit node,
                     Object data)

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

    - #### visit

          public Object visit(ASTEnumDeclaration node,
                     Object data)

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

    - #### visit

          public Object visit(ASTClassOrInterfaceDeclaration node,
                     Object data)

      This check must be evaluated independently for each class. Inner classes get their own EvalPackage in order to perform independent evaluation.
      Specified by:
        `visit` in interface `JavaParserVisitor`
      Overrides:
        `visit` in class `AbstractJavaRule`

    - #### visit

          public Object visit(ASTConstructorDeclaration node,
                     Object data)

      Non-private constructor's methods are added to a list for later safety evaluation. Non-private constructor's calls on private constructors are added to a list for later safety evaluation. Private constructors are added to a list so their safety to be called can be later evaluated.

      Note: We are not checking private constructor's calls on non-private constructors because all non-private constructors will be evaluated for safety anyway. This means we wont flag a private constructor as unsafe just because it calls an unsafe public constructor. We want to show only 1 instance of an error, and this would be 2 instances of the same error. TODO eliminate the redundancy
      Specified by:
        `visit` in interface `JavaParserVisitor`
      Overrides:
        `visit` in class `AbstractJavaRule`

    - #### visit

          public Object visit(ASTMethodDeclarator node,
                     Object data)

      Create a MethodHolder to hold the method. Store the MethodHolder in the Map as the key Store each method called by the current method as a List in the Map as the Object
      Specified by:
        `visit` in interface `JavaParserVisitor`
      Overrides:
        `visit` in class `AbstractJavaRule`

Copyright © 2002-2013 InfoEther. All Rights Reserved.