Class Refactory
java.lang.Object
org.jboss.forge.roaster.model.util.Refactory
Utility refactory methods for
JavaClassSource objects-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateEquals(JavaClassSource clazz, FieldSource<?>... fields) Create an equals implementation for the given class and fields.static voidcreateGetterAndSetter(JavaClassSource clazz, FieldSource<JavaClassSource> field) Generates a getXXX and setXXX method for the supplied fieldstatic voidcreateHashCode(JavaClassSource clazz, FieldSource<?>... fields) Create a hashCode implementation for the given class and fields.static voidDeprecated.static voidcreateHashCodeAndEquals(JavaClassSource clazz, FieldSource<?>... fields) Create a hashCode and equals implementation for the given class and fields.static voidCreate a toString implementation using all the fields in this classstatic voidcreateToStringFromFields(JavaClassSource clazz, List<FieldSource<JavaClassSource>> fields) Create a toString implementation using the supplied fieldsstatic voidcreateToStringFromFields(JavaClassSource clazz, FieldSource<JavaClassSource>... fields) Create a toString implementation using the supplied fields
-
Method Details
-
createGetterAndSetter
Generates a getXXX and setXXX method for the supplied field- Parameters:
clazz- the java source class where to generated the methodsfield- the fields for which the methods should be generated
-
createHashCodeAndEquals
Deprecated.UsecreateHashCodeAndEquals(JavaClassSource, FieldSource...)instead, since this method relies on the existence of the id fieldCreate a hashCode and equals implementation for the given class and fields- Parameters:
clazz- the class where to generate the methods
-
createHashCodeAndEquals
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 changedfields- fields to be used in the equals/hashCode methods
-
createEquals
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 changedfields- fields to be used in the equals/hashCode methods
-
createHashCode
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 changedfields- fields to be used in the equals/hashCode methods
-
createToStringFromFields
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 generatedfields- 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 generatedfields- the fields which are used for this method
-
createHashCodeAndEquals(JavaClassSource, FieldSource...)instead, since this method relies on the existence of the id field