Class Refactory

java.lang.Object
org.jboss.forge.roaster.model.util.Refactory

public class Refactory extends Object
Utility refactory methods for JavaClassSource objects
Author:
Lincoln Baxter, III, George Gastaldi, Vineet Reynolds
  • Method Details

    • 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

      @Deprecated public static void createHashCodeAndEquals(JavaClassSource clazz)
      Deprecated.
      Use createHashCodeAndEquals(JavaClassSource, FieldSource...) instead, since this method relies on the existence of the id field
      Create a hashCode and equals implementation for the given class and fields
      Parameters:
      clazz - the class where to generate the methods
    • 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