Groovy Documentation

org.codenarc.rule.generic
[Groovy] Class StatelessClassRule

java.lang.Object
  org.codenarc.rule.AbstractRule
      org.codenarc.rule.AbstractAstVisitorRule
          org.codenarc.rule.generic.StatelessClassRule

class StatelessClassRule
extends AbstractAstVisitorRule

Rule that checks for non-final fields on a class. The intent of this rule is to check a configured set of classes that should remain "stateless" and reentrant. One example might be Grails service classes, which are, by default, a singleton, and so they should be reentrant. DAO classes are also often kept stateless.

This rule ignores final fields (either instance or static). Fields that are static and non-final, however, do cause a violation.

This rule also ignores all classes annotated with the @Immutable transformation. See http://groovy.codehaus.org/Immutable+transformation.

You can configure this rule to ignore certain fields either by name or by type. This can be useful to ignore fields that hold references to (static) dependencies (such as DAOs or Service objects) or static configuration.

The ignoreFieldNames property specifies one or more (comma-separated) field names that should be ignored (i.e., that should not cause a rule violation). The name(s) may optionally include wildcard characters ('*' or '?'). You can add to the field names to be ignored by setting the (write-only) addIgnoreFieldNames property. This is a "special" property -- each call to setAddIgnoreFieldNames() adds to the existing ignoreFieldNames property value.

The ignoreFieldTypes property specifies one or more (comma-separated) field type names that should be ignored (i.e., that should not cause a rule violation). The type name(s) may optionally include wildcard characters ('*' or '?').

Note: The ignoreFieldTypes property matches the field type name as indicated in the field declaration, only including a full package specification IF it is included in the source code. For example, the field declaration BigDecimal value matches an ignoreFieldTypes value of BigDecimal, but not java.lang.BigDecimal.

There is one exception for the ignoreFieldTypes property: if the field is declared with a modifier/type of def, then the type resolves to java.lang.Object.

Authors:
Chris Mair
Hamlet D'Arcy
Version:
\$Revision: 553 \$ - \$Date: 2011-01-20 16:07:46 -0500 (Thu, 20 Jan 2011) \$


Field Summary
 
Fields inherited from class AbstractAstVisitorRule
DEFAULT_CONST_NAME, DEFAULT_FIELD_NAME, DEFAULT_TEST_CLASS_NAMES, DEFAULT_TEST_FILES, DEFAULT_VAR_NAME
 
Property Summary
Class astVisitorClass

String ignoreFieldNames

String ignoreFieldTypes

String name

int priority

 
Method Summary
void setAddToIgnoreFieldNames(String moreFieldNames)

Add more field names to the existing ignoreFieldNames property value.

 
Methods inherited from class AbstractAstVisitorRule
applyTo, getAstVisitor, shouldApplyThisRuleTo
 
Methods inherited from class AbstractRule
applyTo, applyTo, createViolation, createViolation, createViolationForImport, createViolationForImport, getImportsSortedByLineNumber, getName, getPriority, isReady, packageNameForImport, setName, setPriority, sourceLineAndNumberForImport, sourceLineAndNumberForImport, toString, validate
 

Property Detail

astVisitorClass

Class astVisitorClass


ignoreFieldNames

String ignoreFieldNames


ignoreFieldTypes

String ignoreFieldTypes


name

String name


priority

int priority


 
Method Detail

setAddToIgnoreFieldNames

void setAddToIgnoreFieldNames(String moreFieldNames)
Add more field names to the existing ignoreFieldNames property value.
Parameters:
moreFieldNames - - specifies one or more (comma-separated) field names that should be ignored (i.e., that should not cause a rule violation). The name(s) may optionally include wildcard characters ('*' or '?'). Any names specified here are joined to the existing ignoreFieldNames property value.


 

Groovy Documentation