aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleBuilder.java
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2017-12-12 02:42:14 +0100
committerRoel Spilker <r.spilker@gmail.com>2017-12-12 02:42:14 +0100
commitd9031506b5e7804c277d29db060973cd17033e9a (patch)
tree6eefdfb4bd4201ea5fcf767481a55c2a5e3ec9b9 /src/core/lombok/javac/handlers/HandleBuilder.java
parentf2530ab37efecf60e9ed1df2ed232822df209e4e (diff)
downloadlombok-d9031506b5e7804c277d29db060973cd17033e9a.tar.gz
lombok-d9031506b5e7804c277d29db060973cd17033e9a.tar.bz2
lombok-d9031506b5e7804c277d29db060973cd17033e9a.zip
support for @Builder on methods with a generified return type. Fixes #1420
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleBuilder.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index ea436422..420d4b72 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -212,7 +212,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
thrownExceptions = jmd.thrown;
nameOfBuilderMethod = jmd.name;
if (returnType instanceof JCTypeApply) {
- returnType = ((JCTypeApply) returnType).clazz;
+ returnType = cloneType(tdParent.getTreeMaker(), returnType, ast, annotationNode.getContext());
}
if (builderClassName.isEmpty()) {
if (returnType instanceof JCFieldAccess) {
@@ -232,7 +232,16 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
if (Character.isLowerCase(builderClassName.charAt(0))) {
builderClassName = Character.toTitleCase(builderClassName.charAt(0)) + builderClassName.substring(1);
}
- } else {
+ } else if (returnType instanceof JCTypeApply) {
+ JCExpression clazz = ((JCTypeApply) returnType).clazz;
+ if (clazz instanceof JCFieldAccess) {
+ builderClassName = ((JCFieldAccess) clazz).name + "Builder";
+ } else if (clazz instanceof JCIdent) {
+ builderClassName = ((JCIdent) clazz).name + "Builder";
+ }
+ }
+
+ if (builderClassName.isEmpty()) {
// This shouldn't happen.
System.err.println("Lombok bug ID#20140614-1651: javac HandleBuilder: return type to name conversion failed: " + returnType.getClass());
builderClassName = td.name.toString() + "Builder";
@@ -253,11 +262,14 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
tpOnRet = ((JCTypeApply) fullReturnType).arguments;
}
- if (returnType instanceof JCIdent) {
- simpleName = ((JCIdent) returnType).name;
+ JCExpression namingType = returnType;
+ if (returnType instanceof JCTypeApply) namingType = ((JCTypeApply) returnType).clazz;
+
+ if (namingType instanceof JCIdent) {
+ simpleName = ((JCIdent) namingType).name;
pkg = null;
- } else if (returnType instanceof JCFieldAccess) {
- JCFieldAccess jcfa = (JCFieldAccess) returnType;
+ } else if (namingType instanceof JCFieldAccess) {
+ JCFieldAccess jcfa = (JCFieldAccess) namingType;
simpleName = jcfa.name;
pkg = unpack(jcfa.selected);
if (pkg.startsWith("ERR:")) {
@@ -266,7 +278,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
return;
}
} else {
- annotationNode.addError("Expected a (parameterized) type here instead of a " + returnType.getClass().getName());
+ annotationNode.addError("Expected a (parameterized) type here instead of a " + namingType.getClass().getName());
return;
}