net.sourceforge.pmd.rules

Class AbstractPoorMethodCall

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 judgement on any literal arguments we find in the subclass as well.

Version: $Revision: 5017 $

Author: Brian Remedios

Method Summary
static booleanisSingleCharAsString(String value)
Returns whether the value argument is a single character string.
protected abstract booleanisViolationArgument(int argIndex, String arg)
Returns whether the string argument at the stated position 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 StringtargetTypename()
The name of the type the method will be invoked against.
Objectvisit(ASTVariableDeclaratorId node, Object data)
Method visit.

Method Detail

isSingleCharAsString

public static boolean isSingleCharAsString(String value)
Returns whether the value argument is a single character string.

Parameters: value String

Returns: boolean

isViolationArgument

protected abstract boolean isViolationArgument(int argIndex, String arg)
Returns whether the string argument at the stated position being sent to the method is ok or not. Return true if you want to record the method call as a violation, false otherwise.

Parameters: argIndex int arg String

Returns: boolean

methodNames

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

Returns: String[]

targetTypename

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

Returns: String

visit

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

Parameters: node ASTVariableDeclaratorId data Object

Returns: Object

See Also: JavaParserVisitor