Groovy Documentation

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

java.lang.Object
  org.codenarc.rule.generic.StatelessClassRule
      groovy.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.

This rule ignores non-static properties (i.e., no visibility modifier specified) declared with "def".

This rule also ignores fields annotated with the @Inject annotation.

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


Property Summary
String applyToClassNames

String applyToFilesMatching

String name

int priority

 
Constructor Summary
GrailsStatelessServiceRule()

 
Method Summary
protected boolean shouldIgnoreField(org.codehaus.groovy.ast.FieldNode fieldNode)

 

Property Detail

applyToClassNames

String applyToClassNames


applyToFilesMatching

String applyToFilesMatching


name

String name


priority

int priority


 
Constructor Detail

GrailsStatelessServiceRule

GrailsStatelessServiceRule()


 
Method Detail

shouldIgnoreField

@Override
protected boolean shouldIgnoreField(org.codehaus.groovy.ast.FieldNode fieldNode)


 

Groovy Documentation