aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleBuilder.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-03-05 23:16:27 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-03-05 23:16:27 +0100
commited412b7e091978e1363c91ba4c05aa304c4fb7d6 (patch)
tree6701aaea93463b9d92f544f4ea06ada5e275f7d7 /src/core/lombok/javac/handlers/HandleBuilder.java
parent0401f49fa6975195f81ff3252fefdbd6409dde6b (diff)
parent3a2a61f807eaedd22eab3c6d78653b7de2ae82a4 (diff)
downloadlombok-ed412b7e091978e1363c91ba4c05aa304c4fb7d6.tar.gz
lombok-ed412b7e091978e1363c91ba4c05aa304c4fb7d6.tar.bz2
lombok-ed412b7e091978e1363c91ba4c05aa304c4fb7d6.zip
Merge branch 'jacksonizedSquash' of git://github.com/janrieke/lombok into janrieke-jacksonizedSquash2
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleBuilder.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java73
1 files changed, 40 insertions, 33 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index 2f000546..91a74d62 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -149,7 +149,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
if (!checkName("builderClassName", builderClassName, annotationNode)) return;
}
- deleteAnnotationIfNeccessary(annotationNode, Builder.class, "lombok.experimental.Builder");
+ // Do not delete the Builder annotation here, we need it for @Jacksonized.
JavacNode parent = annotationNode.up();
@@ -257,38 +257,9 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
returnType = cloneType(tdParent.getTreeMaker(), returnType, ast, annotationNode.getContext());
}
if (replaceNameInBuilderClassName) {
- String replStr = null;
- if (returnType instanceof JCFieldAccess) {
- replStr = ((JCFieldAccess) returnType).name.toString();
- } else if (returnType instanceof JCIdent) {
- Name n = ((JCIdent) returnType).name;
-
- for (JCTypeParameter tp : typeParams) {
- if (tp.name.equals(n)) {
- annotationNode.addError("@Builder requires specifying 'builderClassName' if used on methods with a type parameter as return type.");
- return;
- }
- }
- replStr = n.toString();
- } else if (returnType instanceof JCPrimitiveTypeTree) {
- replStr = returnType.toString();
- if (Character.isLowerCase(replStr.charAt(0))) {
- replStr = Character.toTitleCase(replStr.charAt(0)) + replStr.substring(1);
- }
- } else if (returnType instanceof JCTypeApply) {
- JCExpression clazz = ((JCTypeApply) returnType).clazz;
- if (clazz instanceof JCFieldAccess) {
- replStr = ((JCFieldAccess) clazz).name.toString();
- } else if (clazz instanceof JCIdent) {
- replStr = ((JCIdent) clazz).name.toString();
- }
- }
-
- if (replStr == null || replStr.isEmpty()) {
- // This shouldn't happen.
- System.err.println("Lombok bug ID#20140614-1651: javac HandleBuilder: return type to name conversion failed: " + returnType.getClass());
- replStr = td.name.toString();
- }
+ String replStr = returnTypeToBuilderClassName(annotationNode, td, returnType, typeParams);
+ if (replStr == null)
+ return;
builderClassName = builderClassName.replace("*", replStr);
replaceNameInBuilderClassName = false;
}
@@ -507,6 +478,42 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
}
}
}
+
+ static String returnTypeToBuilderClassName(JavacNode annotationNode, JCClassDecl td, JCExpression returnType, List<JCTypeParameter> typeParams) {
+ String replStr = null;
+ if (returnType instanceof JCFieldAccess) {
+ replStr = ((JCFieldAccess) returnType).name.toString();
+ } else if (returnType instanceof JCIdent) {
+ Name n = ((JCIdent) returnType).name;
+
+ for (JCTypeParameter tp : typeParams) {
+ if (tp.name.equals(n)) {
+ annotationNode.addError("@Builder requires specifying 'builderClassName' if used on methods with a type parameter as return type.");
+ return null;
+ }
+ }
+ replStr = n.toString();
+ } else if (returnType instanceof JCPrimitiveTypeTree) {
+ replStr = returnType.toString();
+ if (Character.isLowerCase(replStr.charAt(0))) {
+ replStr = Character.toTitleCase(replStr.charAt(0)) + replStr.substring(1);
+ }
+ } else if (returnType instanceof JCTypeApply) {
+ JCExpression clazz = ((JCTypeApply) returnType).clazz;
+ if (clazz instanceof JCFieldAccess) {
+ replStr = ((JCFieldAccess) clazz).name.toString();
+ } else if (clazz instanceof JCIdent) {
+ replStr = ((JCIdent) clazz).name.toString();
+ }
+ }
+
+ if (replStr == null || replStr.isEmpty()) {
+ // This shouldn't happen.
+ System.err.println("Lombok bug ID#20140614-1651: javac HandleBuilder: return type to name conversion failed: " + returnType.getClass());
+ replStr = td.name.toString();
+ }
+ return replStr;
+ }
private static String unpack(JCExpression expr) {
StringBuilder sb = new StringBuilder();