Skip to content

Commit 36e30b3

Browse files
yorickhenningGoogle Java Core Libraries
authored andcommitted
Added @InlineMe annotations to Lists.newArrayList() and Lists.newLinkedList().
RELNOTES=Added @InlineMe annotations to Lists.newArrayList() and Lists.newLinkedList(). PiperOrigin-RevId: 928611528
1 parent 827fab5 commit 36e30b3

10 files changed

Lines changed: 338 additions & 68 deletions

File tree

android/guava/src/com/google/common/collect/Lists.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ private Lists() {}
7777
*
7878
* <p><b>Note:</b> if mutability is not required, use {@link ImmutableList#of()} instead.
7979
*
80-
* <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated. Instead,
80+
* @deprecated This method is unnecessary. Instead,
8181
* use the {@code ArrayList} {@linkplain ArrayList#ArrayList() constructor} directly, taking
8282
* advantage of <a
8383
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
8484
* syntax</a>.
8585
*/
8686
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
87+
@Deprecated
88+
@InlineMe(replacement = "new ArrayList<>()", imports = "java.util.ArrayList")
8789
public static <E extends @Nullable Object> ArrayList<E> newArrayList() {
8890
return new ArrayList<>();
8991
}
@@ -213,7 +215,7 @@ static int computeArrayListCapacity(int arraySize) {
213215
* outperform {@code LinkedList} except in certain rare and specific situations. Unless you have
214216
* spent a lot of time benchmarking your specific needs, use one of those instead.
215217
*
216-
* <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated. Instead,
218+
* @deprecated This method is unnecessary. Instead,
217219
* use the {@code LinkedList} {@linkplain LinkedList#LinkedList() constructor} directly, taking
218220
* advantage of <a
219221
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
@@ -223,6 +225,8 @@ static int computeArrayListCapacity(int arraySize) {
223225
"NonApiType", // acts as a direct substitute for a constructor call
224226
"JdkObsolete", // We recommend against this method but need to keep it for compatibility.
225227
})
228+
@Deprecated
229+
@InlineMe(replacement = "new LinkedList<>()", imports = "java.util.LinkedList")
226230
public static <E extends @Nullable Object> LinkedList<E> newLinkedList() {
227231
return new LinkedList<>();
228232
}
@@ -260,12 +264,17 @@ static int computeArrayListCapacity(int arraySize) {
260264
*
261265
* @return a new, empty {@code CopyOnWriteArrayList}
262266
* @since 12.0
267+
* @deprecated This method is unnecessary. Instead, use the {@code CopyOnWriteArrayList} {@linkplain
268+
* CopyOnWriteArrayList#CopyOnWriteArrayList() constructor} directly, taking advantage of <a
269+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
270+
* syntax</a>.
263271
*/
264272
@J2ktIncompatible
265273
@GwtIncompatible // CopyOnWriteArrayList
266274
@InlineMe(
267275
replacement = "new CopyOnWriteArrayList<>()",
268276
imports = {"java.util.concurrent.CopyOnWriteArrayList"})
277+
@Deprecated
269278
public static <E extends @Nullable Object> CopyOnWriteArrayList<E> newCopyOnWriteArrayList() {
270279
return new CopyOnWriteArrayList<>();
271280
}

android/guava/src/com/google/common/collect/Maps.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.google.common.collect.MapDifference.ValueDifference;
5454
import com.google.common.primitives.Ints;
5555
import com.google.errorprone.annotations.CanIgnoreReturnValue;
56+
import com.google.errorprone.annotations.InlineMe;
5657
import com.google.errorprone.annotations.concurrent.LazyInit;
5758
import com.google.j2objc.annotations.RetainedWith;
5859
import com.google.j2objc.annotations.Weak;
@@ -216,14 +217,15 @@ public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(
216217
*
217218
* <p><b>Note:</b> if {@code K} is an {@code enum} type, use {@link #newEnumMap} instead.
218219
*
219-
* <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated. Instead,
220-
* use the {@code HashMap} constructor directly, taking advantage of <a
221-
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
222-
* syntax</a>.
223-
*
224220
* @return a new, empty {@code HashMap}
221+
* @deprecated This method is unnecessary. Instead, use the {@code HashMap} {@linkplain
222+
* HashMap#HashMap() constructor} directly, taking advantage of <a
223+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
224+
* syntax</a>.
225225
*/
226226
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
227+
@Deprecated
228+
@InlineMe(replacement = "new HashMap<>()", imports = "java.util.HashMap")
227229
public static <K extends @Nullable Object, V extends @Nullable Object>
228230
HashMap<K, V> newHashMap() {
229231
return new HashMap<>();
@@ -299,14 +301,15 @@ static int capacity(int expectedSize) {
299301
*
300302
* <p><b>Note:</b> if mutability is not required, use {@link ImmutableMap#of()} instead.
301303
*
302-
* <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated. Instead,
303-
* use the {@code LinkedHashMap} constructor directly, taking advantage of <a
304-
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
305-
* syntax</a>.
306-
*
307304
* @return a new, empty {@code LinkedHashMap}
305+
* @deprecated This method is unnecessary. Instead, use the {@code LinkedHashMap} {@linkplain
306+
* LinkedHashMap#LinkedHashMap() constructor} directly, taking advantage of <a
307+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
308+
* syntax</a>.
308309
*/
309310
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
311+
@Deprecated
312+
@InlineMe(replacement = "new LinkedHashMap<>()", imports = "java.util.LinkedHashMap")
310313
public static <K extends @Nullable Object, V extends @Nullable Object>
311314
LinkedHashMap<K, V> newLinkedHashMap() {
312315
return new LinkedHashMap<>();
@@ -353,13 +356,14 @@ LinkedHashMap<K, V> newLinkedHashMapWithExpectedSize(int expectedSize) {
353356
/**
354357
* Creates a new empty {@link ConcurrentHashMap} instance.
355358
*
356-
* <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated. Instead,
357-
* use the {@code ConcurrentHashMap} constructor directly, taking advantage of <a
358-
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
359-
* syntax</a>.
360-
*
361359
* @since 3.0
360+
* @deprecated This method is unnecessary. Instead, use the {@code ConcurrentHashMap} {@linkplain
361+
* ConcurrentHashMap#ConcurrentHashMap() constructor} directly, taking advantage of <a
362+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
363+
* syntax</a>.
362364
*/
365+
@Deprecated
366+
@InlineMe(replacement = "new ConcurrentHashMap<>()", imports = "java.util.concurrent.ConcurrentHashMap")
363367
public static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
364368
return new ConcurrentHashMap<>();
365369
}
@@ -438,7 +442,13 @@ TreeMap<K, V> newTreeMap(@Nullable Comparator<C> comparator) {
438442
*
439443
* @param type the key type for this map
440444
* @return a new, empty {@code EnumMap}
445+
* @deprecated This method is unnecessary. Instead, use the {@code EnumMap} {@linkplain
446+
* EnumMap#EnumMap(Class) constructor} directly, taking advantage of <a
447+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
448+
* syntax</a>.
441449
*/
450+
@Deprecated
451+
@InlineMe(replacement = "new EnumMap<>(type)", imports = "java.util.EnumMap")
442452
public static <K extends Enum<K>, V extends @Nullable Object> EnumMap<K, V> newEnumMap(
443453
Class<K> type) {
444454
return new EnumMap<>(checkNotNull(type));
@@ -465,13 +475,14 @@ TreeMap<K, V> newTreeMap(@Nullable Comparator<C> comparator) {
465475
/**
466476
* Creates an {@code IdentityHashMap} instance.
467477
*
468-
* <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated. Instead,
469-
* use the {@code IdentityHashMap} constructor directly, taking advantage of <a
470-
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
471-
* syntax</a>.
472-
*
473478
* @return a new, empty {@code IdentityHashMap}
479+
* @deprecated This method is unnecessary. Instead, use the {@code IdentityHashMap} {@linkplain
480+
* IdentityHashMap#IdentityHashMap() constructor} directly, taking advantage of <a
481+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
482+
* syntax</a>.
474483
*/
484+
@Deprecated
485+
@InlineMe(replacement = "new IdentityHashMap<>()", imports = "java.util.IdentityHashMap")
475486
public static <K extends @Nullable Object, V extends @Nullable Object>
476487
IdentityHashMap<K, V> newIdentityHashMap() {
477488
return new IdentityHashMap<>();

android/guava/src/com/google/common/collect/Queues.java

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.annotations.J2ktIncompatible;
2323
import com.google.common.base.Preconditions;
2424
import com.google.errorprone.annotations.CanIgnoreReturnValue;
25+
import com.google.errorprone.annotations.InlineMe;
2526
import java.time.Duration;
2627
import java.util.ArrayDeque;
2728
import java.util.Collection;
@@ -54,9 +55,18 @@ private Queues() {}
5455
/**
5556
* Creates an empty {@code ArrayBlockingQueue} with the given (fixed) capacity and nonfair access
5657
* policy.
58+
*
59+
* @deprecated This method is unnecessary. Instead, use the {@code ArrayBlockingQueue} {@linkplain
60+
* ArrayBlockingQueue#ArrayBlockingQueue(int) constructor} directly, taking advantage of <a
61+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
62+
* syntax</a>.
5763
*/
5864
@J2ktIncompatible
5965
@GwtIncompatible // ArrayBlockingQueue
66+
@Deprecated
67+
@InlineMe(
68+
replacement = "new ArrayBlockingQueue<>(capacity)",
69+
imports = "java.util.concurrent.ArrayBlockingQueue")
6070
public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity) {
6171
return new ArrayBlockingQueue<>(capacity);
6272
}
@@ -67,7 +77,13 @@ public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity) {
6777
* Creates an empty {@code ArrayDeque}.
6878
*
6979
* @since 12.0
80+
* @deprecated This method is unnecessary. Instead, use the {@code ArrayDeque} {@linkplain
81+
* ArrayDeque#ArrayDeque() constructor} directly, taking advantage of <a
82+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
83+
* syntax</a>.
7084
*/
85+
@Deprecated
86+
@InlineMe(replacement = "new ArrayDeque<>()", imports = "java.util.ArrayDeque")
7187
public static <E> ArrayDeque<E> newArrayDeque() {
7288
return new ArrayDeque<>();
7389
}
@@ -89,9 +105,20 @@ public static <E> ArrayDeque<E> newArrayDeque(Iterable<? extends E> elements) {
89105

90106
// ConcurrentLinkedQueue
91107

92-
/** Creates an empty {@code ConcurrentLinkedQueue}. */
108+
/**
109+
* Creates an empty {@code ConcurrentLinkedQueue}.
110+
*
111+
* @deprecated This method is unnecessary. Instead, use the {@code ConcurrentLinkedQueue} {@linkplain
112+
* ConcurrentLinkedQueue#ConcurrentLinkedQueue() constructor} directly, taking advantage of <a
113+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
114+
* syntax</a>.
115+
*/
93116
@J2ktIncompatible
94117
@GwtIncompatible // ConcurrentLinkedQueue
118+
@Deprecated
119+
@InlineMe(
120+
replacement = "new ConcurrentLinkedQueue<>()",
121+
imports = "java.util.concurrent.ConcurrentLinkedQueue")
95122
public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue() {
96123
return new ConcurrentLinkedQueue<>();
97124
}
@@ -118,9 +145,17 @@ public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue(
118145
* Creates an empty {@code LinkedBlockingDeque} with a capacity of {@link Integer#MAX_VALUE}.
119146
*
120147
* @since 12.0
148+
* @deprecated This method is unnecessary. Instead, use the {@code LinkedBlockingDeque} {@linkplain
149+
* LinkedBlockingDeque#LinkedBlockingDeque() constructor} directly, taking advantage of <a
150+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
151+
* syntax</a>.
121152
*/
122153
@J2ktIncompatible
123154
@GwtIncompatible // LinkedBlockingDeque
155+
@Deprecated
156+
@InlineMe(
157+
replacement = "new LinkedBlockingDeque<>()",
158+
imports = "java.util.concurrent.LinkedBlockingDeque")
124159
public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque() {
125160
return new LinkedBlockingDeque<>();
126161
}
@@ -130,9 +165,17 @@ public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque() {
130165
*
131166
* @throws IllegalArgumentException if {@code capacity} is less than 1
132167
* @since 12.0
168+
* @deprecated This method is unnecessary. Instead, use the {@code LinkedBlockingDeque} {@linkplain
169+
* LinkedBlockingDeque#LinkedBlockingDeque(int) constructor} directly, taking advantage of <a
170+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
171+
* syntax</a>.
133172
*/
134173
@J2ktIncompatible
135174
@GwtIncompatible // LinkedBlockingDeque
175+
@Deprecated
176+
@InlineMe(
177+
replacement = "new LinkedBlockingDeque<>(capacity)",
178+
imports = "java.util.concurrent.LinkedBlockingDeque")
136179
public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(int capacity) {
137180
return new LinkedBlockingDeque<>(capacity);
138181
}
@@ -157,9 +200,20 @@ public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(Iterable<? exten
157200

158201
// LinkedBlockingQueue
159202

160-
/** Creates an empty {@code LinkedBlockingQueue} with a capacity of {@link Integer#MAX_VALUE}. */
203+
/**
204+
* Creates an empty {@code LinkedBlockingQueue} with a capacity of {@link Integer#MAX_VALUE}.
205+
*
206+
* @deprecated This method is unnecessary. Instead, use the {@code LinkedBlockingQueue} {@linkplain
207+
* LinkedBlockingQueue#LinkedBlockingQueue() constructor} directly, taking advantage of <a
208+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
209+
* syntax</a>.
210+
*/
161211
@J2ktIncompatible
162212
@GwtIncompatible // LinkedBlockingQueue
213+
@Deprecated
214+
@InlineMe(
215+
replacement = "new LinkedBlockingQueue<>()",
216+
imports = "java.util.concurrent.LinkedBlockingQueue")
163217
public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue() {
164218
return new LinkedBlockingQueue<>();
165219
}
@@ -168,9 +222,17 @@ public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue() {
168222
* Creates an empty {@code LinkedBlockingQueue} with the given (fixed) capacity.
169223
*
170224
* @throws IllegalArgumentException if {@code capacity} is less than 1
225+
* @deprecated This method is unnecessary. Instead, use the {@code LinkedBlockingQueue} {@linkplain
226+
* LinkedBlockingQueue#LinkedBlockingQueue(int) constructor} directly, taking advantage of <a
227+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
228+
* syntax</a>.
171229
*/
172230
@J2ktIncompatible
173231
@GwtIncompatible // LinkedBlockingQueue
232+
@Deprecated
233+
@InlineMe(
234+
replacement = "new LinkedBlockingQueue<>(capacity)",
235+
imports = "java.util.concurrent.LinkedBlockingQueue")
174236
public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue(int capacity) {
175237
return new LinkedBlockingQueue<>(capacity);
176238
}
@@ -204,10 +266,18 @@ public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue(Iterable<? exten
204266
*
205267
* @since 11.0 (but the bound of {@code E} was changed from {@code Object} to {@code Comparable}
206268
* in 15.0)
269+
* @deprecated This method is unnecessary. Instead, use the {@code PriorityBlockingQueue} {@linkplain
270+
* PriorityBlockingQueue#PriorityBlockingQueue() constructor} directly, taking advantage of <a
271+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
272+
* syntax</a>.
207273
*/
208274
@SuppressWarnings("rawtypes") // https://github.com/google/guava/issues/989
209275
@J2ktIncompatible
210276
@GwtIncompatible // PriorityBlockingQueue
277+
@Deprecated
278+
@InlineMe(
279+
replacement = "new PriorityBlockingQueue<>()",
280+
imports = "java.util.concurrent.PriorityBlockingQueue")
211281
public static <E extends Comparable> PriorityBlockingQueue<E> newPriorityBlockingQueue() {
212282
return new PriorityBlockingQueue<>();
213283
}
@@ -242,8 +312,14 @@ public static <E extends Comparable> PriorityBlockingQueue<E> newPriorityBlockin
242312
*
243313
* @since 11.0 (but the bound of {@code E} was changed from {@code Object} to {@code Comparable}
244314
* in 15.0)
315+
* @deprecated This method is unnecessary. Instead, use the {@code PriorityQueue} {@linkplain
316+
* PriorityQueue#PriorityQueue() constructor} directly, taking advantage of <a
317+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
318+
* syntax</a>.
245319
*/
246320
@SuppressWarnings("rawtypes") // https://github.com/google/guava/issues/989
321+
@Deprecated
322+
@InlineMe(replacement = "new PriorityQueue<>()", imports = "java.util.PriorityQueue")
247323
public static <E extends Comparable> PriorityQueue<E> newPriorityQueue() {
248324
return new PriorityQueue<>();
249325
}
@@ -270,9 +346,20 @@ public static <E extends Comparable> PriorityQueue<E> newPriorityQueue(
270346

271347
// SynchronousQueue
272348

273-
/** Creates an empty {@code SynchronousQueue} with nonfair access policy. */
349+
/**
350+
* Creates an empty {@code SynchronousQueue} with nonfair access policy.
351+
*
352+
* @deprecated This method is unnecessary. Instead, use the {@code SynchronousQueue} {@linkplain
353+
* SynchronousQueue#SynchronousQueue() constructor} directly, taking advantage of <a
354+
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
355+
* syntax</a>.
356+
*/
274357
@J2ktIncompatible
275358
@GwtIncompatible // SynchronousQueue
359+
@Deprecated
360+
@InlineMe(
361+
replacement = "new SynchronousQueue<>()",
362+
imports = "java.util.concurrent.SynchronousQueue")
276363
public static <E> SynchronousQueue<E> newSynchronousQueue() {
277364
return new SynchronousQueue<>();
278365
}

0 commit comments

Comments
 (0)