Skip to content

Commit 26580f5

Browse files
author
mp.samoylych
committed
Adding support for SequencedCollection, SequencedSet and SequencedMap from JDK 21
1 parent 1342aa8 commit 26580f5

File tree

11 files changed

+173
-15
lines changed

11 files changed

+173
-15
lines changed

buildScripts/tests.ant.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn
220220

221221
<target name="test.eclipse-202312" depends="test.compile, test.formatter.compile" description="runs the tests on your default VM, testing the 2023-12 release of eclipse">
222222
<fetchdep.eclipse version="202312" />
223-
<test.eclipse-X version="202312" />
223+
<test.eclipse-X version="202312" compiler.compliance.level="17" />
224224
</target>
225225

226226
<target name="test.eclipse-I-build" depends="test.compile, test.formatter.compile, deps.rtstubs18, compile.support" description="runs the tests on your default VM, testing the latest integration build of eclipse">

src/core/lombok/core/GuavaTypeMap.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public final class GuavaTypeMap {
3737
m.put("java.util.Map", "ImmutableMap");
3838
m.put("java.util.Collection", "ImmutableList");
3939
m.put("java.util.List", "ImmutableList");
40-
40+
m.put("java.util.SequencedSet", "ImmutableSortedSet");
41+
m.put("java.util.SequencedMap", "ImmutableSortedMap");
42+
m.put("java.util.SequencedCollection", "ImmutableList");
43+
4144
m.put("com.google.common.collect.ImmutableSet", "ImmutableSet");
4245
m.put("com.google.common.collect.ImmutableSortedSet", "ImmutableSortedSet");
4346
m.put("com.google.common.collect.ImmutableMap", "ImmutableMap");

src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
@Provides(EclipseSingularizer.class)
5151
public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingularizer {
5252
@Override public LombokImmutableList<String> getSupportedTypes() {
53-
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable");
53+
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.util.SequencedCollection", "java.lang.Iterable");
5454
}
5555

5656
private static final char[] EMPTY_LIST = {'e', 'm', 'p', 't', 'y', 'L', 'i', 's', 't'};

src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
@Provides(EclipseSingularizer.class)
6767
public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer {
6868
@Override public LombokImmutableList<String> getSupportedTypes() {
69-
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap");
69+
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap", "java.util.SequencedMap");
7070
}
7171

7272
private static final char[] EMPTY_SORTED_MAP = {'e', 'm', 'p', 't', 'y', 'S', 'o', 'r', 't', 'e', 'd', 'M', 'a', 'p'};
@@ -78,7 +78,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
7878
}
7979

8080
@Override protected char[] getEmptyMakerSelector(String targetFqn) {
81-
if (targetFqn.endsWith("SortedMap")) return EMPTY_SORTED_MAP;
81+
if (targetFqn.endsWith("SortedMap") || targetFqn.endsWith("SequencedMap")) return EMPTY_SORTED_MAP;
8282
if (targetFqn.endsWith("NavigableMap")) return EMPTY_NAVIGABLE_MAP;
8383
return EMPTY_MAP;
8484
}
@@ -348,6 +348,8 @@ private void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate
348348

349349
if (data.getTargetFqn().equals("java.util.Map")) {
350350
statements.addAll(createJavaUtilSetMapInitialCapacitySwitchStatements(data, builderType, true, "emptyMap", "singletonMap", "LinkedHashMap", builderVariable));
351+
} else if (data.getTargetFqn().equals("java.util.SequencedMap")) {
352+
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, true, true, false, true, "LinkedHashMap", builderVariable));
351353
} else {
352354
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, true, true, false, true, "TreeMap", builderVariable));
353355
}

