net.sourceforge.pmd

Class AbstractRule

public abstract class AbstractRule extends JavaParserVisitorAdapter implements Rule

BSD-style license; for more info see http://pmd.sourceforge.net/license.html
Method Summary
voidaddExample(String example)
voidaddProperties(Properties properties)
voidaddProperty(String name, String value)
voidaddRuleChainVisit(String astNodeName)
protected voidaddViolation(Object data, SimpleNode node)
Adds a violation to the report.
protected voidaddViolation(Object data, SimpleNode node, String embed)
Adds a violation to the report.
protected voidaddViolation(Object data, Node node, Object[] args)
Adds a violation to the report.
protected voidaddViolationWithMessage(Object data, SimpleNode node, String msg)
Adds a violation to the report.
voidapply(List acus, RuleContext ctx)
protected static Map<String,PropertyDescriptor>asFixedMap(PropertyDescriptor[] descriptors)
protected static Map<String,PropertyDescriptor>asFixedMap(PropertyDescriptor descriptor)
booleanequals(Object o)
Test if rules are equals.
boolean[]getBooleanProperties(PropertyDescriptor descriptor)
booleangetBooleanProperty(PropertyDescriptor descriptor)
booleangetBooleanProperty(String name)
protected StringgetDeclaringType(SimpleNode node)
Gets the Image of the first parent node of type ASTClassOrInterfaceDeclaration or null
StringgetDescription()
double[]getDoubleProperties(PropertyDescriptor descriptor)
doublegetDoubleProperty(String name)
doublegetDoubleProperty(PropertyDescriptor descriptor)
StringgetExample()
Still used by the JDeveloper plugin
List<String>getExamples()
StringgetExternalInfoUrl()
int[]getIntProperties(PropertyDescriptor descriptor)
intgetIntProperty(String name)
intgetIntProperty(PropertyDescriptor descriptor)
StringgetMessage()
StringgetName()
intgetPriority()
StringgetPriorityName()
PropertiesgetProperties()
List<String>getRuleChainVisits()
StringgetRuleSetName()
String[]getStringProperties(PropertyDescriptor descriptor)
StringgetStringProperty(String name)
StringgetStringProperty(PropertyDescriptor descriptor)
Class[]getTypeProperties(PropertyDescriptor descriptor)
ClassgetTypeProperty(PropertyDescriptor descriptor)
inthashCode()
Return a hash code to conform to equality.
booleanhasProperty(String name)
static booleanimportsPackage(ASTCompilationUnit node, String packageName)
booleaninclude()
static booleanisQualifiedName(SimpleNode node)
protected Map<String,PropertyDescriptor>propertiesByName()
Return all the relevant properties for the receiver by overriding in subclasses as necessary.
PropertyDescriptorpropertyDescriptorFor(String propertyName)
Return the indicated property descriptor or null if not found.
voidsetBooleanProperty(String name, boolean flag)
voidsetDescription(String description)
voidsetExternalInfoUrl(String url)
voidsetInclude(boolean include)
voidsetMessage(String message)
voidsetName(String name)
voidsetPriority(int priority)
voidsetProperties(PropertyDescriptor descriptor, Object[] values)
voidsetProperty(PropertyDescriptor descriptor, Object value)
voidsetRuleSetName(String ruleSetName)
voidsetUsesDFA()
voidsetUsesTypeResolution()
booleanusesDFA()
booleanusesRuleChain()
booleanusesTypeResolution()
protected voidvisitAll(List acus, RuleContext ctx)

Method Detail

addExample

public void addExample(String example)

addProperties

public void addProperties(Properties properties)

Deprecated:

addProperty

public void addProperty(String name, String value)

Deprecated:

addRuleChainVisit

public void addRuleChainVisit(String astNodeName)

addViolation

protected final void addViolation(Object data, SimpleNode node)
Adds a violation to the report.

Parameters: ctx the RuleContext node the node that produces the violation

addViolation

protected final void addViolation(Object data, SimpleNode node, String embed)
Adds a violation to the report.

Parameters: ctx the RuleContext node the node that produces the violation embed a variable to embed in the rule violation message

addViolation

protected final void addViolation(Object data, Node node, Object[] args)
Adds a violation to the report.

Parameters: ctx the RuleContext node the node that produces the violation, may be null, in which case all line and column info will be set to zero args objects to embed in the rule violation message

addViolationWithMessage

protected final void addViolationWithMessage(Object data, SimpleNode node, String msg)
Adds a violation to the report.

