aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorEmil Lundberg <emil@emlun.se>2019-01-10 01:48:35 +0100
committerEmil Lundberg <emil@emlun.se>2019-01-13 02:13:44 +0100
commit05ce5e050ea15a7feb26ba2ef6f3cda9b54c8498 (patch)
tree2ca8871ffb946c03c4bedc80f2cb6826b44eaf57 /src/core/lombok/javac
parent5c99e5b9a01e434644e9589d018360d3815332e6 (diff)
downloadlombok-05ce5e050ea15a7feb26ba2ef6f3cda9b54c8498.tar.gz
lombok-05ce5e050ea15a7feb26ba2ef6f3cda9b54c8498.tar.bz2
lombok-05ce5e050ea15a7feb26ba2ef6f3cda9b54c8498.zip
Extract abstract method JavacSingularizer.generateClearStatements
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/JavacSingularsRecipes.java2
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java14
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java15
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java12
4 files changed, 32 insertions, 11 deletions
diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
index cab6dd20..1d4d5a8d 100644
--- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
+++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
@@ -251,6 +251,8 @@ public class JavacSingularsRecipes {
injectMethod(builderType, method);
}
+ protected abstract List<JCStatement> generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType);
+
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 ad972e8b..13a48869 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
@@ -82,15 +82,21 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer {
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
List<JCVariableDecl> params = List.nil();
-
- 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);
+
+ List<JCStatement> statements = generateClearStatements(maker, returnStatement, data, builderType);
finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements);
}
@Override
+ protected List<JCStatement> generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) {
+ JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName());
+
+ JCStatement clearField = maker.Exec(maker.Assign(thisDotField, maker.Literal(CTC_BOT, null)));
+ return returnStatement != null ? List.of(clearField, returnStatement) : List.of(clearField);
+ }
+
+ @Override
protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
index d84e5946..f332aad1 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
@@ -93,16 +93,23 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
List<JCVariableDecl> params = List.nil();
+
+ List<JCStatement> statements = generateClearStatements(maker, returnStatement, data, builderType);
+
+ finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements);
+ }
+
+ @Override
+ protected List<JCStatement> generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) {
List<JCExpression> jceBlank = List.nil();
-
JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName());
JCExpression thisDotFieldDotClear = maker.Select(maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), builderType.toName("clear"));
+
JCStatement clearCall = maker.Exec(maker.Apply(jceBlank, thisDotFieldDotClear, jceBlank));
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);
- finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements);
+ JCStatement ifSetCallClear = maker.If(cond, clearCall, null);
+ return returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear);
}
@Override
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
index 0e6a794a..dab09eb3 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
@@ -119,6 +119,14 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
List<JCVariableDecl> params = List.nil();
+
+ List<JCStatement> statements = generateClearStatements(maker, returnStatement, data, builderType);
+
+ finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements);
+ }
+
+ @Override
+ protected List<JCStatement> generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) {
List<JCExpression> jceBlank = List.nil();
JCExpression thisDotKeyField = chainDots(builderType, "this", data.getPluralName() + "$key");
@@ -129,9 +137,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotKeyField, maker.Literal(CTC_BOT, null));
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);
-
- finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements);
+ return returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear);
}
@Override