net.sourceforge.pmd.rules
Class AbstractPoorMethodCall

java.lang.Object
  extended by net.sourceforge.pmd.CommonAbstractRule
      extended by net.sourceforge.pmd.AbstractJavaRule
          extended by net.sourceforge.pmd.AbstractRule
              extended by net.sourceforge.pmd.rules.AbstractPoorMethodCall
All Implemented Interfaces:
JavaParserVisitor, Rule
Direct Known Subclasses:
UseIndexOfChar

public abstract class AbstractPoorMethodCall
extends AbstractRule

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 interface net.sourceforge.pmd.Rule
LOWEST_PRIORITY, PRIORITIES
 
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  java.lang.String[] methodNames()
          Return the names of all the methods we are scanning for, no brackets or argument types.
protected abstract  java.lang.String targetTypename()
          The name of the type the method will be invoked against.
 java.lang.Object visit(ASTVariableDeclaratorId node, java.lang.Object data)
          Method visit.
 
Methods inherited from class net.sourceforge.pmd.AbstractJavaRule
addViolation, addViolation, addViolation, addViolationWithMessage, 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, visit, visit, visit, visit, visitAll
 
Methods inherited from class net.sourceforge.pmd.CommonAbstractRule
addExample, addProperties, addProperty, addRuleChainVisit, asFixedMap, asFixedMap, end, equals, getBooleanProperties, getBooleanProperty, getBooleanProperty, getDescription, getDoubleProperties, getDoubleProperty, getDoubleProperty, getExample, getExamples, getExternalInfoUrl, getIntProperties, getIntProperty, getIntProperty, getMessage, getName, getPriority, getPriorityName, getProperties, getRuleChainVisits, getRuleClass, getRuleSetName, getSince, getStringProperties, getStringProperty, getStringProperty, getTypeProperties, getTypeProperty, hashCode, hasProperty, include, propertiesByName, propertyDescriptorFor, setDescription, setExternalInfoUrl, setInclude, setMessage, setName, setPriority, setProperties, setProperty, setRuleClass, setRuleSetName, setSince, setUsesDFA, setUsesTypeResolution, start, usesDFA, usesRuleChain, usesTypeResolution
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPoorMethodCall

public AbstractPoorMethodCall()
Method Detail

targetTypename

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

Returns:
String

methodNames

protected abstract java.lang.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 java.lang.Object visit(ASTVariableDeclaratorId node,
                              java.lang.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-2011 InfoEther. All Rights Reserved.