Class ConstructorCallsOverridableMethodRule
- java.lang.Object
-
- net.sourceforge.pmd.properties.AbstractPropertySource
-
- net.sourceforge.pmd.lang.rule.AbstractRule
-
- net.sourceforge.pmd.lang.java.rule.AbstractJavaRule
-
- net.sourceforge.pmd.lang.java.rule.errorprone.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.properties.AbstractPropertySource
propertyDescriptors, propertyValuesByDescriptor
-
Fields inherited from interface net.sourceforge.pmd.Rule
VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, VIOLATION_SUPPRESS_XPATH_DESCRIPTOR
-
-
Constructor Summary
Constructors Constructor Description ConstructorCallsOverridableMethodRule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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(ASTMethodDeclaration 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, isSuppressed, 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, 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, deepCopy, deepCopyValuesTo, end, equals, getDescription, getExamples, getExternalInfoUrl, getLanguage, getMaximumLanguageVersion, getMessage, getMinimumLanguageVersion, getName, getParserOptions, getPriority, getPropertySourceType, getRuleChainVisits, getRuleClass, getRuleSetName, getSince, hashCode, isDeprecated, isDfa, isMultifile, isRuleChain, isTypeResolution, setDeprecated, setDescription, setDfa, setExternalInfoUrl, setLanguage, setMaximumLanguageVersion, setMessage, setMinimumLanguageVersion, setMultifile, setName, setPriority, setRuleClass, setRuleSetName, setSince, setTypeResolution, setUsesDFA, setUsesMultifile, setUsesTypeResolution, start, usesDFA, usesMultifile, usesRuleChain, usesTypeResolution
-
Methods inherited from class net.sourceforge.pmd.properties.AbstractPropertySource
copyPropertyDescriptors, copyPropertyValues, definePropertyDescriptor, dysfunctionReason, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, isPropertyOverridden, setProperty, 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.properties.PropertySource
definePropertyDescriptor, dysfunctionReason, getOverriddenPropertiesByPropertyDescriptor, getOverriddenPropertyDescriptors, getPropertiesByPropertyDescriptor, getProperty, getPropertyDescriptor, getPropertyDescriptors, hasDescriptor, ignoredProperties, isPropertyOverridden, setProperty, setProperty, useDefaultValueFor, usesDefaultValues
-
-
-
-
Method Detail
-
visit
public Object visit(ASTCompilationUnit node, Object data)
- Specified by:
visit
in interfaceJavaParserVisitor
- Overrides:
visit
in classAbstractJavaRule
-
visit
public Object visit(ASTEnumDeclaration node, Object data)
- Specified by:
visit
in interfaceJavaParserVisitor
- Overrides:
visit
in classAbstractJavaRule
-
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 interfaceJavaParserVisitor
- Overrides:
visit
in classAbstractJavaRule
-
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 interfaceJavaParserVisitor
- Overrides:
visit
in classAbstractJavaRule
-
visit
public Object visit(ASTMethodDeclaration 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 interfaceJavaParserVisitor
- Overrides:
visit
in classAbstractJavaRule
-
-