Set @Singularize code for javac improved, Map @Singularize added.

This commit is contained in:
Reinier Zwitserloot
2015-01-11 22:38:22 +01:00
parent 8bfd1a2767
commit 6894fa31e8
12 changed files with 685 additions and 173 deletions
+1 -10
View File
@@ -556,16 +556,7 @@ You can also create your own by writing a 'testenvironment.properties' file. The
<classpath path="build/tests" />
<batchtest>
<fileset dir="test/core/src">
<include name="**/Test*.java" />
</fileset>
<fileset dir="test/transform/src">
<include name="**/Test*.java" />
</fileset>
<fileset dir="test/bytecode/src">
<include name="**/Test*.java" />
</fileset>
<fileset dir="test/configuration/src">
<include name="**/Test*.java" />
<include name="lombok/RunAllTests.java" />
</fileset>
</batchtest>
</junit>
@@ -81,7 +81,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
Name name;
SingularData singularData;
JavacNode mainCreatedField;
java.util.List<JavacNode> createdFields = new ArrayList<JavacNode>();
}
@Override public void handle(AnnotationValues<Builder> annotation, JCAnnotation ast, JavacNode annotationNode) {
@@ -260,8 +260,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
if (methodExists("toString", builderType, 0) == MemberExistsResult.NOT_EXISTS) {
java.util.List<JavacNode> fieldNodes = new ArrayList<JavacNode>();
for (BuilderFieldData bfd : builderFields) {
JavacNode mcf = bfd.mainCreatedField;
if (mcf != null) fieldNodes.add(mcf);
fieldNodes.addAll(bfd.createdFields);
}
JCMethodDecl md = HandleToString.createToString(builderType, fieldNodes, true, false, FieldAccess.ALWAYS_FIELD, ast);
if (md != null) injectMethod(builderType, md);
@@ -382,26 +381,26 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
for (int i = len - 1; i >= 0; i--) {
BuilderFieldData bfd = builderFields.get(i);
if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
bfd.mainCreatedField = bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType, source);
bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType, source));
} else {
for (JavacNode exists : existing) {
Name n = ((JCVariableDecl) exists.get()).name;
if (n.equals(bfd.name)) {
bfd.mainCreatedField = exists;
bfd.createdFields.add(exists);
continue top;
}
}
JavacTreeMaker maker = builderType.getTreeMaker();
JCModifiers mods = maker.Modifiers(Flags.PRIVATE);
JCVariableDecl newField = maker.VarDef(mods, bfd.name, cloneType(maker, bfd.type, source, builderType.getContext()), null);
bfd.mainCreatedField = injectField(builderType, newField);
bfd.createdFields.add(injectField(builderType, newField));
}
}
}
public void makeSetterMethodForBuilder(JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, boolean fluent, boolean chain) {
if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) {
makeSimpleSetterMethodForBuilder(builderType, fieldNode.mainCreatedField, source, fluent, chain);
makeSimpleSetterMethodForBuilder(builderType, fieldNode.createdFields.get(0), source, fluent, chain);
} else {
fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, builderType, source.get(), fluent, chain);
}
@@ -21,6 +21,7 @@
*/
package lombok.javac.handlers;
import static lombok.javac.Javac.*;
import static lombok.javac.handlers.JavacHandlerUtil.*;
import java.io.IOException;
@@ -126,12 +127,17 @@ public class JavacSingularsRecipes {
public JavacSingularizer getSingularizer() {
return singularizer;
}
public String getTargetSimpleType() {
int idx = targetFqn.lastIndexOf(".");
return idx == -1 ? targetFqn : targetFqn.substring(idx + 1);
}
}
public static abstract class JavacSingularizer {
public abstract LombokImmutableList<String> getSupportedTypes();
public abstract JavacNode generateFields(SingularData data, JavacNode builderType, JCTree source);
public abstract java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source);
public abstract void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain);
public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName);
@@ -204,11 +210,35 @@ public class JavacSingularsRecipes {
return maker.TypeApply(type, arguments.toList());
}
/** Generates 'this.<em>name</em>.size()' as an expression. */
protected JCExpression getSize(JavacTreeMaker maker, JavacNode builderType, Name name) {
JCExpression fn = maker.Select(maker.Select(maker.Ident(builderType.toName("this")), name), builderType.toName("size"));
return maker.Apply(List.<JCExpression>nil(), fn, List.<JCExpression>nil());
/** Generates 'this.<em>name</em>.size()' as an expression; if nullGuard is true, it's this.name == null ? 0 : this.name.size(). */
protected JCExpression getSize(JavacTreeMaker maker, JavacNode builderType, Name name, boolean nullGuard) {
Name thisName = builderType.toName("this");
JCExpression fn = maker.Select(maker.Select(maker.Ident(thisName), name), builderType.toName("size"));
JCExpression sizeInvoke = maker.Apply(List.<JCExpression>nil(), fn, List.<JCExpression>nil());
if (nullGuard) {
JCExpression isNull = maker.Binary(CTC_EQUAL, maker.Select(maker.Ident(thisName), name), maker.Literal(CTC_BOT, 0));
return maker.Conditional(isNull, maker.Literal(CTC_INT, 0), sizeInvoke);
}
return sizeInvoke;
}
protected JCExpression cloneParamType(int index, JavacTreeMaker maker, List<JCExpression> typeArgs, JavacNode builderType, JCTree source) {
if (typeArgs == null || typeArgs.size() <= index) {
return chainDots(builderType, "java", "lang", "Object");
} else {
JCExpression originalType = typeArgs.get(index);
if (originalType.getKind() == Kind.UNBOUNDED_WILDCARD || originalType.getKind() == Kind.SUPER_WILDCARD) {
return chainDots(builderType, "java", "lang", "Object");
} else if (originalType.getKind() == Kind.EXTENDS_WILDCARD) {
try {
return cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source, builderType.getContext());
} catch (Exception e) {
return chainDots(builderType, "java", "lang", "Object");
}
} else {
return cloneType(maker, originalType, source, builderType.getContext());
}
}
}
}
}
@@ -0,0 +1,167 @@
/*
* Copyright (C) 2015 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lombok.javac.handlers.singulars;
import static lombok.javac.Javac.*;
import static lombok.javac.handlers.JavacHandlerUtil.*;
import java.util.Arrays;
import lombok.core.LombokImmutableList;
import lombok.core.handlers.HandlerUtil;
import lombok.javac.JavacNode;
import lombok.javac.JavacTreeMaker;
import lombok.javac.handlers.JavacHandlerUtil;
import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer;
import lombok.javac.handlers.JavacSingularsRecipes.SingularData;
import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
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;
import com.sun.tools.javac.util.Name;
@ProviderFor(JavacSingularizer.class)
public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
@Override public LombokImmutableList<String> getSupportedTypes() {
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap");
}
@Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) {
JavacTreeMaker maker = builderType.getTreeMaker();
JCVariableDecl buildKeyField; {
JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList");
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source);
buildKeyField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), builderType.toName(data.getPluralName() + "$key"), type, null);
}
JCVariableDecl buildValueField; {
JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList");
List<JCExpression> tArgs = data.getTypeArgs();
if (tArgs != null && tArgs.size() > 1) tArgs = tArgs.tail;
else tArgs = List.nil();
type = addTypeArgs(1, false, builderType, type, tArgs, source);
buildValueField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), builderType.toName(data.getPluralName() + "$value"), type, null);
}
JavacNode valueFieldNode = injectField(builderType, buildValueField);
JavacNode keyFieldNode = injectField(builderType, buildKeyField);
return Arrays.asList(keyFieldNode, valueFieldNode);
}
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
JavacTreeMaker maker = builderType.getTreeMaker();
JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
}
private void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source));
Name keyName = builderType.toName(data.getSingularName().toString() + "Key");
Name valueName = builderType.toName(data.getSingularName().toString() + "Value");
/* this.pluralname$key.add(singularnameKey); */ {
JCExpression thisDotKeyFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$key", "add");
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotKeyFieldDotAdd, List.<JCExpression>of(maker.Ident(keyName)));
statements.append(maker.Exec(invokeAdd));
}
/* this.pluralname$value.add(singularnameValue); */ {
JCExpression thisDotValueFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$value", "add");
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotValueFieldDotAdd, List.<JCExpression>of(maker.Ident(valueName)));
statements.append(maker.Exec(invokeAdd));
}
if (returnStatement != null) statements.append(returnStatement);
JCBlock body = maker.Block(0, statements.toList());
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
Name name = data.getSingularName();
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString()));
JCExpression paramTypeKey = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
JCExpression paramTypeValue = cloneParamType(1, maker, data.getTypeArgs(), builderType, source);
JCVariableDecl paramKey = maker.VarDef(maker.Modifiers(paramFlags), keyName, paramTypeKey, null);
JCVariableDecl paramValue = maker.VarDef(maker.Modifiers(paramFlags), valueName, paramTypeValue, null);
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(paramKey, paramValue), thrown, body, null);
injectMethod(builderType, method);
}
private void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> jceBlank = List.nil();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source));
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext());
Name entryName = builderType.toName("$lombokEntry");
JCExpression forEachType = chainDots(builderType, "java", "util", "Map", "Entry");
forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs(), source);
JCExpression keyArg = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(entryName), builderType.toName("getKey")), List.<JCExpression>nil());
JCExpression valueArg = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(entryName), builderType.toName("getValue")), List.<JCExpression>nil());
JCExpression addKey = maker.Apply(List.<JCExpression>nil(), chainDots(builderType, "this", data.getPluralName() + "$key", "add"), List.of(keyArg));
JCExpression addValue = maker.Apply(List.<JCExpression>nil(), chainDots(builderType, "this", data.getPluralName() + "$value", "add"), List.of(valueArg));
JCBlock forEachBody = maker.Block(0, List.<JCStatement>of(maker.Exec(addKey), maker.Exec(addValue)));
JCExpression entrySetInvocation = maker.Apply(jceBlank, maker.Select(maker.Ident(data.getPluralName()), builderType.toName("entrySet")), jceBlank);
JCStatement forEach = maker.ForeachLoop(maker.VarDef(maker.Modifiers(baseFlags), entryName, forEachType, null), entrySetInvocation, forEachBody);
statements.append(forEach);
if (returnStatement != null) statements.append(returnStatement);
JCBlock body = maker.Block(0, statements.toList());
Name name = data.getPluralName();
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("putAll", name.toString()));
JCExpression paramType = chainDots(builderType, "java", "util", "Map");
paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source);
JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null);
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), jceBlank, body, null);
injectMethod(builderType, method);
}
@Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) {
JavacTreeMaker maker = builderType.getTreeMaker();
if (data.getTargetFqn().equals("java.util.Map")) {
statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, true, "emptyMap", "singletonMap", "LinkedHashMap", source));
} else {
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, true, true, false, true, "TreeMap", source));
}
}
}
@@ -23,6 +23,8 @@ package lombok.javac.handlers.singulars;
import static lombok.javac.handlers.JavacHandlerUtil.*;
import java.util.Collections;
import org.mangosdk.spi.ProviderFor;
import lombok.core.LombokImmutableList;
@@ -34,7 +36,6 @@ import lombok.javac.handlers.JavacHandlerUtil;
import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer;
import lombok.javac.handlers.JavacSingularsRecipes.SingularData;
import com.sun.source.tree.Tree.Kind;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCBlock;
@@ -44,7 +45,6 @@ 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.tree.JCTree.JCWildcard;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
@@ -55,21 +55,23 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilSingularizer {
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet");
}
@Override public JavacNode generateFields(SingularData data, JavacNode builderType, JCTree source) {
@Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) {
JavacTreeMaker maker = builderType.getTreeMaker();
JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList");
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source);
JCVariableDecl buildField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), data.getPluralName(), type, null);
return injectField(builderType, buildField);
return Collections.singletonList(injectField(builderType, buildField));
}
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
JavacTreeMaker maker = builderType.getTreeMaker();
JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
}
@@ -78,6 +80,7 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilSingularizer {
List<JCExpression> thrown = List.nil();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
statements.append(maker.Exec(invokeAdd));
@@ -86,24 +89,7 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilSingularizer {
Name name = data.getSingularName();
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString()));
JCExpression paramType; {
if (data.getTypeArgs() == null || data.getTypeArgs().isEmpty()) {
paramType = chainDots(builderType, "java", "lang", "Object");
} else {
JCExpression originalType = data.getTypeArgs().head;
if (originalType.getKind() == Kind.UNBOUNDED_WILDCARD || originalType.getKind() == Kind.SUPER_WILDCARD) {
paramType = chainDots(builderType, "java", "lang", "Object");
} else if (originalType.getKind() == Kind.EXTENDS_WILDCARD) {
try {
paramType = cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source, builderType.getContext());
} catch (Exception e) {
paramType = chainDots(builderType, "java", "lang", "Object");
}
} else {
paramType = cloneType(maker, originalType, source, builderType.getContext());
}
}
}
JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null);
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
injectMethod(builderType, method);
@@ -114,6 +100,7 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilSingularizer {
List<JCExpression> thrown = List.nil();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll");
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
statements.append(maker.Exec(invokeAdd));
@@ -131,24 +118,11 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilSingularizer {
@Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) {
JavacTreeMaker maker = builderType.getTreeMaker();
JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn());
localShadowerType = addTypeArgs(1, false, builderType, localShadowerType, data.getTypeArgs(), source);
JCExpression constructTargetType; {
if (data.getTargetFqn().equals("java.util.Set")) {
JCExpression loadFactor = maker.Literal(CTC_FLOAT, 0.75f);
JCExpression internalType = chainDots(builderType, "java", "util", "LinkedHashSet");
internalType = addTypeArgs(1, false, builderType, internalType, data.getTypeArgs(), source);
JCExpression initialCapacity = createJavaUtilSetMapInitialCapacityExpression(maker, data, builderType);
constructTargetType = maker.NewClass(null, List.<JCExpression>nil(), internalType, List.<JCExpression>of(initialCapacity, loadFactor), null);
} else {
JCExpression internalType = chainDots(builderType, "java", "util", "TreeSet");
internalType = addTypeArgs(1, false, builderType, internalType, data.getTypeArgs(), source);
constructTargetType = maker.NewClass(null, List.<JCExpression>nil(), internalType, List.<JCExpression>nil(), null);
}
}
JCVariableDecl varDef = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, constructTargetType);
statements.append(varDef);
stuffJavaUtilCollectionAndWrapWithUnmodifiable(data, builderType, statements, maker, "addAll");
if (data.getTargetFqn().equals("java.util.Set")) {
statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, false, "emptySet", "singleton", "LinkedHashSet", source));
} else {
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, false, true, false, true, "TreeSet", source));
}
}
}
@@ -22,13 +22,15 @@
package lombok.javac.handlers.singulars;
import static lombok.javac.Javac.*;
import static lombok.javac.handlers.JavacHandlerUtil.chainDots;
import static lombok.javac.handlers.JavacHandlerUtil.*;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCase;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
import lombok.javac.JavacNode;
import lombok.javac.JavacTreeMaker;
@@ -36,24 +38,148 @@ import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer;
import lombok.javac.handlers.JavacSingularsRecipes.SingularData;
public abstract class JavacJavaUtilSingularizer extends JavacSingularizer {
protected JCExpression createJavaUtilSetMapInitialCapacityExpression(JavacTreeMaker maker, SingularData data, JavacNode builderType) {
JCExpression lessThanCutoff = maker.Binary(CTC_LESS_THAN, getSize(maker, builderType, data.getPluralName()), maker.Literal(CTC_INT, 0x40000000));
JCExpression maxInt = chainDots(builderType, "java", "lang", "Integer", "MAX_VALUE");
JCExpression belowThree = maker.Binary(CTC_LESS_THAN, getSize(maker, builderType, data.getPluralName()), maker.Literal(CTC_INT, 3));
JCExpression sizePlusOne = maker.Binary(CTC_PLUS, getSize(maker, builderType, data.getPluralName()), maker.Literal(CTC_INT, 1));
JCExpression sizeDivThree = maker.Binary(CTC_DIV, getSize(maker, builderType, data.getPluralName()), maker.Literal(CTC_INT, 3));
JCExpression sizePlusSizeDivThree = maker.Binary(CTC_PLUS, getSize(maker, builderType, data.getPluralName()), sizeDivThree);
JCExpression rest = maker.Conditional(belowThree, sizePlusOne, sizePlusSizeDivThree);
JCExpression initialCapacity = maker.Conditional(lessThanCutoff, rest, maxInt);
return initialCapacity;
protected List<JCStatement> createJavaUtilSetMapInitialCapacitySwitchStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType, JCTree source) {
List<JCExpression> jceBlank = List.nil();
ListBuffer<JCCase> cases = new ListBuffer<JCCase>();
if (emptyCollectionMethod != null) { // case 0: (empty); break;
JCStatement assignStat; {
// pluralName = java.util.Collections.emptyCollectionMethod();
JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", emptyCollectionMethod), jceBlank);
assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
}
JCStatement breakStat = maker.Break(null);
JCCase emptyCase = maker.Case(maker.Literal(CTC_INT, 0), List.of(assignStat, breakStat));
cases.append(emptyCase);
}
if (singletonCollectionMethod != null) { // case 1: (singleton); break;
JCStatement assignStat; {
// !mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName.get(0));
// mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName$key.get(0), this.pluralName$value.get(0));
JCExpression zeroLiteral = maker.Literal(CTC_INT, 0);
JCExpression arg = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + (mapMode ? "$key" : "").toString(), "get"), List.of(zeroLiteral));
List<JCExpression> args;
if (mapMode) {
JCExpression zeroLiteralClone = maker.Literal(CTC_INT, 0);
JCExpression arg2 = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + (mapMode ? "$value" : "").toString(), "get"), List.of(zeroLiteralClone));
args = List.of(arg, arg2);
} else {
args = List.of(arg);
}
JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", singletonCollectionMethod), args);
assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
}
JCStatement breakStat = maker.Break(null);
JCCase singletonCase = maker.Case(maker.Literal(CTC_INT, 1), List.of(assignStat, breakStat));
cases.append(singletonCase);
}
{ // default:
List<JCStatement> statements = createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, mapMode, false, true, emptyCollectionMethod == null, targetType, source);
JCCase defaultCase = maker.Case(null, statements);
cases.append(defaultCase);
}
JCStatement switchStat = maker.Switch(getSize(maker, builderType, mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName(), true), cases.toList());
JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn());
localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs(), source);
JCStatement varDefStat = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, null);
return List.of(varDefStat, switchStat);
}
protected void stuffJavaUtilCollectionAndWrapWithUnmodifiable(SingularData data, JavacNode builderType, ListBuffer<JCStatement> statements, JavacTreeMaker maker, String addAllName) {
JCFieldAccess varDotAddAll = maker.Select(maker.Ident(data.getPluralName()), builderType.toName(addAllName));
JCExpression thisDotFieldName = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName());
statements.append(maker.Exec(maker.Apply(List.<JCExpression>nil(), varDotAddAll, List.of(thisDotFieldName))));
String singletonMaker = "unmodifiable" + data.getTargetFqn().substring(data.getTargetFqn().lastIndexOf(".") + 1);
JCExpression javaUtilCollectionsInvoke = maker.Apply(List.<JCExpression>nil(), chainDots(builderType, "java", "util", "Collections", singletonMaker), List.<JCExpression>of(maker.Ident(data.getPluralName())));
statements.append(maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), javaUtilCollectionsInvoke)));
protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, JCTree source) {
List<JCExpression> jceBlank = List.nil();
Name v1Name = mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName();
Name v2Name = mapMode ? builderType.toName(data.getPluralName() + "$value") : null;
JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), v1Name);
JCExpression cond = maker.Binary(CTC_EQUAL, thisDotField, maker.Literal(CTC_BOT, null));
thisDotField = maker.Select(maker.Ident(builderType.toName("this")), v1Name);
JCExpression v1Type = chainDots(builderType, "java", "util", "ArrayList");
v1Type = addTypeArgs(1, false, builderType, v1Type, data.getTypeArgs(), source);
JCExpression constructArrayList = maker.NewClass(null, jceBlank, v1Type, jceBlank, null);
JCStatement initV1 = maker.Exec(maker.Assign(thisDotField, constructArrayList));
JCStatement thenPart;
if (mapMode) {
thisDotField = maker.Select(maker.Ident(builderType.toName("this")), v2Name);
JCExpression v2Type = chainDots(builderType, "java", "util", "ArrayList");
List<JCExpression> tArgs = data.getTypeArgs();
if (tArgs != null && tArgs.tail != null) tArgs = tArgs.tail;
else tArgs = List.nil();
v2Type = addTypeArgs(1, false, builderType, v2Type, tArgs, source);
constructArrayList = maker.NewClass(null, jceBlank, v2Type, jceBlank, null);
JCStatement initV2 = maker.Exec(maker.Assign(thisDotField, constructArrayList));
thenPart = maker.Block(0, List.of(initV1, initV2));
} else {
thenPart = initV1;
}
return maker.If(cond, thenPart, null);
}
protected List<JCStatement> createJavaUtilSimpleCreationAndFillStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, boolean defineVar, boolean addInitialCapacityArg, boolean nullGuard, String targetType, JCTree source) {
List<JCExpression> jceBlank = List.nil();
Name thisName = builderType.toName("this");
JCStatement createStat; {
// pluralName = new java.util.TargetType(initialCap);
List<JCExpression> constructorArgs = List.nil();
if (addInitialCapacityArg) {
Name varName = mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName();
// this.varName.size() < MAX_POWER_OF_2 ? 1 + this.varName.size() + (this.varName.size() - 3) / 3 : Integer.MAX_VALUE;
// lessThanCutOff = this.varName.size() < MAX_POWER_OF_2
JCExpression lessThanCutoff = maker.Binary(CTC_LESS_THAN, getSize(maker, builderType, varName, nullGuard), maker.Literal(CTC_INT, 0x40000000));
JCExpression integerMaxValue = chainDots(builderType, "java", "lang", "Integer", "MAX_VALUE");
JCExpression sizeFormulaLeft = maker.Binary(CTC_PLUS, maker.Literal(CTC_INT, 1), getSize(maker, builderType, varName, nullGuard));
JCExpression sizeFormulaRightLeft = maker.Binary(CTC_MINUS, getSize(maker, builderType, varName, nullGuard), maker.Literal(CTC_INT, 3));
JCExpression sizeFormulaRight = maker.Binary(CTC_DIV, sizeFormulaRightLeft, maker.Literal(CTC_INT, 3));
JCExpression sizeFormula = maker.Binary(CTC_PLUS, sizeFormulaLeft, sizeFormulaRight);
constructorArgs = List.<JCExpression>of(maker.Conditional(lessThanCutoff, sizeFormula, integerMaxValue));
}
JCExpression targetTypeExpr = chainDots(builderType, "java", "util", targetType);
targetTypeExpr = addTypeArgs(mapMode ? 2 : 1, false, builderType, targetTypeExpr, data.getTypeArgs(), source);
JCExpression constructorCall = maker.NewClass(null, jceBlank, targetTypeExpr, constructorArgs, null);
if (defineVar) {
JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn());
localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs(), source);
createStat = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, constructorCall);
} else {
createStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), constructorCall));
}
}
JCStatement fillStat; {
if (mapMode) {
// for (int $i = 0; $i < this.pluralname$key.size(); i++) pluralname.put(this.pluralname$key.get($i), this.pluralname$value.get($i));
Name ivar = builderType.toName("$i");
Name keyVarName = builderType.toName(data.getPluralName() + "$key");
JCExpression pluralnameDotPut = maker.Select(maker.Ident(data.getPluralName()), builderType.toName("put"));
JCExpression arg1 = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + "$key", "get"), List.<JCExpression>of(maker.Ident(ivar)));
JCExpression arg2 = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + "$value", "get"), List.<JCExpression>of(maker.Ident(ivar)));
JCStatement putStatement = maker.Exec(maker.Apply(jceBlank, pluralnameDotPut, List.of(arg1, arg2)));
JCStatement forInit = maker.VarDef(maker.Modifiers(0), ivar, maker.TypeIdent(CTC_INT), maker.Literal(CTC_INT, 0));
JCExpression checkExpr = maker.Binary(CTC_LESS_THAN, maker.Ident(ivar), getSize(maker, builderType, keyVarName, nullGuard));
JCExpression incrementExpr = maker.Unary(CTC_POSTINC, maker.Ident(ivar));
fillStat = maker.ForLoop(List.of(forInit), checkExpr, List.of(maker.Exec(incrementExpr)), putStatement);
} else {
// 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)));
}
if (nullGuard) {
JCExpression thisDotField = maker.Select(maker.Ident(thisName), mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName());
JCExpression nullCheck = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null));
fillStat = maker.If(nullCheck, fillStat, null);
}
}
JCStatement unmodifiableStat; {
// pluralname = Collections.unmodifiableInterfaceType(pluralname);
JCExpression arg = maker.Ident(data.getPluralName());
JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "unmodifiable" + data.getTargetSimpleType()), List.of(arg));
unmodifiableStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
}
return List.of(createStat, fillStat, unmodifiableStat);
}
}
+3
View File
@@ -178,9 +178,12 @@ public class Javac {
public static final TreeTag CTC_MUL = treeTag("MUL");
public static final TreeTag CTC_DIV = treeTag("DIV");
public static final TreeTag CTC_PLUS = treeTag("PLUS");
public static final TreeTag CTC_MINUS = treeTag("MINUS");
public static final TreeTag CTC_EQUAL = treeTag("EQ");
public static final TreeTag CTC_PREINC = treeTag("PREINC");
public static final TreeTag CTC_PREDEC = treeTag("PREDEC");
public static final TreeTag CTC_POSTINC = treeTag("POSTINC");
public static final TreeTag CTC_POSTDEC = treeTag("POSTDEC");
private static final Method getExtendsClause, getEndPosition, storeEnd;
@@ -0,0 +1,172 @@
import java.util.Map;
import java.util.SortedMap;
class BuilderSingletonMaps<K, V> {
private Map<K, V> women;
private SortedMap<K, ? extends Number> men;
private Map rawMap;
private Map<String, V> stringMap;
@java.lang.SuppressWarnings("all")
BuilderSingletonMaps(final Map<K, V> women, final SortedMap<K, ? extends Number> men, final Map rawMap, final Map<String, V> stringMap) {
this.women = women;
this.men = men;
this.rawMap = rawMap;
this.stringMap = stringMap;
}
@java.lang.SuppressWarnings("all")
public static class BuilderSingletonMapsBuilder<K, V> {
private java.util.ArrayList<K> women$key;
private java.util.ArrayList<V> women$value;
private java.util.ArrayList<K> men$key;
private java.util.ArrayList<Number> men$value;
private java.util.ArrayList<java.lang.Object> rawMap$key;
private java.util.ArrayList<java.lang.Object> rawMap$value;
private java.util.ArrayList<String> stringMap$key;
private java.util.ArrayList<V> stringMap$value;
@java.lang.SuppressWarnings("all")
BuilderSingletonMapsBuilder() {
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> woman(final K womanKey, final V womanValue) {
if (this.women$key == null) {
this.women$key = new java.util.ArrayList<K>();
this.women$value = new java.util.ArrayList<V>();
}
this.women$key.add(womanKey);
this.women$value.add(womanValue);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> women(final java.util.Map<? extends K, ? extends V> women) {
if (this.women$key == null) {
this.women$key = new java.util.ArrayList<K>();
this.women$value = new java.util.ArrayList<V>();
}
for (final java.util.Map.Entry<? extends K, ? extends V> $lombokEntry : women.entrySet()) {
this.women$key.add($lombokEntry.getKey());
this.women$value.add($lombokEntry.getValue());
}
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> man(final K manKey, final Number manValue) {
if (this.men$key == null) {
this.men$key = new java.util.ArrayList<K>();
this.men$value = new java.util.ArrayList<Number>();
}
this.men$key.add(manKey);
this.men$value.add(manValue);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> men(final java.util.Map<? extends K, ? extends Number> men) {
if (this.men$key == null) {
this.men$key = new java.util.ArrayList<K>();
this.men$value = new java.util.ArrayList<Number>();
}
for (final java.util.Map.Entry<? extends K, ? extends Number> $lombokEntry : men.entrySet()) {
this.men$key.add($lombokEntry.getKey());
this.men$value.add($lombokEntry.getValue());
}
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> rawMap(final java.lang.Object rawMapKey, final java.lang.Object rawMapValue) {
if (this.rawMap$key == null) {
this.rawMap$key = new java.util.ArrayList<java.lang.Object>();
this.rawMap$value = new java.util.ArrayList<java.lang.Object>();
}
this.rawMap$key.add(rawMapKey);
this.rawMap$value.add(rawMapValue);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> rawMap(final java.util.Map<?, ?> rawMap) {
if (this.rawMap$key == null) {
this.rawMap$key = new java.util.ArrayList<java.lang.Object>();
this.rawMap$value = new java.util.ArrayList<java.lang.Object>();
}
for (final java.util.Map.Entry<?, ?> $lombokEntry : rawMap.entrySet()) {
this.rawMap$key.add($lombokEntry.getKey());
this.rawMap$value.add($lombokEntry.getValue());
}
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> stringMap(final String stringMapKey, final V stringMapValue) {
if (this.stringMap$key == null) {
this.stringMap$key = new java.util.ArrayList<String>();
this.stringMap$value = new java.util.ArrayList<V>();
}
this.stringMap$key.add(stringMapKey);
this.stringMap$value.add(stringMapValue);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMapsBuilder<K, V> stringMap(final java.util.Map<? extends String, ? extends V> stringMap) {
if (this.stringMap$key == null) {
this.stringMap$key = new java.util.ArrayList<String>();
this.stringMap$value = new java.util.ArrayList<V>();
}
for (final java.util.Map.Entry<? extends String, ? extends V> $lombokEntry : stringMap.entrySet()) {
this.stringMap$key.add($lombokEntry.getKey());
this.stringMap$value.add($lombokEntry.getValue());
}
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonMaps<K, V> build() {
java.util.Map<K, V> women;
switch (this.women$key == null ? 0 : this.women$key.size()) {
case 0:
women = java.util.Collections.emptyMap();
break;
case 1:
women = java.util.Collections.singletonMap(this.women$key.get(0), this.women$value.get(0));
break;
default:
women = new java.util.LinkedHashMap<K, V>(this.women$key.size() < 1073741824 ? 1 + this.women$key.size() + (this.women$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
for (int $i = 0; $i < this.women$key.size(); $i++) women.put(this.women$key.get($i), this.women$value.get($i));
women = java.util.Collections.unmodifiableMap(women);
}
java.util.SortedMap<K, Number> men = new java.util.TreeMap<K, Number>();
if (this.men$key != null) for (int $i = 0; $i < (this.men$key == null ? 0 : this.men$key.size()); $i++) men.put(this.men$key.get($i), this.men$value.get($i));
men = java.util.Collections.unmodifiableSortedMap(men);
java.util.Map<java.lang.Object, java.lang.Object> rawMap;
switch (this.rawMap$key == null ? 0 : this.rawMap$key.size()) {
case 0:
rawMap = java.util.Collections.emptyMap();
break;
case 1:
rawMap = java.util.Collections.singletonMap(this.rawMap$key.get(0), this.rawMap$value.get(0));
break;
default:
rawMap = new java.util.LinkedHashMap<java.lang.Object, java.lang.Object>(this.rawMap$key.size() < 1073741824 ? 1 + this.rawMap$key.size() + (this.rawMap$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
for (int $i = 0; $i < this.rawMap$key.size(); $i++) rawMap.put(this.rawMap$key.get($i), this.rawMap$value.get($i));
rawMap = java.util.Collections.unmodifiableMap(rawMap);
}
java.util.Map<String, V> stringMap;
switch (this.stringMap$key == null ? 0 : this.stringMap$key.size()) {
case 0:
stringMap = java.util.Collections.emptyMap();
break;
case 1:
stringMap = java.util.Collections.singletonMap(this.stringMap$key.get(0), this.stringMap$value.get(0));
break;
default:
stringMap = new java.util.LinkedHashMap<String, V>(this.stringMap$key.size() < 1073741824 ? 1 + this.stringMap$key.size() + (this.stringMap$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
for (int $i = 0; $i < this.stringMap$key.size(); $i++) stringMap.put(this.stringMap$key.get($i), this.stringMap$value.get($i));
stringMap = java.util.Collections.unmodifiableMap(stringMap);
}
return new BuilderSingletonMaps<K, V>(women, men, rawMap, stringMap);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "BuilderSingletonMaps.BuilderSingletonMapsBuilder(women$key=" + this.women$key + ", women$value=" + this.women$value + ", men$key=" + this.men$key + ", men$value=" + this.men$value + ", rawMap$key=" + this.rawMap$key + ", rawMap$value=" + this.rawMap$value + ", stringMap$key=" + this.stringMap$key + ", stringMap$value=" + this.stringMap$value + ")";
}
}
@java.lang.SuppressWarnings("all")
public static <K, V> BuilderSingletonMapsBuilder<K, V> builder() {
return new BuilderSingletonMapsBuilder<K, V>();
}
}
@@ -0,0 +1,128 @@
import java.util.Set;
import java.util.SortedSet;
class BuilderSingletonSets<T> {
private Set<T> dangerMice;
private SortedSet<? extends Number> octopodes;
private Set rawSet;
private Set<String> stringSet;
@java.lang.SuppressWarnings("all")
BuilderSingletonSets(final Set<T> dangerMice, final SortedSet<? extends Number> octopodes, final Set rawSet, final Set<String> stringSet) {
this.dangerMice = dangerMice;
this.octopodes = octopodes;
this.rawSet = rawSet;
this.stringSet = stringSet;
}
@java.lang.SuppressWarnings("all")
public static class BuilderSingletonSetsBuilder<T> {
private java.util.ArrayList<T> dangerMice;
private java.util.ArrayList<Number> octopodes;
private java.util.ArrayList<java.lang.Object> rawSet;
private java.util.ArrayList<String> stringSet;
@java.lang.SuppressWarnings("all")
BuilderSingletonSetsBuilder() {
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> dangerMouse(final T dangerMouse) {
if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList<T>();
this.dangerMice.add(dangerMouse);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> dangerMice(final java.util.Collection<? extends T> dangerMice) {
if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList<T>();
this.dangerMice.addAll(dangerMice);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> octopus(final Number octopus) {
if (this.octopodes == null) this.octopodes = new java.util.ArrayList<Number>();
this.octopodes.add(octopus);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> octopodes(final java.util.Collection<? extends Number> octopodes) {
if (this.octopodes == null) this.octopodes = new java.util.ArrayList<Number>();
this.octopodes.addAll(octopodes);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> rawSet(final java.lang.Object rawSet) {
if (this.rawSet == null) this.rawSet = new java.util.ArrayList<java.lang.Object>();
this.rawSet.add(rawSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> rawSet(final java.util.Collection<?> rawSet) {
if (this.rawSet == null) this.rawSet = new java.util.ArrayList<java.lang.Object>();
this.rawSet.addAll(rawSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> stringSet(final String stringSet) {
if (this.stringSet == null) this.stringSet = new java.util.ArrayList<String>();
this.stringSet.add(stringSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSetsBuilder<T> stringSet(final java.util.Collection<? extends String> stringSet) {
if (this.stringSet == null) this.stringSet = new java.util.ArrayList<String>();
this.stringSet.addAll(stringSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonSets<T> build() {
java.util.Set<T> dangerMice;
switch (this.dangerMice == null ? 0 : this.dangerMice.size()) {
case 0:
dangerMice = java.util.Collections.emptySet();
break;
case 1:
dangerMice = java.util.Collections.singleton(this.dangerMice.get(0));
break;
default:
dangerMice = new java.util.LinkedHashSet<T>(this.dangerMice.size() < 1073741824 ? 1 + this.dangerMice.size() + (this.dangerMice.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
dangerMice.addAll(this.dangerMice);
dangerMice = java.util.Collections.unmodifiableSet(dangerMice);
}
java.util.SortedSet<Number> octopodes = new java.util.TreeSet<Number>();
if (this.octopodes != null) octopodes.addAll(this.octopodes);
octopodes = java.util.Collections.unmodifiableSortedSet(octopodes);
java.util.Set<java.lang.Object> rawSet;
switch (this.rawSet == null ? 0 : this.rawSet.size()) {
case 0:
rawSet = java.util.Collections.emptySet();
break;
case 1:
rawSet = java.util.Collections.singleton(this.rawSet.get(0));
break;
default:
rawSet = new java.util.LinkedHashSet<java.lang.Object>(this.rawSet.size() < 1073741824 ? 1 + this.rawSet.size() + (this.rawSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
rawSet.addAll(this.rawSet);
rawSet = java.util.Collections.unmodifiableSet(rawSet);
}
java.util.Set<String> stringSet;
switch (this.stringSet == null ? 0 : this.stringSet.size()) {
case 0:
stringSet = java.util.Collections.emptySet();
break;
case 1:
stringSet = java.util.Collections.singleton(this.stringSet.get(0));
break;
default:
stringSet = new java.util.LinkedHashSet<String>(this.stringSet.size() < 1073741824 ? 1 + this.stringSet.size() + (this.stringSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
stringSet.addAll(this.stringSet);
stringSet = java.util.Collections.unmodifiableSet(stringSet);
}
return new BuilderSingletonSets<T>(dangerMice, octopodes, rawSet, stringSet);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "BuilderSingletonSets.BuilderSingletonSetsBuilder(dangerMice=" + this.dangerMice + ", octopodes=" + this.octopodes + ", rawSet=" + this.rawSet + ", stringSet=" + this.stringSet + ")";
}
}
@java.lang.SuppressWarnings("all")
public static <T> BuilderSingletonSetsBuilder<T> builder() {
return new BuilderSingletonSetsBuilder<T>();
}
}
@@ -1,90 +0,0 @@
import java.util.Set;
import java.util.SortedSet;
class BuilderSingletons<T> {
private Set<T> dangerMice;
private SortedSet<? extends Number> octopodes;
private Set rawSet;
private Set<String> stringSet;
@java.lang.SuppressWarnings("all")
BuilderSingletons(final Set<T> dangerMice, final SortedSet<? extends Number> octopodes, final Set rawSet, final Set<String> stringSet) {
this.dangerMice = dangerMice;
this.octopodes = octopodes;
this.rawSet = rawSet;
this.stringSet = stringSet;
}
@java.lang.SuppressWarnings("all")
public static class BuilderSingletonsBuilder<T> {
private java.util.ArrayList<T> dangerMice;
private java.util.ArrayList<Number> octopodes;
private java.util.ArrayList<java.lang.Object> rawSet;
private java.util.ArrayList<String> stringSet;
@java.lang.SuppressWarnings("all")
BuilderSingletonsBuilder() {
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> dangerMouse(final T dangerMouse) {
this.dangerMice.add(dangerMouse);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> dangerMice(final java.util.Collection<? extends T> dangerMice) {
this.dangerMice.addAll(dangerMice);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> octopus(final Number octopus) {
this.octopodes.add(octopus);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> octopodes(final java.util.Collection<? extends Number> octopodes) {
this.octopodes.addAll(octopodes);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> rawSet(final java.lang.Object rawSet) {
this.rawSet.add(rawSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> rawSet(final java.util.Collection<?> rawSet) {
this.rawSet.addAll(rawSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> stringSet(final String stringSet) {
this.stringSet.add(stringSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletonsBuilder<T> stringSet(final java.util.Collection<? extends String> stringSet) {
this.stringSet.addAll(stringSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingletons<T> build() {
java.util.Set<T> dangerMice = new java.util.LinkedHashSet<T>(this.dangerMice.size() < 1073741824 ? this.dangerMice.size() < 3 ? this.dangerMice.size() + 1 : this.dangerMice.size() + this.dangerMice.size() / 3 : java.lang.Integer.MAX_VALUE, 0.75F);
dangerMice.addAll(this.dangerMice);
dangerMice = java.util.Collections.unmodifiableSet(dangerMice);
java.util.SortedSet<Number> octopodes = new java.util.TreeSet<Number>();
octopodes.addAll(this.octopodes);
octopodes = java.util.Collections.unmodifiableSortedSet(octopodes);
java.util.Set<java.lang.Object> rawSet = new java.util.LinkedHashSet<java.lang.Object>(this.rawSet.size() < 1073741824 ? this.rawSet.size() < 3 ? this.rawSet.size() + 1 : this.rawSet.size() + this.rawSet.size() / 3 : java.lang.Integer.MAX_VALUE, 0.75F);
rawSet.addAll(this.rawSet);
rawSet = java.util.Collections.unmodifiableSet(rawSet);
java.util.Set<String> stringSet = new java.util.LinkedHashSet<String>(this.stringSet.size() < 1073741824 ? this.stringSet.size() < 3 ? this.stringSet.size() + 1 : this.stringSet.size() + this.stringSet.size() / 3 : java.lang.Integer.MAX_VALUE, 0.75F);
stringSet.addAll(this.stringSet);
stringSet = java.util.Collections.unmodifiableSet(stringSet);
return new BuilderSingletons<T>(dangerMice, octopodes, rawSet, stringSet);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "BuilderSingletons.BuilderSingletonsBuilder(dangerMice=" + this.dangerMice + ", octopodes=" + this.octopodes + ", rawSet=" + this.rawSet + ", stringSet=" + this.stringSet + ")";
}
}
@java.lang.SuppressWarnings("all")
public static <T> BuilderSingletonsBuilder<T> builder() {
return new BuilderSingletonsBuilder<T>();
}
}
@@ -0,0 +1,12 @@
import java.util.Map;
import java.util.SortedMap;
import lombok.Singular;
@lombok.Builder
class BuilderSingletonMaps<K, V> {
@Singular private Map<K, V> women;
@Singular private SortedMap<K, ? extends Number> men;
@Singular("rawMap") private Map rawMap;
@Singular("stringMap") private Map<String, V> stringMap;
}
@@ -4,7 +4,7 @@ import java.util.SortedSet;
import lombok.Singular;
@lombok.Builder
class BuilderSingletons<T> {
class BuilderSingletonSets<T> {
@Singular private Set<T> dangerMice;
@Singular private SortedSet<? extends Number> octopodes;
@Singular("rawSet") private Set rawSet;