aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/HandleValue.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2012-08-10 18:06:13 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2012-08-10 18:06:13 +0200
commit1be7da76012b246af24d0515d192bca85d65c823 (patch)
tree21d9675c00d812c6bbbf76edb80d38b16777740d /src/core/lombok/eclipse/handlers/HandleValue.java
parent70317c73841d3e83b4b8008b68bea95753a5275f (diff)
downloadlombok-1be7da76012b246af24d0515d192bca85d65c823.tar.gz
lombok-1be7da76012b246af24d0515d192bca85d65c823.tar.bz2
lombok-1be7da76012b246af24d0515d192bca85d65c823.zip
* Added priorities to handlers, along with implementation of the priority system for javac and ecj.
* @Value now makes the class itself final by default.
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleValue.java')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleValue.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleValue.java b/src/core/lombok/eclipse/handlers/HandleValue.java
index 9b3edabf..a1eb24ff 100644
--- a/src/core/lombok/eclipse/handlers/HandleValue.java
+++ b/src/core/lombok/eclipse/handlers/HandleValue.java
@@ -21,11 +21,14 @@
*/
package lombok.eclipse.handlers;
+import static lombok.eclipse.handlers.EclipseHandlerUtil.hasAnnotation;
import lombok.AccessLevel;
-import lombok.experimental.Value;
import lombok.core.AnnotationValues;
+import lombok.core.HandlerPriority;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
+import lombok.experimental.NonFinal;
+import lombok.experimental.Value;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
@@ -36,6 +39,7 @@ import org.mangosdk.spi.ProviderFor;
* Handles the {@code lombok.Value} annotation for eclipse.
*/
@ProviderFor(EclipseAnnotationHandler.class)
+@HandlerPriority(-512) //-2^9; to ensure @EqualsAndHashCode and such pick up on this handler making the class final and messing with the fields' access levels, run earlier.
public class HandleValue extends EclipseAnnotationHandler<Value> {
public void handle(AnnotationValues<Value> annotation, Annotation ast, EclipseNode annotationNode) {
Value ann = annotation.getInstance();
@@ -52,6 +56,11 @@ public class HandleValue extends EclipseAnnotationHandler<Value> {
return;
}
+ // Make class final.
+ if (!hasAnnotation(NonFinal.class, typeNode)) typeDecl.modifiers |= ClassFileConstants.AccFinal;
+
+ new HandleFieldDefaults().generateFieldDefaultsForType(typeNode, annotationNode, AccessLevel.PRIVATE, true, true);
+
//Careful: Generate the public static constructor (if there is one) LAST, so that any attempt to
//'find callers' on the annotation node will find callers of the constructor, which is by far the
//most useful of the many methods built by @Value. This trick won't work for the non-static constructor,
@@ -62,7 +71,6 @@ public class HandleValue extends EclipseAnnotationHandler<Value> {
new HandleWither().generateWitherForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
new HandleToString().generateToStringForType(typeNode, annotationNode);
- new HandleFieldDefaults().generateFieldDefaultsForType(typeNode, annotationNode, AccessLevel.PRIVATE, true, true);
new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, ann.staticConstructor(), true, ast);
}
}