Class Refactory

    • Method Detail

      • createGetterAndSetter

        public static void createGetterAndSetter​(JavaClassSource clazz,
                                                 FieldSource<JavaClassSource> field)
        Generates a getXXX and setXXX method for the supplied field
        Parameters:
        clazz - the java source class where to generated the methods
        field - the fields for which the methods should be generated
      • createHashCodeAndEquals

        public static void createHashCodeAndEquals​(JavaClassSource clazz,
                                                   FieldSource<?>... fields)
        Create a hashCode and equals implementation for the given class and fields. Callers must verify that the types of the fields override the default identity based equals and hashcode implementations. No warnings are issued in an event where the field type uses the implementation of java.lang.Object. This method ignores static fields for generating the equals and hashCode methods, since they are ideally not meant to be used in these cases. Although transient fields could also be ignored, they are not since there is no mechanism to convey warnings (not errors) in this case.
        Parameters:
        clazz - class to be changed
        fields - fields to be used in the equals/hashCode methods
      • createEquals

        public static void createEquals​(JavaClassSource clazz,
                                        FieldSource<?>... fields)
        Create an equals implementation for the given class and fields. Callers must verify that the types of the fields override the default identity based equals implementation. No warnings are issued in an event where the field type uses the implementation of java.lang.Object. This method ignores static fields for generating the equals method, since they are ideally not meant to be used in these cases. Although transient fields could also be ignored, they are not since there is no mechanism to convey warnings (not errors) in this case.
        Parameters:
        clazz - class to be changed
        fields - fields to be used in the equals/hashCode methods
      • createHashCode

        public static void createHashCode​(JavaClassSource clazz,
                                          FieldSource<?>... fields)
        Create a hashCode implementation for the given class and fields. Callers must verify that the types of the fields override the default identity based hashcode implementation. No warnings are issued in an event where the field type uses the implementation of java.lang.Object. This method ignores static fields for generating the equals method, since they are ideally not meant to be used in these cases. Although transient fields could also be ignored, they are not since there is no mechanism to convey warnings (not errors) in this case.
        Parameters:
        clazz - class to be changed
        fields - fields to be used in the equals/hashCode methods
      • createToStringFromFields

        public static void createToStringFromFields​(JavaClassSource clazz)
        Create a toString implementation using all the fields in this class
        Parameters:
        clazz - the class where the method should be generated
      • createToStringFromFields

        public static void createToStringFromFields​(JavaClassSource clazz,
                                                    FieldSource<JavaClassSource>... fields)
        Create a toString implementation using the supplied fields
        Parameters:
        clazz - the class where the method should be generated
        fields - the fields which are used for this method
      • createToStringFromFields

        public static void createToStringFromFields​(JavaClassSource clazz,
                                                    List<FieldSource<JavaClassSource>> fields)
        Create a toString implementation using the supplied fields
        Parameters:
        clazz - the class where the method should be generated
        fields - the fields which are used for this method