net.sourceforge.pmd.lang.java.rule
Class AbstractPoorMethodCall

java.lang.Object
  extended by net.sourceforge.pmd.AbstractPropertySource
      extended by net.sourceforge.pmd.lang.rule.AbstractRule
          extended by net.sourceforge.pmd.lang.java.rule.AbstractJavaRule
              extended by net.sourceforge.pmd.lang.java.rule.AbstractPoorMethodCall
All Implemented Interfaces:
JavaParserVisitor, ImmutableLanguage, PropertySource, Rule
Direct Known Subclasses:
UseIndexOfCharRule

public abstract class AbstractPoorMethodCall
extends AbstractJavaRule

Detects and flags the occurrences of specific method calls against an instance of a designated class. I.e. String.indexOf. The goal is to be able to suggest more efficient/modern ways of implementing the same function. Concrete subclasses are expected to provide the name of the target class and an array of method names that we are looking for. We then pass judgment on any literal arguments we find in the subclass as well.

Version:
$Revision$
Author:
Brian Remedios

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
AbstractPoorMethodCall()
           
 
Method Summary
protected abstract  boolean isViolationArgument(Node arg)
          Returns whether the node being sent to the method is OK or not.
protected abstract  String[] methodNames()
          Return the names of all the methods we are scanning for, no brackets or argument types.
protected abstract  String targetTypename()
          The name of the type the method will be invoked against.
 Object visit(ASTVariableDeclaratorId node, Object data)
          Method visit.
 
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, 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

AbstractPoorMethodCall

public AbstractPoorMethodCall()
Method Detail

targetTypename

protected abstract String targetTypename()
The name of the type the method will be invoked against.

Returns:
String

methodNames

protected abstract String[] methodNames()
Return the names of all the methods we are scanning for, no brackets or argument types.

Returns:
String[]

isViolationArgument

protected abstract boolean isViolationArgument(Node arg)
Returns whether the node being sent to the method is OK or not. Return true if you want to record the method call as a violation.

Parameters:
arg - the node to inspect
Returns:
boolean

visit

public Object visit(ASTVariableDeclaratorId node,
                    Object data)
Method visit.

Specified by:
visit in interface JavaParserVisitor
Overrides:
visit in class AbstractJavaRule
Parameters:
node - ASTVariableDeclaratorId
data - Object
Returns:
Object
See Also:
JavaParserVisitor.visit(ASTVariableDeclaratorId, Object)


Copyright © 2002-2015 InfoEther. All Rights Reserved.