From 5fcb9284c13e58750ec6c36a1eae5869a5a52925 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 29 Apr 2014 22:00:30 +0200 Subject: added docs for the new onParam feature on EqualsAndHashCode, and some tiny stylistic nitpicking. --- doc/changelog.markdown | 1 + src/core/lombok/EqualsAndHashCode.java | 8 ++++---- src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 4 ++-- website/features/EqualsAndHashCode.html | 4 +++- website/features/experimental/onX.html | 6 +++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 21475d79..8ac2fb9c 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -2,6 +2,7 @@ Lombok Changelog ---------------- ### v1.12.7 "Edgy Guinea Pig" +* FEATURE: It is now possible to put annotations, such as `@Nullable`, on the one parameter of generated `equals()` methods by specifying the `onParam=` option on `@EqualsAndHashCode`, similar to how that feature already exists for `@Setter`. [Issue #674](https://code.google.com/p/projectlombok/issues/detail?id=674) * CHANGE: suppressConstructorProperties should now be configured via lombok configuration. [Issue #659](https://code.google.com/p/projectlombok/issues/detail?id=659) * CHANGE: The `canEqual` method generated by `@EqualsAndHashCode`, `@Value` and `@Data` is now `protected` instead of `public`. [Issue #660](https://code.google.com/p/projectlombok/issues/detail?id=660) * BUGFIX: Deadlocks would occasionally occur in eclipse when using lazy getters [Issue #590](https://code.google.com/p/projectlombok/issues/detail?id=590) diff --git a/src/core/lombok/EqualsAndHashCode.java b/src/core/lombok/EqualsAndHashCode.java index 0ce9ded7..dbce23b8 100644 --- a/src/core/lombok/EqualsAndHashCode.java +++ b/src/core/lombok/EqualsAndHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 The Project Lombok Authors. + * Copyright (C) 2009-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -69,9 +69,9 @@ public @interface EqualsAndHashCode { AnyAnnotation[] onParam() default {}; /** - * Placeholder annotation to enable the placement of annotations on the generated code. - * @deprecated Don't use this annotation, ever - Read the documentation. - */ + * Placeholder annotation to enable the placement of annotations on the generated code. + * @deprecated Don't use this annotation, ever - Read the documentation. + */ @Deprecated @Retention(RetentionPolicy.SOURCE) @Target({}) diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 9b2389e8..b6ea568d 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -484,7 +484,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler statements = new ArrayList(); @@ -749,7 +749,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandlerHow to Write an Equality Method in Java. If all classes in a hierarchy are a mix of scala case classes and classes with lombok-generated equals methods, all equality will 'just work'. If you need to write your own equals methods, you should always override canEqual if you change equals and hashCode. -

+

+ NEW in Lombok 1.14.0: To put annotations on the other parameter of the equals (and, if relevant, canEqual) method, you can use onParam=@__({@AnnotationsHere}). Be careful though! This is an experimental feature. For more details see the documentation on the onX feature. +

diff --git a/website/features/experimental/onX.html b/website/features/experimental/onX.html index 530d98a4..78537c67 100644 --- a/website/features/experimental/onX.html +++ b/website/features/experimental/onX.html @@ -15,7 +15,7 @@

Since

- onX was introduced as experimental feature in lombok v0.11.7 (edge release only). + onX was introduced as experimental feature in lombok v0.11.8.

@@ -40,7 +40,7 @@

@AllArgsConstructor, @NoArgsConstructor, and @RequiredArgsConstructor support the onConstructor option which will put the listed annotations on the generated constructor.

- @Setter and @Wither support onParam in addition to onMethod; annotations listed will be put on the only parameter that the generated method has. + @Setter and @Wither support onParam in addition to onMethod; annotations listed will be put on the only parameter that the generated method has. @EqualsAndHashCode also supports onParam; the listed annotation(s) will be placed on the single parameter of the generated equals method, as well as any generated canEqual method.

The syntax is a little strange; to use any of the 3 onX features, you must wrap the annotations to be applied to the constructor / method / parameter in @__(@AnnotationGoesHere). To apply multiple annotations, use @__({@Annotation1, @Annotation2}). The annotations can themselves obviously have parameters as well.

@@ -60,7 +60,7 @@

Small print

- The reason of the weird syntax is to make this feature work in javac 7 compilers; the @__ type is an annotation reference to the annotation type _ (underscore) which doesn't actually exist; this makes javac 7 delay aborting the compilation process due to an error because it is possible an annotation processor will later create the _ type. Instead, lombok applies the annotations and removes the references so that the error will never actually occur. The point is: The _ type must not exist, otherwise the feature does not work. In the rare case that the _ type does exist (and is imported or in the package), you can simply add more underscores. Technically any non-existent type would work, but to maintain consistency and readability and catch erroneous use, lombok considers it an error if the 'wrapper' annotation is anything but a series of underscores. + The reason of the weird syntax is to make this feature work in javac 7 compilers; the @__ type is an annotation reference to the annotation type __ (double underscore) which doesn't actually exist; this makes javac 7 delay aborting the compilation process due to an error because it is possible an annotation processor will later create the __ type. Instead, lombok applies the annotations and removes the references so that the error will never actually occur. The point is: The __ type must not exist, otherwise the feature does not work. In the rare case that the __ type does exist (and is imported or in the package), you can simply add more underscores. Technically any non-existent type would work, but to maintain consistency and readability and catch erroneous use, lombok considers it an error if the 'wrapper' annotation is anything but a series of underscores.

To reiterate: This feature can disappear at any time; if you use this feature, be prepared to adjust your code when we find a nicer way of implementing this feature, or, if a future version of javac forces us to remove this feature entirely with no alternative.

-- cgit