Class ToStringASTTransformation

java.lang.Object
org.codehaus.groovy.transform.AbstractASTTransformation
org.codehaus.groovy.transform.ToStringASTTransformation
All Implemented Interfaces:
ASTTransformation, ErrorCollecting

public class ToStringASTTransformation extends AbstractASTTransformation
Handles generation of code for the @ToString annotation.
  • Constructor Details

    • ToStringASTTransformation

      public ToStringASTTransformation()
  • Method Details

    • visit

      public void visit(ASTNode[] nodes, SourceUnit source)
      Description copied from interface: ASTTransformation
      The 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)
      Adds toString, printing null values. Delegates with ignoreNulls false.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - 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)
      Adds toString with the class name qualified by its package. Delegates with includePackage true.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - 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)
      Adds toString that is computed on every call. Delegates with cache false.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - skip a null value
      includePackage - 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)
      Adds toString without superclass properties. Delegates with includeSuperProperties false.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - skip a null value
      includePackage - qualify the class name with its package
      cache - store the text in a $to$string 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)
      Adds toString including JavaBean getters that have no field. Delegates with allProperties true.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - skip a null value
      includePackage - qualify the class name with its package
      cache - store the text in a $to$string field
      includeSuperProperties - 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)
      Adds toString that skips internal names and superclass fields. Delegates with allNames and includeSuperFields false.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - skip a null value
      includePackage - qualify the class name with its package
      cache - store the text in a $to$string field
      includeSuperProperties - include properties declared on superclasses
      allProperties - 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)
      Adds toString using FormatHelper.toString(Object) and the default delimiters. Delegates with pojo false and delims null.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - skip a null value
      includePackage - qualify the class name with its package
      cache - store the text in a $to$string field
      includeSuperProperties - include properties declared on superclasses
      allProperties - include JavaBean getters that have no field
      allNames - 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)
      Adds toString, reading properties from this rather than through getters. Delegates with useGetter false.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - skip a null value
      includePackage - qualify the class name with its package
      cache - store the text in a $to$string field
      includeSuperProperties - include properties declared on superclasses
      allProperties - include JavaBean getters that have no field
      allNames - keep names that contain $
      includeSuperFields - include fields declared on superclasses
      pojo - render each value with toString, printing null as the text null, instead of FormatHelper
      delims - 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)
      Adds toString to cNode, or a private _toString when a hand-written toString is already declared. A stub placeholder receives this body. An existing generated toString, 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. When includes is set, values follow that order. A value whose static type is this class and that is this instance is rendered as (this). When cache is true the text is stored in a private synthetic $to$string field and computed only while that field is null.
      Parameters:
      cNode - class that receives toString
      includeSuper - append super.toString()
      includeFields - include fields as well as properties
      excludes - names to omit, or null
      includes - names to print, in this order, or null
      includeNames - print each name before its value
      ignoreNulls - skip a null value
      includePackage - qualify the class name with its package; ignored for an enum, which prints name()
      cache - store the text in a $to$string field
      includeSuperProperties - include properties declared on superclasses
      allProperties - include JavaBean getters that have no field
      allNames - keep names that contain $
      includeSuperFields - include fields declared on superclasses
      pojo - render each value with toString, printing null as the text null, instead of FormatHelper
      delims - 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 on this. A bare field is read directly either way