Groovy Documentation

org.codenarc.rule.grails
[Groovy] Class GrailsStatelessServiceRule

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

class GrailsStatelessServiceRule
extends StatelessClassRule

Rule that checks for non-final fields on a Grails service class. Grails service classes are, by default, singletons, and so they should be reentrant. In most cases, this implies (or at least encourages) that they should be stateless.

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

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.

The ignoreFieldNames property of this rule is preconfigured to ignore the standard Grails service configuration field names ('scope', 'transactional') and injected bean names ('dataSource', 'sessionFactory'), as well as all other field names ending with 'Service'.

This rule sets the default value of applyToFilesMatching to only match files under the 'grails-app/services' folder. You can override this with a different regular expression value if appropriate.

This rule also sets the default value of applyToClassNames to only match class names ending in 'Service'. You can override this with a different class name pattern (String) if appropriate.

Authors:
Chris Mair
Version:
\$Revision: 356 \$ - \$Date: 2010-08-31 05:59:37 -0400 (Tue, 31 Aug 2010) \$


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
String applyToClassNames

String applyToFilesMatching

String name

int priority

 
Constructor Summary
GrailsStatelessServiceRule()

 
Method Summary
 
Methods inherited from class StatelessClassRule
setAddToIgnoreFieldNames
 
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

applyToClassNames

String applyToClassNames


applyToFilesMatching

String applyToFilesMatching


name

String name


priority

int priority


 
Constructor Detail

GrailsStatelessServiceRule

GrailsStatelessServiceRule()


 

Groovy Documentation