Skip to content

Commit

Permalink
Adding support for SequencedCollection, SequencedSet and SequencedMap…
Browse files Browse the repository at this point in the history
… from JDK 21
  • Loading branch information
mp.samoylych committed Jan 15, 2024
1 parent 1342aa8 commit 26580f5
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 15 deletions.
2 changes: 1 addition & 1 deletion buildScripts/tests.ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn

<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">
<fetchdep.eclipse version="202312" />
<test.eclipse-X version="202312" />
<test.eclipse-X version="202312" compiler.compliance.level="17" />
</target>

<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">
Expand Down
5 changes: 4 additions & 1 deletion src/core/lombok/core/GuavaTypeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public final class GuavaTypeMap {
m.put("java.util.Map", "ImmutableMap");
m.put("java.util.Collection", "ImmutableList");
m.put("java.util.List", "ImmutableList");

m.put("java.util.SequencedSet", "ImmutableSortedSet");
m.put("java.util.SequencedMap", "ImmutableSortedMap");
m.put("java.util.SequencedCollection", "ImmutableList");

m.put("com.google.common.collect.ImmutableSet", "ImmutableSet");
m.put("com.google.common.collect.ImmutableSortedSet", "ImmutableSortedSet");
m.put("com.google.common.collect.ImmutableMap", "ImmutableMap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
@Provides(EclipseSingularizer.class)
public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingularizer {
@Override public LombokImmutableList<String> getSupportedTypes() {
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable");
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.util.SequencedCollection", "java.lang.Iterable");
}

private static final char[] EMPTY_LIST = {'e', 'm', 'p', 't', 'y', 'L', 'i', 's', 't'};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
@Provides(EclipseSingularizer.class)
public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer {
@Override public LombokImmutableList<String> getSupportedTypes() {
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap");
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap", "java.util.SequencedMap");
}

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

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

if (data.getTargetFqn().equals("java.util.Map")) {
statements.addAll(createJavaUtilSetMapInitialCapacitySwitchStatements(data, builderType, true, "emptyMap", "singletonMap", "LinkedHashMap", builderVariable));
} else if (data.getTargetFqn().equals("java.util.SequencedMap")) {
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, true, true, false, true, "LinkedHashMap", builderVariable));
} else {
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, true, true, false, true, "TreeMap", builderVariable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@Provides(EclipseSingularizer.class)
public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilListSetSingularizer {
@Override public LombokImmutableList<String> getSupportedTypes() {
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet");
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet", "java.util.SequencedSet");
}

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

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

if (data.getTargetFqn().equals("java.util.Set")) {
statements.addAll(createJavaUtilSetMapInitialCapacitySwitchStatements(data, builderType, false, "emptySet", "singleton", "LinkedHashSet", builderVariable));
} else if (data.getTargetFqn().equals("java.util.SequencedSet")) {
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, false, true, false, true, "LinkedHashSet", builderVariable));
} else {
statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, false, true, false, true, "TreeSet", builderVariable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@Provides(JavacSingularizer.class)
public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingularizer {
@Override public LombokImmutableList<String> getSupportedTypes() {
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable");
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.util.SequencedCollection", "java.lang.Iterable");
}

@Override protected String getEmptyMaker(String target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
@Provides(JavacSingularizer.class)
public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
@Override public LombokImmutableList<String> getSupportedTypes() {
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap");
return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap", "java.util.SequencedMap");
}

@Override protected String getEmptyMaker(String target) {
if (target.endsWith("SortedMap") || target.endsWith("SequencedMap")) return "java.util.Collections.emptySortedMap";
if (target.endsWith("NavigableMap")) return "java.util.Collections.emptyNavigableMap";
if (target.endsWith("SortedMap")) return "java.util.Collections.emptySortedMap";
return "java.util.Collections.emptyMap";
}

Expand Down Expand Up @@ -171,6 +171,8 @@ protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, Si

if (data.getTargetFqn().equals("java.util.Map")) {
statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, true, "emptyMap", "singletonMap", "LinkedHashMap", source, builderVariable));
} else if (data.getTargetFqn().equals("java.util.SequencedMap")) {
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, true, true, false, true, "LinkedHashMap", source, builderVariable));
} else {
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, true, true, false, true, "TreeMap", source, builderVariable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
@Provides(JavacSingularizer.class)
public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingularizer {
@Override public LombokImmutableList<String> getSupportedTypes() {
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet");
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet", "java.util.SequencedSet");
}

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

if (data.getTargetFqn().equals("java.util.Set")) {
statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, false, "emptySet", "singleton", "LinkedHashSet", source, builderVariable));
} else if (data.getTargetFqn().equals("java.util.SequencedSet")) {
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, false, true, false, true, "LinkedHashSet", source, builderVariable));
} else {
statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, false, true, false, true, "TreeSet", source, builderVariable));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// version 21:
import java.util.SequencedCollection;
import java.util.SequencedMap;
import java.util.SequencedSet;
class BuilderSingularSequencedCollections<T, K, V> {
private SequencedCollection<T> sequencedCollection;
private SequencedMap<K, V> sequencedMap;
private SequencedSet<T> sequencedSet;
@java.lang.SuppressWarnings("all")
BuilderSingularSequencedCollections(final SequencedCollection<T> sequencedCollection, final SequencedMap<K, V> sequencedMap, final SequencedSet<T> sequencedSet) {
this.sequencedCollection = sequencedCollection;
this.sequencedMap = sequencedMap;
this.sequencedSet = sequencedSet;
}
@java.lang.SuppressWarnings("all")
public static class BuilderSingularSequencedCollectionsBuilder<T, K, V> {
@java.lang.SuppressWarnings("all")
private java.util.ArrayList<T> sequencedCollection;
@java.lang.SuppressWarnings("all")
private java.util.ArrayList<K> sequencedMap$key;
@java.lang.SuppressWarnings("all")
private java.util.ArrayList<V> sequencedMap$value;
@java.lang.SuppressWarnings("all")
private java.util.ArrayList<T> sequencedSet;
@java.lang.SuppressWarnings("all")
BuilderSingularSequencedCollectionsBuilder() {
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> col(final T col) {
if (this.sequencedCollection == null) this.sequencedCollection = new java.util.ArrayList<T>();
this.sequencedCollection.add(col);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> sequencedCollection(final java.util.Collection<? extends T> sequencedCollection) {
if (sequencedCollection == null) {
throw new java.lang.NullPointerException("sequencedCollection cannot be null");
}
if (this.sequencedCollection == null) this.sequencedCollection = new java.util.ArrayList<T>();
this.sequencedCollection.addAll(sequencedCollection);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> clearSequencedCollection() {
if (this.sequencedCollection != null) this.sequencedCollection.clear();
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> map(final K mapKey, final V mapValue) {
if (this.sequencedMap$key == null) {
this.sequencedMap$key = new java.util.ArrayList<K>();
this.sequencedMap$value = new java.util.ArrayList<V>();
}
this.sequencedMap$key.add(mapKey);
this.sequencedMap$value.add(mapValue);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> sequencedMap(final java.util.Map<? extends K, ? extends V> sequencedMap) {
if (sequencedMap == null) {
throw new java.lang.NullPointerException("sequencedMap cannot be null");
}
if (this.sequencedMap$key == null) {
this.sequencedMap$key = new java.util.ArrayList<K>();
this.sequencedMap$value = new java.util.ArrayList<V>();
}
for (final java.util.Map.Entry<? extends K, ? extends V> $lombokEntry : sequencedMap.entrySet()) {
this.sequencedMap$key.add($lombokEntry.getKey());
this.sequencedMap$value.add($lombokEntry.getValue());
}
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> clearSequencedMap() {
if (this.sequencedMap$key != null) {
this.sequencedMap$key.clear();
this.sequencedMap$value.clear();
}
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> set(final T set) {
if (this.sequencedSet == null) this.sequencedSet = new java.util.ArrayList<T>();
this.sequencedSet.add(set);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> sequencedSet(final java.util.Collection<? extends T> sequencedSet) {
if (sequencedSet == null) {
throw new java.lang.NullPointerException("sequencedSet cannot be null");
}
if (this.sequencedSet == null) this.sequencedSet = new java.util.ArrayList<T>();
this.sequencedSet.addAll(sequencedSet);
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> clearSequencedSet() {
if (this.sequencedSet != null) this.sequencedSet.clear();
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderSingularSequencedCollections<T, K, V> build() {
java.util.SequencedCollection<T> sequencedCollection;
switch (this.sequencedCollection == null ? 0 : this.sequencedCollection.size()) {
case 0:
sequencedCollection = java.util.Collections.emptyList();
break;
case 1:
sequencedCollection = java.util.Collections.singletonList(this.sequencedCollection.get(0));
break;
default:
sequencedCollection = java.util.Collections.unmodifiableList(new java.util.ArrayList<T>(this.sequencedCollection));
}
java.util.SequencedMap<K, V> sequencedMap = new java.util.LinkedHashMap<K, V>();
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));
sequencedMap = java.util.Collections.unmodifiableSequencedMap(sequencedMap);
java.util.SequencedSet<T> sequencedSet = new java.util.LinkedHashSet<T>();
if (this.sequencedSet != null) sequencedSet.addAll(this.sequencedSet);
sequencedSet = java.util.Collections.unmodifiableSequencedSet(sequencedSet);
return new BuilderSingularSequencedCollections<T, K, V>(sequencedCollection, sequencedMap, sequencedSet);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder(sequencedCollection=" + this.sequencedCollection + ", sequencedMap$key=" + this.sequencedMap$key + ", sequencedMap$value=" + this.sequencedMap$value + ", sequencedSet=" + this.sequencedSet + ")";
}
}
@java.lang.SuppressWarnings("all")
public static <T, K, V> BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V> builder() {
return new BuilderSingularSequencedCollections.BuilderSingularSequencedCollectionsBuilder<T, K, V>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// version 21:

import java.util.SequencedCollection;
import java.util.SequencedMap;
import java.util.SequencedSet;

import lombok.Builder;
import lombok.Singular;

@Builder
class BuilderSingularSequencedCollections<T, K, V> {
@Singular("col") private SequencedCollection<T> sequencedCollection;
@Singular("map") private SequencedMap<K, V> sequencedMap;
@Singular("set") private SequencedSet<T> sequencedSet;
}
6 changes: 3 additions & 3 deletions website/templates/features/Builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ <h3 id="singular"><a name="singular">@Singular</a></h3>
<a href="https://docs.oracle.com/javase/8/docs/api/java/util/package-summary.html"><code>java.util</code></a>:
<ul>
<li>
<code>Iterable</code>, <code>Collection</code>, and <code>List</code> (backed by a compacted unmodifiable <code>ArrayList</code> in the general case).
<code>Iterable</code>, <code>Collection</code>, <code>SequencedCollection</code>, and <code>List</code> (backed by a compacted unmodifiable <code>ArrayList</code> in the general case).
</li><li>
<code>Set</code>, <code>SortedSet</code>, and <code>NavigableSet</code> (backed by a smartly sized unmodifiable <code>HashSet</code> or <code>TreeSet</code> in the general case).
<code>Set</code>, <code>SortedSet</code>, <code>NavigableSet</code>, and <code>SequencedSet</code> (backed by a smartly sized unmodifiable <code>LinkedHashSet</code> or <code>TreeSet</code> in the general case).
</li><li>
<code>Map</code>, <code>SortedMap</code>, and <code>NavigableMap</code> (backed by a smartly sized unmodifiable <code>HashMap</code> or <code>TreeMap</code> in the general case).
<code>Map</code>, <code>SortedMap</code>, <code>NavigableMap</code>, and <code>SequencedMap</code> (backed by a smartly sized unmodifiable <code>LinkedHashMap</code> or <code>TreeMap</code> in the general case).
</li>
</ul>
</li><li>
Expand Down

0 comments on commit 26580f5

Please sign in to comment.