mirror of
https://github.com/tiennm99/lombok.git
synced 2026-09-03 08:18:57 +00:00
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.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
package lombok.eclipse;
|
||||
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.core.SpiLoadUtil;
|
||||
|
||||
/**
|
||||
* Implement this interface if you want to be triggered for a specific annotation.
|
||||
@@ -59,4 +60,13 @@ public abstract class EclipseAnnotationHandler<T extends java.lang.annotation.An
|
||||
*/
|
||||
public void preHandle(AnnotationValues<T> annotation, org.eclipse.jdt.internal.compiler.ast.Annotation ast, EclipseNode 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(), EclipseAnnotationHandler.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,8 +158,7 @@ public class HandlerLibrary {
|
||||
try {
|
||||
for (EclipseAnnotationHandler<?> handler : SpiLoadUtil.findServices(EclipseAnnotationHandler.class, EclipseAnnotationHandler.class.getClassLoader())) {
|
||||
try {
|
||||
Class<? extends Annotation> annotationClass =
|
||||
SpiLoadUtil.findAnnotationClass(handler.getClass(), EclipseAnnotationHandler.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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user