blob: 733aea5a3500227cbe47321ae37f79d3d2ec5c18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package lombok.javac.handlers;
import static lombok.javac.handlers.JavacHandlerUtil.*;
import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import lombok.Builder;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
import lombok.core.HandlerPriority;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
@ProviderFor(JavacAnnotationHandler.class)
@HandlerPriority(-1025) //HandleBuilder's level, minus one.
public class HandleBuilderDefault extends JavacAnnotationHandler<Builder.Default> {
@SuppressWarnings("deprecation")
@Override public void handle(AnnotationValues<Builder.Default> annotation, JCAnnotation ast, JavacNode annotationNode) {
JavacNode annotatedField = annotationNode.up();
if (annotatedField.getKind() != Kind.FIELD) return;
JavacNode classWithAnnotatedField = annotatedField.up();
if (!hasAnnotation(Builder.class, classWithAnnotatedField) && !hasAnnotation(lombok.experimental.Builder.class, classWithAnnotatedField)) {
annotationNode.addWarning("@Builder.Default requires @Builder on the class for it to mean anything.");
deleteAnnotationIfNeccessary(annotationNode, Builder.Default.class);
}
}
}
|