Parameters: ctx the RuleContext node the node that produces the violation msg specific message to put in the report

apply

public void apply(List acus, RuleContext ctx)

asFixedMap

protected static Map<String,PropertyDescriptor> asFixedMap(PropertyDescriptor[] descriptors)

asFixedMap

protected static Map<String,PropertyDescriptor> asFixedMap(PropertyDescriptor descriptor)

equals

public boolean equals(Object o)
Test if rules are equals. Rules are equals if 1. they have the same implementation class 2. they have the same name 3. they have the same priority 4. they share the same properties/values

getBooleanProperties

public boolean[] getBooleanProperties(PropertyDescriptor descriptor)

getBooleanProperty

public boolean getBooleanProperty(PropertyDescriptor descriptor)

getBooleanProperty

public boolean getBooleanProperty(String name)

Deprecated: - use getBooleanProperty(PropertyDescriptor) instead

getDeclaringType

protected final String getDeclaringType(SimpleNode node)
Gets the Image of the first parent node of type ASTClassOrInterfaceDeclaration or null

Parameters: node the node which will be searched

getDescription

public String getDescription()

getDoubleProperties

public double[] getDoubleProperties(PropertyDescriptor descriptor)

getDoubleProperty

public double getDoubleProperty(String name)

Deprecated: - use getDoubleProperty(PropertyDescriptor) instead

getDoubleProperty

public double getDoubleProperty(PropertyDescriptor descriptor)

getExample

public String getExample()

Deprecated: use getExamples(), since we now support multiple examples

Still used by the JDeveloper plugin

getExamples

public List<String> getExamples()

getExternalInfoUrl

public String getExternalInfoUrl()

getIntProperties

public int[] getIntProperties(PropertyDescriptor descriptor)

getIntProperty

public int getIntProperty(String name)

Deprecated: - use getIntProperty(PropertyDescriptor) instead

getIntProperty

public int getIntProperty(PropertyDescriptor descriptor)

getMessage

public String getMessage()

getName

public String getName()

getPriority

public int getPriority()

getPriorityName

public String getPriorityName()

getProperties

public Properties getProperties()

Deprecated: - retrieve by name using getProperty or getProperties

getRuleChainVisits

public List<String> getRuleChainVisits()

getRuleSetName

public String getRuleSetName()

getStringProperties

public String[] getStringProperties(PropertyDescriptor descriptor)

getStringProperty

public String getStringProperty(String name)

Deprecated: - use getStringProperty(PropertyDescriptor) instead

getStringProperty

public String getStringProperty(PropertyDescriptor descriptor)

getTypeProperties

public Class[] getTypeProperties(PropertyDescriptor descriptor)

getTypeProperty

public Class getTypeProperty(PropertyDescriptor descriptor)

hashCode

public int hashCode()
Return a hash code to conform to equality. Try with a string.

hasProperty

public boolean hasProperty(String name)

Deprecated: - property values will be guaranteed available via default values

importsPackage

public static boolean importsPackage(ASTCompilationUnit node, String packageName)

include

public boolean include()

isQualifiedName

public static boolean isQualifiedName(SimpleNode node)

propertiesByName

protected Map<String,PropertyDescriptor> propertiesByName()
Return all the relevant properties for the receiver by overriding in subclasses as necessary.

Returns: Map

propertyDescriptorFor

public PropertyDescriptor propertyDescriptorFor(String propertyName)
Return the indicated property descriptor or null if not found.

Parameters: propertyName String

Returns: PropertyDescriptor

setBooleanProperty

public void setBooleanProperty(String name, boolean flag)

Deprecated: - use setProperty(PropertyDescriptor, Object) instead

Parameters: name flag

setDescription

public void setDescription(String description)

setExternalInfoUrl

public void setExternalInfoUrl(String url)

setInclude

public void setInclude(boolean include)

setMessage

public void setMessage(String message)

setName

public void setName(String name)

setPriority

public void setPriority(int priority)

setProperties

public void setProperties(PropertyDescriptor descriptor, Object[] values)

setProperty

public void setProperty(PropertyDescriptor descriptor, Object value)

setRuleSetName

public void setRuleSetName(String ruleSetName)

setUsesDFA

public void setUsesDFA()

setUsesTypeResolution

public void setUsesTypeResolution()

usesDFA

public boolean usesDFA()

usesRuleChain

public boolean usesRuleChain()

usesTypeResolution

public boolean usesTypeResolution()

visitAll

protected void visitAll(List acus, RuleContext ctx)