src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@Provides(EclipseSingularizer.class)
3535
public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilListSetSingularizer {
3636
@Override public LombokImmutableList<String> getSupportedTypes() {
37-
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet");
37+
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet", "java.util.SequencedSet");
3838
}
3939

4040
private static final char[] EMPTY_SORTED_SET = {'e', 'm', 'p', 't', 'y', 'S', 'o', 'r', 't', 'e', 'd', 'S', 'e', 't'};
@@ -46,7 +46,7 @@ public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilListSetSingul
4646
}
4747

4848
@Override protected char[] getEmptyMakerSelector(String targetFqn) {
49-
if (targetFqn.endsWith("SortedSet")) return EMPTY_SORTED_SET;
49+
if (targetFqn.endsWith("SortedSet") || targetFqn.endsWith("SequencedSet")) return EMPTY_SORTED_SET;
5050
if (targetFqn.endsWith("NavigableSet")) return EMPTY_NAVIGABLE_SET;
5151
return EMPTY_SET;
5252
}
@@ -59,6 +59,8 @@ public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilListSetSingul
5959

6060
if (data.getTargetFqn().equals("java.util.Set")) {
6161
statements.addAll(createJavaUtilSetMapInitialCapacitySwitchStatements(data, builderType, false, "emptySet", "singleton", "LinkedHashSet", builderVariable));
62+
} else if (data.getTargetFqn().equals("java.util.SequencedSet")) {
63+
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, false, true, false, true, "LinkedHashSet", builderVariable));
6264
} else {
6365
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, false, true, false, true, "TreeSet", builderVariable));
6466
}

src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
@Provides(JavacSingularizer.class)
4242
public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingularizer {
4343
@Override public LombokImmutableList<String> getSupportedTypes() {
44-
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable");
44+
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.util.SequencedCollection", "java.lang.Iterable");
4545
}
4646

4747
@Override protected String getEmptyMaker(String target) {

src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
@Provides(JavacSingularizer.class)
5151
public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
5252
@Override public LombokImmutableList<String> getSupportedTypes() {
53-
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap");
53+
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap", "java.util.SequencedMap");
5454
}
5555

5656
@Override protected String getEmptyMaker(String target) {
57+
if (target.endsWith("SortedMap") || target.endsWith("SequencedMap")) return "java.util.Collections.emptySortedMap";
5758
if (target.endsWith("NavigableMap")) return "java.util.Collections.emptyNavigableMap";
58-
if (target.endsWith("SortedMap")) return "java.util.Collections.emptySortedMap";
5959
return "java.util.Collections.emptyMap";
6060
}
6161

@@ -171,6 +171,8 @@ protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, Si
171171

172172
if (data.getTargetFqn().equals("java.util.Map")) {
173173
statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, true, "emptyMap", "singletonMap", "LinkedHashMap", source, builderVariable));
174+
} else if (data.getTargetFqn().equals("java.util.SequencedMap")) {
175+
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, true, true, false, true, "LinkedHashMap", source, builderVariable));
174176
} else {
175177
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, true, true, false, true, "TreeMap", source, builderVariable));
176178
}

