net.sourceforge.pmd
Class AbstractRule

java.lang.Object
  extended bynet.sourceforge.pmd.ast.JavaParserVisitorAdapter
      extended bynet.sourceforge.pmd.AbstractRule
All Implemented Interfaces:
JavaParserVisitor, Rule
Direct Known Subclasses:
AbstractInefficientZeroCheck, AbstractOptimizationRule, AbstractPoorMethodCall, AbstractSunSecureRule, AccessorClassGeneration, AppendCharacterWithChar, AssignmentInOperand, AssignmentToNonFinalStatic, AvoidCallingFinalize, AvoidCatchingThrowable, AvoidDeeplyNestedIfStmtsRule, AvoidDollarSigns, AvoidDuplicateLiteralsRule, AvoidFieldNameMatchingMethodName, AvoidFieldNameMatchingTypeName, AvoidNonConstructorMethodsWithClassName, AvoidReassigningParameters, AvoidUsingOctalValues, BeanMembersShouldSerializeRule, BigIntegerInstantiation, BooleanInstantiation, ClassNamingConventions, CloneMethodMustImplementCloneable, CloseResource, CompareObjectsWithEquals, ConfusingTernary, ConsecutiveLiteralAppends, ConstructorCallsOverridableMethod, CouplingBetweenObjects, CyclomaticComplexity, DaaRule, DFAGraphRule, DontImportJavaLang, DontImportSun, DoubleCheckedLocking, DuplicateImportsRule, DynamicXPathRule, ExceptionAsFlowControl, ExceptionSignatureDeclaration, IdempotentOperations, ImmutableField, ImportFromSamePackageRule, InefficientStringBuffering, InsufficientStringBufferDeclaration, JUnitAssertionsShouldIncludeMessage, JUnitTestsShouldContainAsserts, LooseCoupling, LooseCoupling, MethodNamingConventions, MethodWithSameNameAsEnclosingClass, MoreThanOneLogger, NonThreadSafeSingleton, NullAssignmentRule, OnlyOneReturnRule, OverrideBothEqualsAndHashcode, PositionalIteratorRule, PreserveStackTrace, SimplifyBooleanReturns, SingularField, StatisticalRule, StringConcatenationRule, StringInstantiation, StringToStringRule, SuspiciousHashcodeMethodName, SuspiciousOctalEscape, SymbolTableTestRule, TestClassWithoutTestCases, TooManyFields, UnnecessaryCaseChange, UnnecessaryCast, UnnecessaryConversionTemporary, UnnecessaryLocalBeforeReturn, UnnecessaryReturn, UnnecessaryWrapperObjectCreation, UnsynchronizedStaticDateFormatter, UnusedFormalParameterRule, UnusedImportsRule, UnusedLocalVariableRule, UnusedModifier, UnusedPrivateFieldRule, UnusedPrivateMethodRule, UselessAssignment, UselessOperationOnImmutable, UselessOverridingMethod, UselessStringValueOf, UseSingleton, UseStringBufferForStringAppends, UseStringBufferLength, VariableNamingConventions

public abstract class AbstractRule
extends JavaParserVisitorAdapter
implements Rule


Field Summary
protected  java.lang.String description
           
protected  java.lang.String example
           
protected  java.lang.String externalInfoUrl
           
protected  boolean include
           
protected  java.lang.String message
           
protected  java.lang.String name
           
protected  int priority
           
protected  java.util.Properties properties
           
protected  java.lang.String ruleSetName
           
protected  boolean usesDFA
           
protected  boolean usesTypeResolution
           
 
Fields inherited from interface net.sourceforge.pmd.Rule
LOWEST_PRIORITY, PRIORITIES
 
Constructor Summary
AbstractRule()
           
 
Method Summary
 void addProperties(java.util.Properties properties)
          Deprecated.  
 void addProperty(java.lang.String name, java.lang.String value)
          Deprecated.  
protected  void addViolation(java.lang.Object data, Node node, java.lang.Object[] args)
          Adds a violation to the report.
protected  void addViolation(java.lang.Object data, SimpleNode node)
          Adds a violation to the report.
protected  void addViolation(java.lang.Object data, SimpleNode node, java.lang.String embed)
          Adds a violation to the report.
protected  void addViolationWithMessage(java.lang.Object data, SimpleNode node, java.lang.String msg)
          Adds a violation to the report.
 void apply(java.util.List acus, RuleContext ctx)
           
protected static java.util.Map asFixedMap(PropertyDescriptor descriptor)
           
protected static java.util.Map asFixedMap(PropertyDescriptor[] descriptors)
           
 boolean equals(java.lang.Object o)
          Test if rules are equals.
 boolean[] getBooleanProperties(PropertyDescriptor descriptor)
           
 boolean getBooleanProperty(PropertyDescriptor descriptor)
           
 boolean getBooleanProperty(java.lang.String name)
          Deprecated. - use getBooleanProperty(PropertyDescriptor) instead
