aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java29
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java25
2 files changed, 20 insertions, 34 deletions
diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java
index 0784ac4f..0a9eaf75 100644
--- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java
+++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
import lombok.core.LombokImmutableList;
+import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseNode;
import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer;
import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData;
@@ -90,34 +91,26 @@ public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingu
switchContents.add(new BreakStatement(null, 0, 0));
}
- /* default: Create with right size, then add all */ {
+ /* default: Create by passing builder field to constructor. */ {
switchContents.add(new CaseStatement(null, 0, 0));
- /* pluralName = new j.u.ArrayList<Generics>(this.pluralName.size()); */ {
- Expression[] args = new Expression[] {getSize(builderType, data.getPluralName(), false)};
+ Expression argToUnmodifiable;
+ /* new j.u.ArrayList<Generics>(this.pluralName); */ {
+ FieldReference thisDotPluralName = new FieldReference(data.getPluralName(), 0L);
+ thisDotPluralName.receiver = new ThisReference(0, 0);
TypeReference targetTypeExpr = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs());
AllocationExpression constructorCall = new AllocationExpression();
constructorCall.type = targetTypeExpr;
- constructorCall.arguments = args;
- switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0L), constructorCall, 0));
- }
-
- /* pluralname.addAll(this.pluralname); */ {
- FieldReference thisDotPluralName = new FieldReference(data.getPluralName(), 0L);
- thisDotPluralName.receiver = new ThisReference(0, 0);
- MessageSend addAllInvoke = new MessageSend();
- addAllInvoke.receiver = new SingleNameReference(data.getPluralName(), 0L);
- addAllInvoke.selector = new char[] { 'a', 'd', 'd', 'A', 'l', 'l' };
- addAllInvoke.arguments = new Expression[] {thisDotPluralName};
- switchContents.add(addAllInvoke);
+ constructorCall.arguments = new Expression[] {thisDotPluralName};
+ argToUnmodifiable = constructorCall;
}
- /* pluralname = Collections.unmodifiableList(pluralname); */ {
+ /* pluralname = Collections.unmodifiableList(-newlist-); */ {
MessageSend unmodInvoke = new MessageSend();
unmodInvoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0);
unmodInvoke.selector = "unmodifiableList".toCharArray();
- unmodInvoke.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
+ unmodInvoke.arguments = new Expression[] {argToUnmodifiable};
switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), unmodInvoke, 0));
}
}
@@ -126,7 +119,7 @@ public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingu
switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]);
switchStat.expression = getSize(builderType, data.getPluralName(), true);
- TypeReference localShadowerType = new QualifiedTypeReference(JAVA_UTIL_LIST, NULL_POSS);
+ TypeReference localShadowerType = new QualifiedTypeReference(Eclipse.fromQualifiedName(data.getTargetFqn()), NULL_POSS);
localShadowerType = addTypeArgs(1, false, builderType, localShadowerType, data.getTypeArgs());
LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0);
varDefStat.type = localShadowerType;
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java
index 2cf34cf7..65e91fa0 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java
@@ -88,7 +88,7 @@ public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingulari
}
JCStatement switchStat = maker.Switch(getSize(maker, builderType, data.getPluralName(), true), cases.toList());
- JCExpression localShadowerType = chainDots(builderType, "java", "util", "List");
+ JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn());
localShadowerType = addTypeArgs(1, false, builderType, localShadowerType, data.getTypeArgs(), source);
JCStatement varDefStat = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, null);
statements.append(varDefStat);
@@ -99,29 +99,22 @@ public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingulari
List<JCExpression> jceBlank = List.nil();
Name thisName = builderType.toName("this");
- JCStatement createStat; {
- // pluralName = new java.util.ArrayList<Generics>(this.pluralName.size());
+ JCExpression argToUnmodifiable; {
+ // new java.util.ArrayList<Generics>(this.pluralName);
List<JCExpression> constructorArgs = List.nil();
- constructorArgs = List.<JCExpression>of(getSize(maker, builderType, data.getPluralName(), false));
+ JCExpression thisDotPluralName = maker.Select(maker.Ident(thisName), data.getPluralName());
+ constructorArgs = List.<JCExpression>of(thisDotPluralName);
JCExpression targetTypeExpr = chainDots(builderType, "java", "util", "ArrayList");
targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs(), source);
- JCExpression constructorCall = maker.NewClass(null, jceBlank, targetTypeExpr, constructorArgs, null);
- createStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), constructorCall));
- }
-
- JCStatement fillStat; {
- // pluralname.addAll(this.pluralname);
- JCExpression thisDotPluralName = maker.Select(maker.Ident(thisName), data.getPluralName());
- fillStat = maker.Exec(maker.Apply(jceBlank, maker.Select(maker.Ident(data.getPluralName()), builderType.toName("addAll")), List.of(thisDotPluralName)));
+ argToUnmodifiable = maker.NewClass(null, jceBlank, targetTypeExpr, constructorArgs, null);
}
JCStatement unmodifiableStat; {
- // pluralname = Collections.unmodifiableInterfaceType(pluralname);
- JCExpression arg = maker.Ident(data.getPluralName());
- JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "unmodifiableList"), List.of(arg));
+ // pluralname = Collections.unmodifiableInterfaceType(-newlist-);
+ JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "unmodifiableList"), List.of(argToUnmodifiable));
unmodifiableStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
}
- return List.of(createStat, fillStat, unmodifiableStat);
+ return List.of(unmodifiableStat);
}
}