From 5c99e5b9a01e434644e9589d018360d3815332e6 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:42:16 +0100 Subject: Extract method JavacSingularizer.finishGenerateClearMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 11 +++++++++++ .../javac/handlers/singulars/JavacGuavaSingularizer.java | 8 ++------ .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 8 ++------ .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 8 ++------ 4 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src/core/lombok/javac') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 5ef01edc..cab6dd20 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -24,6 +24,8 @@ package lombok.javac.handlers; import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; +import com.sun.tools.javac.tree.JCTree.JCBlock; +import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -33,6 +35,7 @@ import java.util.Map; import lombok.core.LombokImmutableList; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; +import lombok.core.handlers.HandlerUtil; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; @@ -240,6 +243,14 @@ public class JavacSingularsRecipes { protected abstract void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source); + protected void finishGenerateClearMethod(JavacTreeMaker maker, JCExpression returnType, SingularData data, JavacNode builderType, JCTree source, JCModifiers mods, List typeParams, List thrown, List params, List statements) { + JCBlock body = maker.Block(0, statements); + Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); + JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); + recursiveSetGeneratedBy(method, source, builderType.getContext()); + injectMethod(builderType, method); + } + protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); protected abstract void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 38783e95..ad972e8b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -86,12 +86,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); JCStatement clearField = maker.Exec(maker.Assign(thisDotField, maker.Literal(CTC_BOT, null))); List statements = returnStatement != null ? List.of(clearField, returnStatement) : List.of(clearField); - - JCBlock body = maker.Block(0, statements); - Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index fbd0bc7b..d84e5946 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -101,12 +101,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null)); JCStatement ifSetCallClear = maker.If(cond, clearCall, null); List statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); - - JCBlock body = maker.Block(0, statements); - Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index e4f189ad..0e6a794a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -130,12 +130,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCBlock clearCalls = maker.Block(0, List.of(clearKeyCall, clearValueCall)); JCStatement ifSetCallClear = maker.If(cond, clearCalls, null); List statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); - - JCBlock body = maker.Block(0, statements); - Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); } @Override -- cgit