diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-08-24 15:17:46 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-08-24 15:17:46 +0200 |
commit | 4f5f689bf2be42bc2a6e331ae83bace35c9e86e9 (patch) | |
tree | b520fa131af905616653ea038f2087e2a110fb05 /src/core/lombok/javac | |
parent | 579e139c6cea831789fe28d0ecbd7e753870f456 (diff) | |
download | lombok-4f5f689bf2be42bc2a6e331ae83bace35c9e86e9.tar.gz lombok-4f5f689bf2be42bc2a6e331ae83bace35c9e86e9.tar.bz2 lombok-4f5f689bf2be42bc2a6e331ae83bace35c9e86e9.zip |
There is now an 'override this method' alternative for
setting the annotation you handle for an XAnnotationHandler<T>;
default behaviour still extracts the T part out of the signature.
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r-- | src/core/lombok/javac/HandlerLibrary.java | 3 | ||||
-rw-r--r-- | src/core/lombok/javac/JavacAnnotationHandler.java | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/core/lombok/javac/HandlerLibrary.java b/src/core/lombok/javac/HandlerLibrary.java index 81618070..2be84355 100644 --- a/src/core/lombok/javac/HandlerLibrary.java +++ b/src/core/lombok/javac/HandlerLibrary.java @@ -165,8 +165,7 @@ public class HandlerLibrary { private static void loadAnnotationHandlers(HandlerLibrary lib) throws IOException { //No, that seemingly superfluous reference to JavacAnnotationHandler's classloader is not in fact superfluous! for (JavacAnnotationHandler handler : SpiLoadUtil.findServices(JavacAnnotationHandler.class, JavacAnnotationHandler.class.getClassLoader())) { - Class<? extends Annotation> annotationClass = - SpiLoadUtil.findAnnotationClass(handler.getClass(), JavacAnnotationHandler.class); + Class<? extends Annotation> annotationClass = handler.getAnnotationHandledByThisHandler(); AnnotationHandlerContainer<?> container = new AnnotationHandlerContainer(handler, annotationClass); String annotationClassName = container.annotationClass.getName().replace("$", "."); if (lib.annotationHandlers.put(annotationClassName, container) != null) { diff --git a/src/core/lombok/javac/JavacAnnotationHandler.java b/src/core/lombok/javac/JavacAnnotationHandler.java index 434eab46..169e2026 100644 --- a/src/core/lombok/javac/JavacAnnotationHandler.java +++ b/src/core/lombok/javac/JavacAnnotationHandler.java @@ -24,6 +24,7 @@ package lombok.javac; import java.lang.annotation.Annotation; import lombok.core.AnnotationValues; +import lombok.core.SpiLoadUtil; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -53,4 +54,13 @@ public abstract class JavacAnnotationHandler<T extends Annotation> { * as access useful methods such as generating warnings or errors focused on the annotation. */ public abstract void handle(AnnotationValues<T> annotation, JCAnnotation ast, JavacNode annotationNode); + + /** + * This handler is a handler for the given annotation; you don't normally need to override this class + * as the annotation type is extracted from your {@code extends EclipseAnnotationHandler<AnnotationTypeHere>} + * signature. + */ + @SuppressWarnings("unchecked") public Class<T> getAnnotationHandledByThisHandler() { + return (Class<T>) SpiLoadUtil.findAnnotationClass(getClass(), JavacAnnotationHandler.class); + } } |