diff options
author | Emil Lundberg <emil@emlun.se> | 2019-01-10 01:42:16 +0100 |
---|---|---|
committer | Emil Lundberg <emil@emlun.se> | 2019-01-10 02:12:17 +0100 |
commit | 5c99e5b9a01e434644e9589d018360d3815332e6 (patch) | |
tree | f300ba15937c9cf411097e012b16c2ac677ac447 /src | |
parent | a8a78880331db06122a4432009eb03d6833371b5 (diff) | |
download | lombok-5c99e5b9a01e434644e9589d018360d3815332e6.tar.gz lombok-5c99e5b9a01e434644e9589d018360d3815332e6.tar.bz2 lombok-5c99e5b9a01e434644e9589d018360d3815332e6.zip |
Extract method JavacSingularizer.finishGenerateClearMethod
Diffstat (limited to 'src')
4 files changed, 17 insertions, 18 deletions
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<JCTypeParameter> typeParams, List<JCExpression> thrown, List<JCVariableDecl> params, List<JCStatement> 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<JCStatement> 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<JCStatement> 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<JCStatement> 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 |