Package org.codehaus.groovy.transform
Class ToStringASTTransformation
java.lang.Object
org.codehaus.groovy.transform.AbstractASTTransformation
org.codehaus.groovy.transform.ToStringASTTransformation
- All Implemented Interfaces:
ASTTransformation,ErrorCollecting
Handles generation of code for the @ToString annotation.
-
Field Summary
Fields inherited from class org.codehaus.groovy.transform.AbstractASTTransformation
RETENTION_CLASSNODE, sourceUnit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames) AddstoString, printing null values.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls) AddstoStringwith the class name qualified by its package.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage) AddstoStringthat is computed on every call.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache) AddstoStringwithout superclass properties.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties) AddstoStringincluding JavaBean getters that have no field.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties) AddstoStringthat skips internal names and superclass fields.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties, boolean allNames, boolean includeSuperFields) AddstoStringusingFormatHelper.toString(Object)and the default delimiters.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties, boolean allNames, boolean includeSuperFields, boolean pojo, String[] delims) AddstoString, reading properties fromthisrather than through getters.static voidcreateToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties, boolean allNames, boolean includeSuperFields, boolean pojo, String[] delims, boolean useGetter) AddstoStringtocNode, or a private_toStringwhen a hand-writtentoStringis already declared.voidvisit(ASTNode[] nodes, SourceUnit source) The method is invoked when an AST Transformation is active.Methods inherited from class org.codehaus.groovy.transform.AbstractASTTransformation
addError, checkIncludeExcludeUndefinedAware, checkIncludeExcludeUndefinedAware, checkNotInterface, checkPropertyList, checkPropertyList, checkPropertyList, copyAnnotatedNodeAnnotations, copyAnnotatedNodeAnnotations, deemedInternal, deemedInternalName, getAnnotationName, getMemberClassList, getMemberClassValue, getMemberClassValue, getMemberIntValue, getMemberStringList, getMemberStringValue, getMemberStringValue, getMemberValue, hasAnnotation, init, markAsInternal, memberHasValue, shouldSkip, shouldSkip, shouldSkip, shouldSkipOnDescriptorUndefinedAware, shouldSkipUndefinedAware, shouldSkipUndefinedAware, shouldSkipUndefinedAware, tokenize
-
Constructor Details
-
ToStringASTTransformation
public ToStringASTTransformation()
-
-
Method Details
-
visit
Description copied from interface:ASTTransformationThe method is invoked when an AST Transformation is active. For local transformations, it is invoked once each time the local annotation is encountered. For global transformations, it is invoked once for every source unit, which is typically a source file.- Parameters:
nodes- The ASTnodes when the call was triggered. Element 0 is the AnnotationNode that triggered this annotation to be activated. Element 1 is the AnnotatedNode decorated, such as a MethodNode or ClassNode. For global transformations it is usually safe to ignore this parameter.source- The source unit being compiled. The source unit may contain several classes. For global transformations, information about the AST can be retrieved from this object.
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames) AddstoString, printing null values. Delegates withignoreNullsfalse.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its value
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls) AddstoStringwith the class name qualified by its package. Delegates withincludePackagetrue.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null value
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage) AddstoStringthat is computed on every call. Delegates withcachefalse.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null valueincludePackage- qualify the class name with its package
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache) AddstoStringwithout superclass properties. Delegates withincludeSuperPropertiesfalse.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null valueincludePackage- qualify the class name with its packagecache- store the text in a$to$stringfield
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties) AddstoStringincluding JavaBean getters that have no field. Delegates withallPropertiestrue.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null valueincludePackage- qualify the class name with its packagecache- store the text in a$to$stringfieldincludeSuperProperties- include properties declared on superclasses
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties) AddstoStringthat skips internal names and superclass fields. Delegates withallNamesandincludeSuperFieldsfalse.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null valueincludePackage- qualify the class name with its packagecache- store the text in a$to$stringfieldincludeSuperProperties- include properties declared on superclassesallProperties- include JavaBean getters that have no field
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties, boolean allNames, boolean includeSuperFields) AddstoStringusingFormatHelper.toString(Object)and the default delimiters. Delegates withpojofalse anddelimsnull.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null valueincludePackage- qualify the class name with its packagecache- store the text in a$to$stringfieldincludeSuperProperties- include properties declared on superclassesallProperties- include JavaBean getters that have no fieldallNames- keep names that contain$includeSuperFields- include fields declared on superclasses
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties, boolean allNames, boolean includeSuperFields, boolean pojo, String[] delims) AddstoString, reading properties fromthisrather than through getters. Delegates withuseGetterfalse.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null valueincludePackage- qualify the class name with its packagecache- store the text in a$to$stringfieldincludeSuperProperties- include properties declared on superclassesallProperties- include JavaBean getters that have no fieldallNames- keep names that contain$includeSuperFields- include fields declared on superclassespojo- render each value withtoString, printing null as the textnull, instead ofFormatHelperdelims- left delimiter, right delimiter, name/value separator, and field separator; null or any other length uses(,),:, and,
-
createToString
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties, boolean allNames, boolean includeSuperFields, boolean pojo, String[] delims, boolean useGetter) AddstoStringtocNode, or a private_toStringwhen a hand-writtentoStringis already declared. A stub placeholder receives this body. An existing generatedtoString, or a class that already declares both names, is left unchanged. The text starts with the class name, or the enum constant name, then the left delimiter, the selected values, and the right delimiter. Whenincludesis set, values follow that order. A value whose static type is this class and that is this instance is rendered as(this). Whencacheis true the text is stored in a private synthetic$to$stringfield and computed only while that field is null.- Parameters:
cNode- class that receivestoStringincludeSuper- appendsuper.toString()includeFields- include fields as well as propertiesexcludes- names to omit, or nullincludes- names to print, in this order, or nullincludeNames- print each name before its valueignoreNulls- skip a null valueincludePackage- qualify the class name with its package; ignored for an enum, which printsname()cache- store the text in a$to$stringfieldincludeSuperProperties- include properties declared on superclassesallProperties- include JavaBean getters that have no fieldallNames- keep names that contain$includeSuperFields- include fields declared on superclassespojo- render each value withtoString, printing null as the textnull, instead ofFormatHelperdelims- left delimiter, right delimiter, name/value separator, and field separator; null or any other length uses(,),:, and,useGetter- read each property with its getter; otherwise read the property onthis. A bare field is read directly either way
-