mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 03:13:38 +00:00
Implement javac handler
This commit is contained in:
1 parent
3cdc80050e
commit
ce9a103dd2
1 file changed
+17
-2
@@ -118,10 +118,12 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add @JsonProperty to all fields. It will be automatically copied to the getter/setters later.
|
||||
// Add @JsonProperty to all non-transient fields. It will be automatically copied to the getter/setters later.
|
||||
// Add @JsonIgnore to all transient fields. It will be automatically copied to the getter/setters later.
|
||||
for (JavacNode javacNode : tdNode.down()) {
|
||||
if (javacNode.getKind() == Kind.FIELD) {
|
||||
createJsonPropertyForField(javacNode, annotationNode);
|
||||
if (javacNode.isTransient()) createJsonIgnoreForField(javacNode, annotationNode);
|
||||
else createJsonPropertyForField(javacNode, annotationNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,6 +141,19 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> {
|
||||
fieldDecl.mods.annotations = fieldDecl.mods.annotations.append(annotationJsonProperty);
|
||||
}
|
||||
|
||||
private void createJsonIgnoreForField(JavacNode fieldNode, JavacNode annotationNode) {
|
||||
if (JacksonAnnotations.JSON_IGNORE.isAnnotating(fieldNode)) {
|
||||
return;
|
||||
}
|
||||
JavacTreeMaker maker = fieldNode.getTreeMaker();
|
||||
|
||||
JCExpression jsonPropertyType = chainDots(fieldNode, JacksonAnnotations.JSON_IGNORE.chainedDots);
|
||||
JCAnnotation annotationJsonProperty = maker.Annotation(jsonPropertyType, List.<JCExpression>nil());
|
||||
recursiveSetGeneratedBy(annotationJsonProperty, annotationNode);
|
||||
JCVariableDecl fieldDecl = ((JCVariableDecl)fieldNode.get());
|
||||
fieldDecl.mods.annotations = fieldDecl.mods.annotations.append(annotationJsonProperty);
|
||||
}
|
||||
|
||||
private void handleJacksonizedBuilder(JavacNode annotationNode, JavacNode annotatedNode, JavacNode tdNode, JCClassDecl td, JavacNode builderAnnotationNode, JavacNode superBuilderAnnotationNode) {
|
||||
if (builderAnnotationNode != null && superBuilderAnnotationNode != null) {
|
||||
annotationNode.addError("@Jacksonized cannot process both @Builder and @SuperBuilder on the same class.");
|
||||
|
||||
Reference in new issue
Block a user