From bd51fa8484fde587eef10fc58e4527f26ec16430 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Mon, 13 Mar 2017 14:32:57 +0100 Subject: activate extendable builders explicitly (ensure backwards compatibility) --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/core/lombok/eclipse') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 4f152fe3..4bfc89f4 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -141,6 +141,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { String builderClassName = builderInstance.builderClassName(); boolean inherit = builderInstance.inherit(); + boolean extendable = inherit || builderInstance.extendable(); // inherit implies extendable String superclassBuilderClassName = builderInstance.superclassBuilderClassName(); String toBuilderMethodName = "toBuilder"; @@ -203,9 +204,9 @@ public class HandleBuilder extends EclipseAnnotationHandler { superclassBuilderClassName = new String(td.superclass.getLastToken()) + "Builder"; } - boolean callSuperConstructor = inherit && td.superclass != null; + boolean callBuilderBasedSuperConstructor = inherit && td.superclass != null; new HandleConstructor().generateConstructor(tdParent, AccessLevel.PROTECTED, allFields, false, null, SkipIfConstructorExists.I_AM_BUILDER, true, - Collections.emptyList(), annotationNode, builderClassName, callSuperConstructor); + Collections.emptyList(), annotationNode, extendable ? builderClassName : null, callBuilderBasedSuperConstructor); returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); typeParams = td.typeParameters; @@ -216,6 +217,10 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("@Builder(inherit=true) is only supported for type builders."); return; } + if (extendable) { + annotationNode.addError("@Builder(extendable=true) is only supported for type builders."); + return; + } ConstructorDeclaration cd = (ConstructorDeclaration) parent.get(); if (cd.typeParameters != null && cd.typeParameters.length > 0) { annotationNode.addError("@Builder is not supported on constructors with constructor type parameters."); @@ -234,6 +239,10 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("@Builder(inherit=true) is only supported for type builders."); return; } + if (extendable) { + annotationNode.addError("@Builder(extendable=true) is only supported for type builders."); + return; + } MethodDeclaration md = (MethodDeclaration) parent.get(); tdParent = parent.up(); isStatic = md.isStatic(); @@ -427,7 +436,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } if (methodExists(buildMethodName, builderType, -1) == MemberExistsResult.NOT_EXISTS) { - boolean useBuilderBasedConstructor = parent.get() instanceof TypeDeclaration; + boolean useBuilderBasedConstructor = parent.get() instanceof TypeDeclaration && extendable; MethodDeclaration md = generateBuildMethod(isStatic, buildMethodName, nameOfStaticBuilderMethod, returnType, builderFields, builderType, thrownExceptions, addCleaning, ast, useBuilderBasedConstructor); if (md != null) injectMethod(builderType, md); } -- cgit