Skip to content

Commit 2e7cee9

Browse files
authored
Improve nullability in generics + update to RxJava 3.1.0 (#453)
* Update RxJava and improve generics nullability * Opportunistic suppress a deprecation * Update RxJava to 3.1.0
1 parent c8f3759 commit 2e7cee9

File tree

32 files changed

+105
-75
lines changed

32 files changed

+105
-75
lines changed

android/autodispose-android/src/main/java/autodispose2/android/KotlinExtensions.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ inline fun View.scope(): ScopeProvider = ViewScopeProvider.from(this)
4444
* Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable]
4545
*/
4646
@CheckReturnValue
47-
inline fun <T> Flowable<T>.autoDispose(
47+
inline fun <T : Any> Flowable<T>.autoDispose(
4848
view: View
4949
): FlowableSubscribeProxy<T> =
5050
this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view)))
@@ -53,7 +53,7 @@ inline fun <T> Flowable<T>.autoDispose(
5353
* Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable]
5454
*/
5555
@CheckReturnValue
56-
inline fun <T> Observable<T>.autoDispose(
56+
inline fun <T : Any> Observable<T>.autoDispose(
5757
view: View
5858
): ObservableSubscribeProxy<T> =
5959
this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view)))
@@ -62,7 +62,7 @@ inline fun <T> Observable<T>.autoDispose(
6262
* Extension that proxies to [Single.as] + [AutoDispose.autoDisposable]
6363
*/
6464
@CheckReturnValue
65-
inline fun <T> Single<T>.autoDispose(
65+
inline fun <T : Any> Single<T>.autoDispose(
6666
view: View
6767
): SingleSubscribeProxy<T> =
6868
this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view)))
@@ -71,7 +71,7 @@ inline fun <T> Single<T>.autoDispose(
7171
* Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable]
7272
*/
7373
@CheckReturnValue
74-
inline fun <T> Maybe<T>.autoDispose(
74+
inline fun <T : Any> Maybe<T>.autoDispose(
7575
view: View
7676
): MaybeSubscribeProxy<T> =
7777
this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view)))
@@ -89,7 +89,7 @@ inline fun Completable.autoDispose(
8989
* Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable]
9090
*/
9191
@CheckReturnValue
92-
inline fun <T> ParallelFlowable<T>.autoDispose(
92+
inline fun <T : Any> ParallelFlowable<T>.autoDispose(
9393
view: View
9494
): ParallelFlowableSubscribeProxy<T> =
9595
this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view)))

android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/KotlinExtensions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import io.reactivex.rxjava3.annotations.CheckReturnValue
2424
/**
2525
* Extension that returns a [TestLifecycleOwner] for this [LifecycleRegistry].
2626
*/
27+
@Suppress("DEPRECATION")
2728
@SuppressLint("RestrictedApi")
2829
@CheckReturnValue
2930
@Deprecated("Switch to androidx.lifecycle.testing.TestLifecycleOwner")

