Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for SequencedCollection, SequencedSet and SequencedMap from JDK 21 #3584

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Mart Hagenaars <marthagenaars@gmail.com>
Martin O'Connor <38929043+martinoconnor@users.noreply.github.com>
Martin Panzer <postremus1996@googlemail.com>
Mateusz Matela <mateusz.matela@gmail.com>
Maxim Samoylych <msamoylych@gmail.com>
Michael Dardis <git@md-5.net>
Michael Ernst <mernst@alum.mit.edu>
Michiel Verheul <cheelio@gmail.com>
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>();
}
}
Loading