protected  java.lang.String getDeclaringType(SimpleNode node)
          Gets the Image of the first parent node of type ASTClassOrInterfaceDeclaration or null
 java.lang.String getDescription()
           
 double[] getDoubleProperties(PropertyDescriptor descriptor)
           
 double getDoubleProperty(PropertyDescriptor descriptor)
           
 double getDoubleProperty(java.lang.String name)
          Deprecated. - use getDoubleProperty(PropertyDescriptor) instead
 java.lang.String getExample()
           
 java.lang.String getExternalInfoUrl()
           
 int[] getIntProperties(PropertyDescriptor descriptor)
           
 int getIntProperty(PropertyDescriptor descriptor)
           
 int getIntProperty(java.lang.String name)
          Deprecated. - use getIntProperty(PropertyDescriptor) instead
 java.lang.String getMessage()
           
 java.lang.String getName()
           
 int getPriority()
           
 java.lang.String getPriorityName()
           
 java.util.Properties getProperties()
          Deprecated. - retrieve by name using getProperty or getProperties
 java.lang.String getRuleSetName()
           
 java.lang.String[] getStringProperties(PropertyDescriptor descriptor)
           
 java.lang.String getStringProperty(PropertyDescriptor descriptor)
           
 java.lang.String getStringProperty(java.lang.String name)
          Deprecated. - use getStringProperty(PropertyDescriptor) instead
 java.lang.Class[] getTypeProperties(PropertyDescriptor descriptor)
           
 java.lang.Class getTypeProperty(PropertyDescriptor descriptor)
           
 int hashCode()
          Return a hash code to conform to equality.
 boolean hasProperty(java.lang.String name)
          Deprecated. - property values will be guaranteed available via default values
static boolean importsPackage(ASTCompilationUnit node, java.lang.String packageName)
           
 boolean include()
           
static boolean isQualifiedName(SimpleNode node)
           
protected  java.util.Map propertiesByName()
          Return all the relevant properties for the receiver by overriding in subclasses as necessary.
 PropertyDescriptor propertyDescriptorFor(java.lang.String propertyName)
          Return the indicated property descriptor or null if not found.
 void setBooleanProperty(java.lang.String name, boolean flag)
          Deprecated. - use setProperty(PropertyDescriptor, Object) instead
 void setDescription(java.lang.String description)
           
 void setExample(java.lang.String example)
           
 void setExternalInfoUrl(java.lang.String url)
           
 void setInclude(boolean include)
           
 void setMessage(java.lang.String message)
           
 void setName(java.lang.String name)
           
 void setPriority(int priority)
           
 void setProperties(PropertyDescriptor descriptor, java.lang.Object[] values)
           
 void setProperty(PropertyDescriptor descriptor, java.lang.Object value)
           
 void setRuleSetName(java.lang.String ruleSetName)
           
 void setUsesDFA()
           
 void setUsesTypeResolution()
           
 boolean usesDFA()
           
 boolean usesTypeResolution()
           
protected  void visitAll(java.util.List acus, RuleContext ctx)
           
 
Methods inherited from class net.sourceforge.pmd.ast.JavaParserVisitorAdapter
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

properties

protected java.util.Properties properties

message

protected java.lang.String message

description

protected java.lang.String description

example

protected java.lang.String example

ruleSetName

protected java.lang.String ruleSetName

include

protected boolean include

usesDFA

protected boolean usesDFA

usesTypeResolution

protected boolean usesTypeResolution

priority

protected int priority

externalInfoUrl

protected java.lang.String externalInfoUrl
Constructor Detail

AbstractRule

public AbstractRule()
Method Detail

asFixedMap

protected static java.util.Map asFixedMap(PropertyDescriptor[] descriptors)

asFixedMap

protected static java.util.Map asFixedMap(PropertyDescriptor descriptor)

getRuleSetName

public java.lang.String getRuleSetName()
Specified by:
getRuleSetName in interface Rule

setRuleSetName

public void setRuleSetName(java.lang.String ruleSetName)
Specified by:
setRuleSetName in interface Rule

getDescription

public java.lang.String getDescription()
Specified by:
getDescription in interface Rule

setDescription

public void setDescription(java.lang.String description)
Specified by:
setDescription in interface Rule

getExample

public java.lang.String getExample()
Specified by:
getExample in interface Rule

setExample

public void setExample(java.lang.String example)
Specified by:
setExample in interface Rule

hasProperty

public boolean hasProperty(java.lang.String name)
Deprecated. - property values will be guaranteed available via default values

Specified by:
hasProperty in interface Rule

addProperty

public void addProperty(java.lang.String name,
                        java.lang.String value)
Deprecated.  

