Groovy Documentation

org.codenarc.rule.naming
Class FieldNameRule

java.lang.Object
  org.codenarc.rule.AbstractRule
      org.codenarc.rule.AbstractAstVisitorRule
          org.codenarc.rule.naming.FieldNameRule

class FieldNameRule
extends AbstractAstVisitorRule

Rule that verifies that the name of each field matches a regular expression. By default it checks that non-final field names start with a lowercase letter and contains only letters or numbers. By default, final field names start with an uppercase letter and contain only uppercase letters, numbers and underscores.

NOTE: This rule checks only regular fields of a class, not properties. In Groovy, properties are fields declared with no access modifier (public, protected, private). Thus, this rule only checks fields that specify an access modifier. For naming of regular properties, see PropertyNameRule.

The regex property specifies the default regular expression to validate a field name. It is required and cannot be null or empty. It defaults to '[a-z][a-zA-Z0-9]*'.

The finalRegex property specifies the regular expression to validate final field names. It is optional but defaults to '[A-Z][A-Z0-9_]*'.

The staticRegex property specifies the regular expression to validate static field names. It is optional and defaults to null, so that static fields that are non-final will be validated using regex.

The staticFinalRegex property specifies the regular expression to validate static final field names. It is optional and defaults to null, so that finalRegex is used by default.

The order of precedence for the regular expression properties is: staticFinalRegex, finalRegex, staticRegex and finally regex. In other words, the first regex in that list matching the modifiers for the field is the one that is applied for the field name validation.

The ignoreFieldNames property optionally 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 '?').

author:
Chris Mair
version:
$Revision: 204 $ - $Date: 2009-08-15 18:39:10 -0400 (Sat, 15 Aug 2009) $


Property Summary
Class astVisitorClass

String finalRegex

String ignoreFieldNames

String name

int priority

String regex

String staticFinalRegex

String staticRegex

 
Constructor Summary
FieldNameRule()

 
Method Summary
void validate()

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

Property Detail

astVisitorClass

Class astVisitorClass


finalRegex

String finalRegex


ignoreFieldNames

String ignoreFieldNames


name

String name


priority

int priority


regex

String regex


staticFinalRegex

String staticFinalRegex


staticRegex

String staticRegex


 
Constructor Detail

FieldNameRule

FieldNameRule()


 
Method Detail

validate

void validate()


 

Groovy Documentation