android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/KotlinExtensions.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ inline fun Lifecycle.scope(
111111
* @param untilEvent Optional lifecycle event when subscription will be disposed.
112112
*/
113113
@CheckReturnValue
114-
inline fun <T> Flowable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): FlowableSubscribeProxy<T> {
114+
inline fun <T : Any> Flowable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): FlowableSubscribeProxy<T> {
115115
return if (untilEvent == null) {
116116
this.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner)))
117117
} else {
@@ -134,7 +134,7 @@ inline fun <T> Flowable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEven
134134
* @param untilEvent Optional lifecycle event when subscription will be disposed.
135135
*/
136136
@CheckReturnValue
137-
inline fun <T> Observable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): ObservableSubscribeProxy<T> {
137+
inline fun <T : Any> Observable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): ObservableSubscribeProxy<T> {
138138
return if (untilEvent == null) {
139139
this.to(
140140
AutoDispose.autoDisposable(
@@ -161,7 +161,7 @@ inline fun <T> Observable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEv
161161
* @param untilEvent Optional lifecycle event when subscription will be disposed.
162162
*/
163163
@CheckReturnValue
164-
inline fun <T> Single<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): SingleSubscribeProxy<T> {
164+
inline fun <T : Any> Single<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): SingleSubscribeProxy<T> {
165165
return if (untilEvent == null) {
166166
this.to(
167167
AutoDispose.autoDisposable(
@@ -188,7 +188,7 @@ inline fun <T> Single<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent:
188188
* @param untilEvent Optional lifecycle event when subscription will be disposed.
189189
*/
190190
@CheckReturnValue
191-
inline fun <T> Maybe<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): MaybeSubscribeProxy<T> {
191+
inline fun <T : Any> Maybe<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): MaybeSubscribeProxy<T> {
192192
return if (untilEvent == null) {
193193
this.to(
194194
AutoDispose.autoDisposable(
@@ -242,7 +242,7 @@ inline fun Completable.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: E
242242
* @param untilEvent Optional lifecycle event when subscription will be disposed.
243243
*/
244244
@CheckReturnValue
245-
inline fun <T> ParallelFlowable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): ParallelFlowableSubscribeProxy<T> {
245+
inline fun <T : Any> ParallelFlowable<T>.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): ParallelFlowableSubscribeProxy<T> {
246246
return if (untilEvent == null) {
247247
this.to(
248248
AutoDispose.autoDisposable(

autodispose-interop/coroutines/src/main/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInterop.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ import kotlinx.coroutines.cancel
3838
import kotlin.coroutines.CoroutineContext
3939

4040
/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
41-
public inline fun <T> Flowable<T>.autoDispose(scope: CoroutineScope): FlowableSubscribeProxy<T> {
41+
public inline fun <T : Any> Flowable<T>.autoDispose(scope: CoroutineScope): FlowableSubscribeProxy<T> {
4242
return autoDispose(scope.asScopeProvider())
4343
}
4444

4545
/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
46-
public inline fun <T> Observable<T>.autoDispose(scope: CoroutineScope): ObservableSubscribeProxy<T> {
46+
public inline fun <T : Any> Observable<T>.autoDispose(scope: CoroutineScope): ObservableSubscribeProxy<T> {
4747
return autoDispose(scope.asScopeProvider())
4848
}
4949

5050
/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
51-
public inline fun <T> Single<T>.autoDispose(scope: CoroutineScope): SingleSubscribeProxy<T> {
51+
public inline fun <T : Any> Single<T>.autoDispose(scope: CoroutineScope): SingleSubscribeProxy<T> {
5252
return autoDispose(scope.asScopeProvider())
5353
}
5454

5555
/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
56-
public inline fun <T> Maybe<T>.autoDispose(scope: CoroutineScope): MaybeSubscribeProxy<T> {
56+
public inline fun <T : Any> Maybe<T>.autoDispose(scope: CoroutineScope): MaybeSubscribeProxy<T> {
5757
return autoDispose(scope.asScopeProvider())
5858
}
5959

autodispose-lifecycle/src/main/java/autodispose2/lifecycle/CorrespondingEventsFunction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package autodispose2.lifecycle;
1717

1818
import autodispose2.OutsideScopeException;
19+
import io.reactivex.rxjava3.annotations.NonNull;
1920
import io.reactivex.rxjava3.functions.Function;
2021

2122
/**
@@ -24,7 +25,7 @@
2425
*
2526
* @param <E> the event type.
2627
*/
27-
public interface CorrespondingEventsFunction<E> extends Function<E, E> {
28+
public interface CorrespondingEventsFunction<@NonNull E> extends Function<E, E> {
2829

2930
/**
3031
* Given an event {@code event}, returns the next corresponding event that this lifecycle should

autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopeProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import autodispose2.ScopeProvider;
1919
import autodispose2.internal.DoNotMock;
2020
import io.reactivex.rxjava3.annotations.CheckReturnValue;
21+
import io.reactivex.rxjava3.annotations.NonNull;
2122
import io.reactivex.rxjava3.annotations.Nullable;
2223
import io.reactivex.rxjava3.core.Completable;
2324
import io.reactivex.rxjava3.core.CompletableSource;
@@ -34,7 +35,7 @@
3435
* @see LifecycleScopes
3536
*/
3637
@DoNotMock(value = "Use TestLifecycleScopeProvider instead")
37-
public interface LifecycleScopeProvider<E> extends ScopeProvider {
38+
public interface LifecycleScopeProvider<@NonNull E> extends ScopeProvider {
3839

3940
/**
4041
* Returns a sequence of lifecycle events. Note that completion of this lifecycle will also

autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopes.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import autodispose2.AutoDisposePlugins;
1919
import autodispose2.OutsideScopeException;
20+
import io.reactivex.rxjava3.annotations.NonNull;
2021
import io.reactivex.rxjava3.annotations.Nullable;
2122
import io.reactivex.rxjava3.core.Completable;
2223
import io.reactivex.rxjava3.core.CompletableSource;
@@ -51,7 +52,7 @@ private LifecycleScopes() {
5152
* @throws OutsideScopeException if the {@link LifecycleScopeProvider#correspondingEvents()}
5253
* throws an {@link OutsideScopeException} during resolution.
5354
*/
54-
public static <E> CompletableSource resolveScopeFromLifecycle(
55+
public static <@NonNull E> CompletableSource resolveScopeFromLifecycle(
5556
final LifecycleScopeProvider<E> provider) throws OutsideScopeException {
5657
return resolveScopeFromLifecycle(provider, true);
5758
}
@@ -74,7 +75,7 @@ public static <E> CompletableSource resolveScopeFromLifecycle(
7475
* @throws OutsideScopeException if the {@link LifecycleScopeProvider#correspondingEvents()}
7576
* throws an {@link OutsideScopeException} during resolution.
7677
*/
77-
public static <E> CompletableSource resolveScopeFromLifecycle(
78+
public static <@NonNull E> CompletableSource resolveScopeFromLifecycle(
7879
final LifecycleScopeProvider<E> provider, final boolean checkEndBoundary)
7980
throws OutsideScopeException {
8081
E lastEvent = provider.peekLifecycle();
@@ -114,7 +115,7 @@ public static <E> CompletableSource resolveScopeFromLifecycle(
114115
* @param endEvent the target end event
115116
* @param <E> the lifecycle event type
116117
*/
117-
public static <E> CompletableSource resolveScopeFromLifecycle(
118+
public static <@NonNull E> CompletableSource resolveScopeFromLifecycle(
118119
Observable<E> lifecycle, final E endEvent) {
119120
@Nullable Comparator<E> comparator = null;
120121
if (endEvent instanceof Comparable) {
@@ -133,7 +134,7 @@ public static <E> CompletableSource resolveScopeFromLifecycle(
133134
* @param comparator an optional comparator for checking event equality.
134135
* @param <E> the lifecycle event type
135136
*/
136-
public static <E> CompletableSource resolveScopeFromLifecycle(
137+
public static <@NonNull E> CompletableSource resolveScopeFromLifecycle(
137138
Observable<E> lifecycle, final E endEvent, @Nullable final Comparator<E> comparator) {
138139
Predicate<E> equalityPredicate;
139140
if (comparator != null) {

autodispose/src/main/java/autodispose2/AutoDispose.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static autodispose2.AutoDisposeUtil.checkNotNull;
1919
import static autodispose2.Scopes.completableOf;
2020

21+
import io.reactivex.rxjava3.annotations.NonNull;
2122
import io.reactivex.rxjava3.core.Completable;
2223
import io.reactivex.rxjava3.core.CompletableObserver;
2324
import io.reactivex.rxjava3.core.CompletableSource;
@@ -76,7 +77,7 @@ public final class AutoDispose {
7677
* @return an {@link AutoDisposeConverter} to transform with operators like {@link
7778
* Observable#to(ObservableConverter)}
7879
*/
79-
public static <T> AutoDisposeConverter<T> autoDisposable(final ScopeProvider provider) {
80+
public static <@NonNull T> AutoDisposeConverter<T> autoDisposable(final ScopeProvider provider) {
8081
checkNotNull(provider, "provider == null");
8182
return autoDisposable(completableOf(provider));
8283
}
@@ -97,7 +98,7 @@ public static <T> AutoDisposeConverter<T> autoDisposable(final ScopeProvider pro
9798
* @return an {@link AutoDisposeConverter} to transform with operators like {@link
9899
* Observable#to(ObservableConverter)}
99100
*/
100-
public static <T> AutoDisposeConverter<T> autoDisposable(final CompletableSource scope) {
101+
public static <@NonNull T> AutoDisposeConverter<T> autoDisposable(final CompletableSource scope) {
101102
checkNotNull(scope, "scope == null");
102103
return new AutoDisposeConverter<T>() {
103104
@Override
@@ -136,7 +137,7 @@ public void subscribe(CompletableObserver observer) {
136137
}
137138

138139
@Override
139-
public <E extends CompletableObserver> E subscribeWith(E observer) {
140+
public <@NonNull E extends CompletableObserver> E subscribeWith(E observer) {
140141
return new AutoDisposeCompletable(upstream, scope).subscribeWith(observer);
141142
}
142143

@@ -194,7 +195,7 @@ public void subscribe(Subscriber<? super T> observer) {
194195
}
195196

196197
@Override
197-
public <E extends Subscriber<? super T>> E subscribeWith(E observer) {
198+
public <@NonNull E extends Subscriber<? super T>> E subscribeWith(E observer) {
198199
return new AutoDisposeFlowable<>(upstream, scope).subscribeWith(observer);
199200
}
200201

@@ -261,7 +262,7 @@ public void subscribe(MaybeObserver<? super T> observer) {
261262
}
262263

263264
@Override
264-
public <E extends MaybeObserver<? super T>> E subscribeWith(E observer) {
265+
public <@NonNull E extends MaybeObserver<? super T>> E subscribeWith(E observer) {
265266
return new AutoDisposeMaybe<>(upstream, scope).subscribeWith(observer);
266267
}
267268

@@ -319,7 +320,7 @@ public void subscribe(Observer<? super T> observer) {
319320
}
320321

321322
@Override
322-
public <E extends Observer<? super T>> E subscribeWith(E observer) {
323+
public <@NonNull E extends Observer<? super T>> E subscribeWith(E observer) {
323324
return new AutoDisposeObservable<>(upstream, scope).subscribeWith(observer);
324325
}
325326

@@ -375,7 +376,7 @@ public void subscribe(SingleObserver<? super T> observer) {
375376
}
376377

377378
@Override
378-
public <E extends SingleObserver<? super T>> E subscribeWith(E observer) {
379+
public <@NonNull E extends SingleObserver<? super T>> E subscribeWith(E observer) {
379380
return new AutoDisposeSingle<>(upstream, scope).subscribeWith(observer);
380381
}
381382

autodispose/src/main/java/autodispose2/AutoDisposeConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package autodispose2;
1717

18+
import io.reactivex.rxjava3.annotations.NonNull;
1819
import io.reactivex.rxjava3.core.CompletableConverter;
1920
import io.reactivex.rxjava3.core.FlowableConverter;
2021
import io.reactivex.rxjava3.core.MaybeConverter;
@@ -28,7 +29,7 @@
2829
*
2930
* @param <T> the type.
3031
*/
31-
public interface AutoDisposeConverter<T>
32+
public interface AutoDisposeConverter<@NonNull T>
3233
extends FlowableConverter<T, FlowableSubscribeProxy<T>>,
3334
ParallelFlowableConverter<T, ParallelFlowableSubscribeProxy<T>>,
3435
ObservableConverter<T, ObservableSubscribeProxy<T>>,

autodispose/src/main/java/autodispose2/AutoDisposeFlowable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package autodispose2;
1717

18+
import io.reactivex.rxjava3.annotations.NonNull;
1819
import io.reactivex.rxjava3.core.CompletableSource;
1920
import io.reactivex.rxjava3.core.Flowable;
2021
import org.reactivestreams.Publisher;
2122
import org.reactivestreams.Subscriber;
2223

23-
final class AutoDisposeFlowable<T> extends Flowable<T> implements FlowableSubscribeProxy<T> {
24+
final class AutoDisposeFlowable<@NonNull T> extends Flowable<T>
25+
implements FlowableSubscribeProxy<T> {
2426
private final Publisher<T> source;
2527
private final CompletableSource scope;
2628

0 commit comments

Comments
 (0)