diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-08-10 18:06:13 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-08-10 18:06:13 +0200 |
commit | 1be7da76012b246af24d0515d192bca85d65c823 (patch) | |
tree | 21d9675c00d812c6bbbf76edb80d38b16777740d /src/core/lombok/javac/handlers | |
parent | 70317c73841d3e83b4b8008b68bea95753a5275f (diff) | |
download | lombok-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/javac/handlers')
7 files changed, 20 insertions, 11 deletions
diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java index 50a2f1bb..b693a2a3 100644 --- a/src/core/lombok/javac/handlers/HandleDelegate.java +++ b/src/core/lombok/javac/handlers/HandleDelegate.java @@ -43,11 +43,11 @@ import javax.lang.model.type.TypeMirror; import lombok.Delegate; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; +import lombok.core.HandlerPriority; import lombok.javac.FindTypeVarScanner; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacResolution; -import lombok.javac.ResolutionBased; import lombok.javac.JavacResolution.TypeNotConvertibleException; import org.mangosdk.spi.ProviderFor; @@ -75,7 +75,7 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; @ProviderFor(JavacAnnotationHandler.class) -@ResolutionBased +@HandlerPriority(65536) //2^16; to make sure that we also delegate generated methods. public class HandleDelegate extends JavacAnnotationHandler<Delegate> { private static final List<String> METHODS_IN_OBJECT = Collections.unmodifiableList(Arrays.asList( "hashCode()", diff --git a/src/core/lombok/javac/handlers/HandleExtensionMethod.java b/src/core/lombok/javac/handlers/HandleExtensionMethod.java index 92d7c0e4..68df38ef 100644 --- a/src/core/lombok/javac/handlers/HandleExtensionMethod.java +++ b/src/core/lombok/javac/handlers/HandleExtensionMethod.java @@ -31,10 +31,10 @@ import java.util.List; import javax.lang.model.element.ElementKind; import lombok.core.AnnotationValues; +import lombok.core.HandlerPriority; import lombok.experimental.ExtensionMethod; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; -import lombok.javac.ResolutionBased; import org.mangosdk.spi.ProviderFor; @@ -60,7 +60,7 @@ import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; * Handles the {@link ExtensionMethod} annotation for javac. */ @ProviderFor(JavacAnnotationHandler.class) -@ResolutionBased +@HandlerPriority(66560) // 2^16 + 2^10; we must run AFTER HandleVal which is at 2^16 public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMethod> { @Override public void handle(final AnnotationValues<ExtensionMethod> annotation, final JCAnnotation source, final JavacNode annotationNode) { @@ -83,9 +83,6 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho final List<Extension> extensions = getExtensions(annotationNode, extensionProviders); if (extensions.isEmpty()) return; - // call HandleVal explicitly to ensure val gets handled before @ExtensionMethdod gets handled. - // TODO maybe we should prioritize lombok handler - annotationNode.traverse(new HandleVal()); new ExtensionMethodReplaceVisitor(annotationNode, extensions, suppressBaseMethods).replace(); annotationNode.rebuild(); diff --git a/src/core/lombok/javac/handlers/HandleFieldDefaults.java b/src/core/lombok/javac/handlers/HandleFieldDefaults.java index a2dfb7ce..c0829172 100644 --- a/src/core/lombok/javac/handlers/HandleFieldDefaults.java +++ b/src/core/lombok/javac/handlers/HandleFieldDefaults.java @@ -25,6 +25,7 @@ import static lombok.javac.handlers.JavacHandlerUtil.*; import lombok.AccessLevel; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; +import lombok.core.HandlerPriority; import lombok.experimental.FieldDefaults; import lombok.experimental.NonFinal; import lombok.experimental.PackagePrivate; @@ -43,6 +44,7 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; * Handles the {@code lombok.FieldDefaults} annotation for eclipse. */ @ProviderFor(JavacAnnotationHandler.class) +@HandlerPriority(-512) //-2^9; to ensure @Setter and such pick up on messing with the fields' 'final' state, run earlier. public class HandleFieldDefaults extends JavacAnnotationHandler<FieldDefaults> { public boolean generateFieldDefaultsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean makeFinal, boolean checkForTypeLevelFieldDefaults) { if (checkForTypeLevelFieldDefaults) { diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java index 4208f3c6..5ccc82d4 100644 --- a/src/core/lombok/javac/handlers/HandleLog.java +++ b/src/core/lombok/javac/handlers/HandleLog.java @@ -44,7 +44,6 @@ import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Name; public class HandleLog { - private HandleLog() { throw new UnsupportedOperationException(); } diff --git a/src/core/lombok/javac/handlers/HandlePrintAST.java b/src/core/lombok/javac/handlers/HandlePrintAST.java index 27aa02ad..7b6d942c 100644 --- a/src/core/lombok/javac/handlers/HandlePrintAST.java +++ b/src/core/lombok/javac/handlers/HandlePrintAST.java @@ -31,6 +31,7 @@ import com.sun.tools.javac.tree.JCTree.JCAnnotation; import lombok.Lombok; import lombok.core.AnnotationValues; +import lombok.core.HandlerPriority; import lombok.core.PrintAST; import lombok.javac.JavacASTVisitor; import lombok.javac.JavacAnnotationHandler; @@ -40,6 +41,7 @@ import lombok.javac.JavacNode; * Handles the {@code lombok.core.PrintAST} annotation for javac. */ @ProviderFor(JavacAnnotationHandler.class) +@HandlerPriority(536870912) // 2^29; this handler is customarily run at the very end. public class HandlePrintAST extends JavacAnnotationHandler<PrintAST> { @Override public void handle(AnnotationValues<PrintAST> annotation, JCAnnotation ast, JavacNode annotationNode) { PrintStream stream = System.out; diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java index 52d2ed13..0ab9d783 100644 --- a/src/core/lombok/javac/handlers/HandleVal.java +++ b/src/core/lombok/javac/handlers/HandleVal.java @@ -24,11 +24,11 @@ package lombok.javac.handlers; import static lombok.javac.handlers.JavacHandlerUtil.*; import lombok.val; +import lombok.core.HandlerPriority; import lombok.javac.JavacASTAdapter; import lombok.javac.JavacASTVisitor; import lombok.javac.JavacNode; import lombok.javac.JavacResolution; -import lombok.javac.ResolutionBased; import org.mangosdk.spi.ProviderFor; @@ -44,7 +44,7 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; @ProviderFor(JavacASTVisitor.class) -@ResolutionBased +@HandlerPriority(65536) // 2^16; resolution needs to work, so if the RHS expression is i.e. a call to a generated getter, we have to run after that getter has been generated. public class HandleVal extends JavacASTAdapter { @Override public void visitLocal(JavacNode localNode, JCVariableDecl local) { if (local.vartype == null || (!local.vartype.toString().equals("val") && !local.vartype.toString().equals("lombok.val"))) return; diff --git a/src/core/lombok/javac/handlers/HandleValue.java b/src/core/lombok/javac/handlers/HandleValue.java index fac017a8..b52bad7c 100644 --- a/src/core/lombok/javac/handlers/HandleValue.java +++ b/src/core/lombok/javac/handlers/HandleValue.java @@ -24,18 +24,23 @@ package lombok.javac.handlers; import static lombok.javac.handlers.JavacHandlerUtil.*; import lombok.AccessLevel; import lombok.core.AnnotationValues; +import lombok.core.HandlerPriority; +import lombok.experimental.NonFinal; import lombok.experimental.Value; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import org.mangosdk.spi.ProviderFor; +import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree.JCAnnotation; +import com.sun.tools.javac.tree.JCTree.JCClassDecl; /** * Handles the {@code lombok.Value} annotation for javac. */ @ProviderFor(JavacAnnotationHandler.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 JavacAnnotationHandler<Value> { @Override public void handle(AnnotationValues<Value> annotation, JCAnnotation ast, JavacNode annotationNode) { deleteAnnotationIfNeccessary(annotationNode, Value.class); @@ -49,12 +54,16 @@ public class HandleValue extends JavacAnnotationHandler<Value> { String staticConstructorName = annotation.getInstance().staticConstructor(); + if (!hasAnnotationAndDeleteIfNeccessary(NonFinal.class, typeNode)) { + ((JCClassDecl) typeNode.get()).mods.flags |= Flags.FINAL; + } + new HandleFieldDefaults().generateFieldDefaultsForType(typeNode, annotationNode, AccessLevel.PRIVATE, true, true); + // TODO move this to the end OR move it to the top in eclipse. new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, staticConstructorName, true, annotationNode); new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true); 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); } } |