Package org.codehaus.groovy.transform
Class BuilderASTTransformation.AbstractBuilderStrategy
java.lang.Object
org.codehaus.groovy.transform.BuilderASTTransformation.AbstractBuilderStrategy
- All Implemented Interfaces:
BuilderASTTransformation.BuilderStrategy
- Direct Known Subclasses:
DefaultStrategy,ExternalStrategy,InitializerStrategy,SimpleStrategy
- Enclosing class:
- BuilderASTTransformation
public abstract static class BuilderASTTransformation.AbstractBuilderStrategy
extends Object
implements BuilderASTTransformation.BuilderStrategy
Base class for builder generation strategies.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classHolds information about a builder property. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckKnownField(BuilderASTTransformation transform, AnnotationNode anno, String name, List<FieldNode> fields) Reports an error when no field infieldsis namedname.protected voidcheckKnownProperty(BuilderASTTransformation transform, AnnotationNode anno, String name, List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> properties) Reports an error whennameis not a property inproperties.getFields(BuilderASTTransformation transform, AnnotationNode anno, ClassNode buildee) Returns the property fields the builder should see.protected booleangetIncludeExclude(BuilderASTTransformation transform, AnnotationNode anno, ClassNode cNode, List<String> excludes, List<String> includes) Fillsexcludesandincludesfromanno.protected static List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo>getPropertyInfoFromBeanInfo(ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames) Lists writable, non-hidden JavaBean properties ofcNodeviaIntrospector.protected static List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo>Lists instance property fields ofcNode, skipping internal names.protected static List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo>getPropertyInfoFromClassNode(ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames) Lists instance property fields ofcNode.getPropertyInfoFromClassNode(BuilderASTTransformation transform, AnnotationNode anno, ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames, boolean allProperties) Lists properties ofcNode, then property fields fromgetFields(org.codehaus.groovy.transform.BuilderASTTransformation, org.codehaus.groovy.ast.AnnotationNode, org.codehaus.groovy.ast.ClassNode)whose names were not already seen.getPropertyInfos(BuilderASTTransformation transform, AnnotationNode anno, ClassNode buildee, List<String> excludes, List<String> includes, boolean allNames, boolean allProperties) Lists the properties the builder should copy.protected StringgetSetterName(String prefix, String fieldName) Builds a setter name.protected booleanunsupportedAttribute(BuilderASTTransformation transform, AnnotationNode anno, String memberName) ReportsmemberNamewhen this strategy does not support it.protected booleanunsupportedAttribute(BuilderASTTransformation transform, AnnotationNode anno, String memberName, String extraMessage) Reports an error whenmemberNameis set to something other than the undefined marker.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.transform.BuilderASTTransformation.BuilderStrategy
build
-
Constructor Details
-
AbstractBuilderStrategy
public AbstractBuilderStrategy()
-
-
Method Details
-
getPropertyInfoFromClassNode
protected static List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> getPropertyInfoFromClassNode(ClassNode cNode, List<String> includes, List<String> excludes) Lists instance property fields ofcNode, skipping internal names. Same as the four-argument form withallNamesfalse.- Parameters:
cNode- class whose property fields are collectedincludes- names to keep; an empty or null list keeps every name that is not excludedexcludes- names to drop, or null- Returns:
- the matching properties, in field order
-
getPropertyInfoFromClassNode
protected static List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> getPropertyInfoFromClassNode(ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames) Lists instance property fields ofcNode. A name inexcludesis dropped. Whenincludesis non-empty, a name absent from it is dropped. WhenallNamesis false, an internal name is dropped as well.- Parameters:
cNode- class whose property fields are collectedincludes- names to keep; empty or null does not filterexcludes- names to drop, or nullallNames-trueto keep internal names- Returns:
- the matching properties, in field order
-
getPropertyInfoFromBeanInfo
protected static List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> getPropertyInfoFromBeanInfo(ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames) Lists writable, non-hidden JavaBean properties ofcNodeviaIntrospector. Filtering matchesAbstractASTTransformation.shouldSkipUndefinedAware(String, List, List, boolean). An introspection failure leaves the list collected so far, which may be empty.- Parameters:
cNode- class to introspect; it must already be loadableincludes- names to keep; null does not filter, and an empty list drops every nameexcludes- names to drop, or nullallNames-trueto keep internal names- Returns:
- the matching properties
-
getSetterName
Builds a setter name. An emptyprefixyieldsfieldNameunchanged. Otherwise the result isprefixplusfieldNamewith its first character upper-cased.- Parameters:
prefix- setter prefix, possibly emptyfieldName- property name, with at least one character- Returns:
- the setter name
-
unsupportedAttribute
protected boolean unsupportedAttribute(BuilderASTTransformation transform, AnnotationNode anno, String memberName) ReportsmemberNamewhen this strategy does not support it. Same as the four-argument form with an empty extra message.- Parameters:
transform- transformation that records the erroranno- annotation being processedmemberName- annotation member to reject when it is set- Returns:
truewhen an error was recorded
-
unsupportedAttribute
protected boolean unsupportedAttribute(BuilderASTTransformation transform, AnnotationNode anno, String memberName, String extraMessage) Reports an error whenmemberNameis set to something other than the undefined marker. A missing member, an undefined string, or an undefined class is accepted.extraMessageis appended, with a leading space, when it is not empty.- Parameters:
transform- transformation that records the erroranno- annotation being processedmemberName- annotation member to reject when it is setextraMessage- text appended to the error, or empty- Returns:
truewhen an error was recorded
-
checkKnownProperty
protected void checkKnownProperty(BuilderASTTransformation transform, AnnotationNode anno, String name, List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> properties) Reports an error whennameis not a property inproperties.- Parameters:
transform- transformation that records the erroranno- annotation the error is reported againstname- property name that was requestedproperties- properties this strategy knows about
-
checkKnownField
protected void checkKnownField(BuilderASTTransformation transform, AnnotationNode anno, String name, List<FieldNode> fields) Reports an error when no field infieldsis namedname. The error text callsnamea property.- Parameters:
transform- transformation that records the erroranno- annotation the error is reported againstname- field name that was requestedfields- fields this strategy knows about
-
getIncludeExclude
protected boolean getIncludeExclude(BuilderASTTransformation transform, AnnotationNode anno, ClassNode cNode, List<String> excludes, List<String> includes) Fillsexcludesandincludesfromanno. Anincludesmember replacesincludes; anexcludesmember is appended. Whenincludesis absent andexcludesis still empty, the lists are filled from a@TupleConstructoroncNodeif one is present. A one-elementincludeslist holding the undefined marker is treated as no includes.- Parameters:
transform- transformation that reads members and reports errorsanno- the@BuilderannotationcNode- class that may carry@TupleConstructorexcludes- names to exclude; this method appends to itincludes- names to include; this method may clear and refill it- Returns:
falsewhen both includes and excludes are supplied
-
getFields
protected List<FieldNode> getFields(BuilderASTTransformation transform, AnnotationNode anno, ClassNode buildee) Returns the property fields the builder should see. WhenannosetsincludeSuperPropertiesto true, fields from superclasses are included; otherwise only the instance property fields ofbuildeeare returned.- Parameters:
transform- transformation that reads the annotation memberanno- the@Builderannotationbuildee- class being built- Returns:
- those property fields
-
getPropertyInfoFromClassNode
protected List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> getPropertyInfoFromClassNode(BuilderASTTransformation transform, AnnotationNode anno, ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames, boolean allProperties) Lists properties ofcNode, then property fields fromgetFields(org.codehaus.groovy.transform.BuilderASTTransformation, org.codehaus.groovy.ast.AnnotationNode, org.codehaus.groovy.ast.ClassNode)whose names were not already seen. Superclass properties and static properties are not taken from the property walk. WhenallPropertiesis true, JavaBean getters that have no field are included. Include, exclude, and internal-name filtering matchesgetPropertyInfoFromClassNode(ClassNode, List, List, boolean).- Parameters:
transform- transformation passed togetFields(org.codehaus.groovy.transform.BuilderASTTransformation, org.codehaus.groovy.ast.AnnotationNode, org.codehaus.groovy.ast.ClassNode)anno- annotation passed togetFields(org.codehaus.groovy.transform.BuilderASTTransformation, org.codehaus.groovy.ast.AnnotationNode, org.codehaus.groovy.ast.ClassNode)cNode- class whose properties are collectedincludes- names to keep; empty or null does not filterexcludes- names to drop, or nullallNames-trueto keep internal namesallProperties-trueto include getters with no field- Returns:
- the matching properties
-
getPropertyInfos
protected List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> getPropertyInfos(BuilderASTTransformation transform, AnnotationNode anno, ClassNode buildee, List<String> excludes, List<String> includes, boolean allNames, boolean allProperties) Lists the properties the builder should copy. Abuildeewith no module is read withgetPropertyInfoFromBeanInfo(org.codehaus.groovy.ast.ClassNode, java.util.List<java.lang.String>, java.util.List<java.lang.String>, boolean), andallPropertiesis ignored. Otherwise the properties come from the AST.- Parameters:
transform- transformation passed through to the AST walkanno- annotation passed through to the AST walkbuildee- class being builtexcludes- names to drop, or nullincludes- names to keep, or nullallNames-trueto keep internal namesallProperties-trueto include getters with no field on the AST path- Returns:
- the matching properties
-