Specified by:
addProperty in interface Rule

addProperties

public void addProperties(java.util.Properties properties)
Deprecated.  

Specified by:
addProperties in interface Rule

getDoubleProperties

public double[] getDoubleProperties(PropertyDescriptor descriptor)

getDoubleProperty

public double getDoubleProperty(java.lang.String name)
Deprecated. - use getDoubleProperty(PropertyDescriptor) instead

Specified by:
getDoubleProperty in interface Rule

getDoubleProperty

public double getDoubleProperty(PropertyDescriptor descriptor)

getIntProperties

public int[] getIntProperties(PropertyDescriptor descriptor)

getIntProperty

public int getIntProperty(java.lang.String name)
Deprecated. - use getIntProperty(PropertyDescriptor) instead

Specified by:
getIntProperty in interface Rule

getIntProperty

public int getIntProperty(PropertyDescriptor descriptor)

getTypeProperties

public java.lang.Class[] getTypeProperties(PropertyDescriptor descriptor)

getTypeProperty

public java.lang.Class getTypeProperty(PropertyDescriptor descriptor)

getBooleanProperties

public boolean[] getBooleanProperties(PropertyDescriptor descriptor)

getBooleanProperty

public boolean getBooleanProperty(PropertyDescriptor descriptor)

getBooleanProperty

public boolean getBooleanProperty(java.lang.String name)
Deprecated. - use getBooleanProperty(PropertyDescriptor) instead

Specified by:
getBooleanProperty in interface Rule

setBooleanProperty

public void setBooleanProperty(java.lang.String name,
                               boolean flag)
Deprecated. - use setProperty(PropertyDescriptor, Object) instead

Parameters:
name -
flag -

getStringProperties

public java.lang.String[] getStringProperties(PropertyDescriptor descriptor)

getStringProperty

public java.lang.String getStringProperty(java.lang.String name)
Deprecated. - use getStringProperty(PropertyDescriptor) instead

Specified by:
getStringProperty in interface Rule

getStringProperty

public java.lang.String getStringProperty(PropertyDescriptor descriptor)

setProperty

public void setProperty(PropertyDescriptor descriptor,
                        java.lang.Object value)

setProperties

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

getName

public java.lang.String getName()
Specified by:
getName in interface Rule

setName

public void setName(java.lang.String name)
Specified by:
setName in interface Rule

getMessage

public java.lang.String getMessage()
Specified by:
getMessage in interface Rule

setMessage

public void setMessage(java.lang.String message)
Specified by:
setMessage in interface Rule

getExternalInfoUrl

public java.lang.String getExternalInfoUrl()
Specified by:
getExternalInfoUrl in interface Rule

setExternalInfoUrl

public void setExternalInfoUrl(java.lang.String url)
Specified by:
setExternalInfoUrl in interface Rule

equals

public boolean equals(java.lang.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


hashCode

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


apply

public void apply(java.util.List acus,
                  RuleContext ctx)
Specified by:
apply in interface Rule

getProperties

public java.util.Properties getProperties()
Deprecated. - retrieve by name using getProperty or getProperties

Specified by:
getProperties in interface Rule

include

public boolean include()
Specified by:
include in interface Rule

setInclude

public void setInclude(boolean include)
Specified by:
setInclude in interface Rule

getPriority

public int getPriority()
Specified by:
getPriority in interface Rule

getPriorityName

public java.lang.String getPriorityName()
Specified by:
getPriorityName in interface Rule

setPriority

public void setPriority(int priority)
Specified by:
setPriority in interface Rule

setUsesDFA

public void setUsesDFA()
Specified by:
setUsesDFA in interface Rule

usesDFA

public boolean usesDFA()
Specified by:
usesDFA in interface Rule

setUsesTypeResolution

public void setUsesTypeResolution()
Specified by:
setUsesTypeResolution in interface Rule

usesTypeResolution

public boolean usesTypeResolution()
Specified by:
usesTypeResolution in interface Rule

visitAll

protected void visitAll(java.util.List acus,
                        RuleContext ctx)

addViolation

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

Parameters:
node - the node that produces the violation

addViolationWithMessage

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

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

addViolation

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

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

addViolation

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

Parameters:
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

getDeclaringType

protected final java.lang.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

isQualifiedName

public static boolean isQualifiedName(SimpleNode node)

importsPackage

public static boolean importsPackage(ASTCompilationUnit node,
                                     java.lang.String packageName)

propertiesByName

protected java.util.Map propertiesByName()
Return all the relevant properties for the receiver by overriding in subclasses as necessary.

Returns:
Map

propertyDescriptorFor

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

Specified by:
propertyDescriptorFor in interface Rule
Parameters:
propertyName - String
Returns:
PropertyDescriptor


Copyright © 2002-2006 InfoEther. All Rights Reserved.