src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
@Provides(JavacSingularizer.class)
3636
public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingularizer {
3737
@Override public LombokImmutableList<String> getSupportedTypes() {
38-
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet");
38+
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet", "java.util.SequencedSet");
3939
}
4040

4141
@Override protected String getEmptyMaker(String target) {
42-
if (target.endsWith("SortedSet")) return "java.util.Collections.emptySortedSet";
42+
if (target.endsWith("SortedSet") || target.endsWith("SequencedSet")) return "java.util.Collections.emptySortedSet";
4343
if (target.endsWith("NavigableSet")) return "java.util.Collections.emptyNavigableSet";
4444
return "java.util.Collections.emptySet";
4545
}
@@ -49,6 +49,8 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingulariz
4949

5050
if (data.getTargetFqn().equals("java.util.Set")) {
5151
statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, false, "emptySet", "singleton", "LinkedHashSet", source, builderVariable));
52+
} else if (data.getTargetFqn().equals("java.util.SequencedSet")) {
53+
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, false, true, false, true, "LinkedHashSet", source, builderVariable));
5254
} else {
5355
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, false, true, false, true, "TreeSet", source, builderVariable));
5456
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// version 21:
2+
import java.util.SequencedCollection;
3+
import java.util.SequencedMap;
4+
import java.util.SequencedSet;
5+
class BuilderSingularSequencedCollections<T, K, V> {
6+
private SequencedCollection<T> sequencedCollection;
7+
private SequencedMap<K, V> sequencedMap;
8+
private SequencedSet<T> sequencedSet;
9+
@java.lang.SuppressWarnings("all")
10+
BuilderSingularSequencedCollections(final SequencedCollection<T> sequencedCollection, final SequencedMap<K, V> sequencedMap, final SequencedSet<T> sequencedSet) {
11+
this.sequencedCollection = sequencedCollection;
12+
this.sequencedMap = sequencedMap;
13+
this.sequencedSet = sequencedSet;
14+
}
15+
@java.lang.SuppressWarnings("all")
16+
public static class BuilderSingularSequencedCollectionsBuilder<T, K, V> {
17+
@java.lang.SuppressWarnings("all")
18+
private java.util.ArrayList<T> sequencedCollection;
19+
@java.lang.SuppressWarnings("all")
20+
private java.util.ArrayList<K> sequencedMap$key;
21+
@java.lang.SuppressWarnings("all")
22+
private java.util.ArrayList<V> sequencedMap$value;
23+
@java.lang.SuppressWarnings("all")
24+
private java.util.ArrayList<T> sequencedSet;
25+
@java.lang.SuppressWarnings("all")
26+
BuilderSingularSequencedCollectionsBuilder() {
27+
}
28+
@java.lang.SuppressWarnings("all")
29+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> col(final T col) {
30+
if (this.sequencedCollection == null) this.sequencedCollection = new java.util.ArrayList<T>();
31+
this.sequencedCollection.add(col);
32+
return this;
33+
}
34+
@java.lang.SuppressWarnings("all")
35+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> sequencedCollection(final java.util.Collection<? extends T> sequencedCollection) {
36+
if (sequencedCollection == null) {
37+
throw new java.lang.NullPointerException("sequencedCollection cannot be null");
38+
}
39+
if (this.sequencedCollection == null) this.sequencedCollection = new java.util.ArrayList<T>();
40+
this.sequencedCollection.addAll(sequencedCollection);
41+
return this;
42+
}
43+
@java.lang.SuppressWarnings("all")
44+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> clearSequencedCollection() {
45+
if (this.sequencedCollection != null) this.sequencedCollection.clear();
46+
return this;
47+
}
48+
@java.lang.SuppressWarnings("all")
49+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> map(final K mapKey, final V mapValue) {
50+
if (this.sequencedMap$key == null) {
51+
this.sequencedMap$key = new java.util.ArrayList<K>();
52+
this.sequencedMap$value = new java.util.ArrayList<V>();
53+
}
54+
this.sequencedMap$key.add(mapKey);
55+
this.sequencedMap$value.add(mapValue);
56+
return this;
57+
}
58+
@java.lang.SuppressWarnings("all")
59+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> sequencedMap(final java.util.Map<? extends K, ? extends V> sequencedMap) {
60+
if (sequencedMap == null) {
61+
throw new java.lang.NullPointerException("sequencedMap cannot be null");
62+
}
63+
if (this.sequencedMap$key == null) {
64+
this.sequencedMap$key = new java.util.ArrayList<K>();
65+
this.sequencedMap$value = new java.util.ArrayList<V>();
66+
}
67+
for (final java.util.Map.Entry<? extends K, ? extends V> $lombokEntry : sequencedMap.entrySet()) {
68+
this.sequencedMap$key.add($lombokEntry.getKey());
69+
this.sequencedMap$value.add($lombokEntry.getValue());
70+
}
71+
return this;
72+
}
73+
@java.lang.SuppressWarnings("all")
74+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> clearSequencedMap() {
75+
if (this.sequencedMap$key != null) {
76+
this.sequencedMap$key.clear();
77+
this.sequencedMap$value.clear();
78+
}
79+
return this;
80+
}
81+
@java.lang.SuppressWarnings("all")
82+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> set(final T set) {
83+
if (this.sequencedSet == null) this.sequencedSet = new java.util.ArrayList<T>();
84+
this.sequencedSet.add(set);
85+
return this;
86+
}
87+
@java.lang.SuppressWarnings("all")
88+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> sequencedSet(final java.util.Collection<? extends T> sequencedSet) {
89+
if (sequencedSet == null) {
90+
throw new java.lang.NullPointerException("sequencedSet cannot be null");
91+
}
92+
if (this.sequencedSet == null) this.sequencedSet = new java.util.ArrayList<T>();
93+
this.sequencedSet.addAll(sequencedSet);
94+
return this;
95+
}
96+
@java.lang.SuppressWarnings("all")
97+
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> clearSequencedSet() {
98+
if (this.sequencedSet != null) this.sequencedSet.clear();
99+
return this;
100+
}
101+
@java.lang.SuppressWarnings("all")
102+
public BuilderSingularSequencedCollections<T, K, V> build() {
103+
java.util.SequencedCollection<T> sequencedCollection;
104+
switch (this.sequencedCollection == null ? 0 : this.sequencedCollection.size()) {
105+
case 0:
106+
sequencedCollection = java.util.Collections.emptyList();
107+
break;
108+
case 1:
109+
sequencedCollection = java.util.Collections.singletonList(this.sequencedCollection.get(0));
110+
break;
111+
default:
112+
sequencedCollection = java.util.Collections.unmodifiableList(new java.util.ArrayList<T>(this.sequencedCollection));
113+
}
114+
java.util.SequencedMap<K, V> sequencedMap = new java.util.LinkedHashMap<K, V>();
115+
if (this.sequencedMap$key != null) for (int $i = 0; $i < (this.sequencedMap$key == null ? 0 : this.sequencedMap$key.size()); $i++) sequencedMap.put(this.sequencedMap$key.get($i), (V) this.sequencedMap$value.get($i));
116+
sequencedMap = java.util.Collections.unmodifiableSequencedMap(sequencedMap);
117+
java.util.SequencedSet<T> sequencedSet = new java.util.LinkedHashSet<T>();
118+
if (this.sequencedSet != null) sequencedSet.addAll(this.sequencedSet);
119+
sequencedSet = java.util.Collections.unmodifiableSequencedSet(sequencedSet);
120+
return new BuilderSingularSequencedCollections<T, K, V>(sequencedCollection, sequencedMap, sequencedSet);
121+
}
122+
@java.lang.Override
123+
@java.lang.SuppressWarnings("all")
124+
public java.lang.String toString() {
125+
return "BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder(sequencedCollection=" + this.sequencedCollection + ", sequencedMap$key=" + this.sequencedMap$key + ", sequencedMap$value=" + this.sequencedMap$value + ", sequencedSet=" + this.sequencedSet + ")";
126+
}
127+
}
128+
@java.lang.SuppressWarnings("all")
129+
public static <T, K, V> BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> builder() {
130+
return new BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V>();
131+
}
132+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// version 21:
2+
3+
import java.util.SequencedCollection;
4+
import java.util.SequencedMap;
5+
import java.util.SequencedSet;
6+
7+
import lombok.Builder;
8+
import lombok.Singular;
9+
10+
@Builder
11+
class BuilderSingularSequencedCollections<T, K, V> {
12+
@Singular("col") private SequencedCollection<T> sequencedCollection;
13+
@Singular("map") private SequencedMap<K, V> sequencedMap;
14+
@Singular("set") private SequencedSet<T> sequencedSet;
15+
}

0 commit comments

Comments
 (0)