aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorEmil Lundberg <emil@emlun.se>2019-01-10 03:06:57 +0100
committerEmil Lundberg <emil@emlun.se>2019-01-13 02:19:50 +0100
commit4599a65b7df036eabf5d6784466a0ab848a63d16 (patch)
treea6be1dbc5ac086493b6469d9d1b4ce37cd4d6b92 /src/core/lombok/javac
parent85759a1949fe862a2baa2cb836d0bbea5349db66 (diff)
downloadlombok-4599a65b7df036eabf5d6784466a0ab848a63d16.tar.gz
lombok-4599a65b7df036eabf5d6784466a0ab848a63d16.tar.bz2
lombok-4599a65b7df036eabf5d6784466a0ab848a63d16.zip
Extract method JavacSingularizer.generateSingularMethodParameter
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/JavacSingularsRecipes.java8
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java7
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java8
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java14
4 files changed, 12 insertions, 25 deletions
diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
index 9921ba89..d8dc65c7 100644
--- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
+++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
@@ -266,6 +266,14 @@ public class JavacSingularsRecipes {
protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent);
+ protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name, long flags) {
+ JCExpression type = cloneParamType(typeIndex, maker, data.getTypeArgs(), builderType, source);
+ List<JCAnnotation> typeUseAnns = getTypeUseAnnotations(type);
+ type = removeTypeUseAnnotations(type);
+ JCModifiers mods = typeUseAnns.isEmpty() ? maker.Modifiers(flags) : maker.Modifiers(flags, typeUseAnns);
+ return maker.VarDef(mods, name, type, null);
+ }
+
protected abstract void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent);
public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable);
diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
index b514ebd5..cd650f9a 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
@@ -44,7 +44,6 @@ import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
import com.sun.tools.javac.tree.JCTree.JCStatement;
-import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
@@ -109,11 +108,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer {
if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), methodName.toString()));
ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
for (int i = 0; i < suffixes.size(); i++) {
- JCExpression pt = cloneParamType(i, maker, data.getTypeArgs(), builderType, source);
- List<JCAnnotation> typeUseAnns = getTypeUseAnnotations(pt);
- pt = removeTypeUseAnnotations(pt);
- JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns);
- JCVariableDecl p = maker.VarDef(paramMods, names[i], pt, null);
+ JCVariableDecl p = generateSingularMethodParameter(i, maker, data, builderType, source, names[i], paramFlags);
params.append(p);
}
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
index 79d5166e..665e22ea 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
@@ -36,12 +36,10 @@ import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
import com.sun.tools.javac.tree.JCTree.JCStatement;
-import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
@@ -112,11 +110,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString()));
Name paramName = data.getSingularName();
- JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
- List<JCAnnotation> typeUseAnns = getTypeUseAnnotations(paramType);
- paramType = removeTypeUseAnnotations(paramType);
- JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns);
- JCVariableDecl param = maker.VarDef(paramMods, paramName, paramType, null);
+ JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, paramName, paramFlags);
finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param));
}
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
index 9373512a..8b5f08eb 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
@@ -45,7 +45,6 @@ import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
import com.sun.tools.javac.tree.JCTree.JCStatement;
-import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
@@ -150,17 +149,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
Name name = data.getSingularName();
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString()));
- JCExpression paramTypeKey = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
- List<JCAnnotation> typeUseAnnsKey = getTypeUseAnnotations(paramTypeKey);
- paramTypeKey = removeTypeUseAnnotations(paramTypeKey);
- JCModifiers paramModsKey = typeUseAnnsKey.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsKey);
- JCVariableDecl paramKey = maker.VarDef(paramModsKey, keyName, paramTypeKey, null);
-
- JCExpression paramTypeValue = cloneParamType(1, maker, data.getTypeArgs(), builderType, source);
- List<JCAnnotation> typeUseAnnsValue = getTypeUseAnnotations(paramTypeValue);
- paramTypeValue = removeTypeUseAnnotations(paramTypeValue);
- JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue);
- JCVariableDecl paramValue = maker.VarDef(paramModsValue, valueName, paramTypeValue, null);
+ JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName, paramFlags);
+ JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName, paramFlags);
finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(paramKey, paramValue));
}