@groovy.transform.CompileStatic class FieldDefinition extends AbstractMemberDefinition
Represents a field definition for domain class code generation. Fields in Groovy have an explicit access modifier and do not auto-generate getter/setter methods.
| Modifiers | Name | Description |
|---|---|---|
static enum |
FieldDefinition.AccessModifier |
Access modifier options for fields. |
static class |
FieldDefinition.Builder |
Builder pattern for creating FieldDefinition instances. |
| Type | Name and description |
|---|---|
FieldDefinition.AccessModifier |
accessModifier |
| Properties inherited from class | Properties |
|---|---|
class AbstractMemberDefinition |
BUILTIN_TYPES, blank, constraintStyle, maxSize, minSize, name, nullable, type |
| Constructor and description |
|---|
FieldDefinition() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
static Builder |
builder()Factory for the FieldDefinition.Builder. |
|
protected java.lang.String |
getMemberType() |
|
static FieldDefinition |
parse(java.lang.String fieldSpec)Parses a field specification string like "title:String" into a FieldDefinition. |
|
java.lang.String |
toDeclaration()Generates the field declaration line for the domain class. |
|
void |
validate() |
| Methods inherited from class | Name |
|---|---|
class AbstractMemberDefinition |
getMemberType, getRequiredImports, isBuiltinType, isValidTypeName, toAnnotations, toConstraintLine, toDeclaration, usesGrailsConstraints, usesJakartaAnnotations, validate |
Factory for the FieldDefinition.Builder. The return type is intentionally fully qualified:
PropertyDefinition declares an inner Builder of the same simple name, and groovydoc resolves
unqualified Builder references inconsistently between builds (depends on filesystem iteration
order). Keep this qualified to ensure groovydoc renders FieldDefinition.Builder reproducibly.
TODO(GROOVY-11954): Revisit and simplify the return type to Builder once Grails depends on
Groovy 4.0.32+ (also fixed in 5.0.6 and 6.0.0-alpha-1). The upstream fix corrects the shared
short-name resolution cache in SimpleGroovyClassDoc that causes this non-reproducibility,
so the workaround here will no longer be needed. As of writing, Grails pins groovy.version=4.0.31
and 4.0.32 has not yet been released to Maven Central. See:
https://issues.apache.org/jira/browse/GROOVY-11954 and https://github.com/apache/groovy/pull/2484.
Parses a field specification string like "title:String" into a FieldDefinition. Note: The access modifier must be set separately.
fieldSpec - the field specification (e.g., "title:String" or just "title")Generates the field declaration line for the domain class.