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

Switch to provided jsr305 and nullability improvements #69

Merged
merged 1 commit into from
May 13, 2017
Merged
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
2 changes: 2 additions & 0 deletions autodispose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ test {
dependencies {
api deps.rx.java
compileOnly deps.misc.errorProneAnnotations
compileOnly deps.misc.jsr305

errorprone deps.build.errorProne

testCompile deps.test.junit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.reactivex.disposables.Disposable;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;

/**
* Utility methods for working with Disposables atomically. Copied from the RxJava implementation.
Expand All @@ -33,7 +34,7 @@ static boolean isDisposed(Disposable d) {
return d == DISPOSED;
}

static boolean set(AtomicReference<Disposable> field, Disposable d) {
static boolean set(AtomicReference<Disposable> field, @Nullable Disposable d) {
for (; ; ) {
Disposable current = field.get();
if (current == DISPOSED) {
Expand Down Expand Up @@ -96,7 +97,7 @@ static boolean setIfNotSet(AtomicReference<Disposable> field, Disposable d) {
* @return true if the operation succeeded, false if the target field contained
* the common DISPOSED instance and the given disposable (if not null) is disposed.
*/
static boolean replace(AtomicReference<Disposable> field, Disposable d) {
static boolean replace(AtomicReference<Disposable> field, @Nullable Disposable d) {
for (; ; ) {
Disposable current = field.get();
if (current == DISPOSED) {
Expand Down Expand Up @@ -140,7 +141,8 @@ static boolean dispose(AtomicReference<Disposable> field) {
* @param next the next Disposable, expected to be non-null
* @return true if the validation succeeded
*/
static boolean validate(Disposable current, Disposable next) {
static boolean validate(@Nullable Disposable current, Disposable next) {
//noinspection ConstantConditions leftover from original RxJava implementation
if (next == null) {
RxJavaPlugins.onError(new NullPointerException("next is null"));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.uber.autodispose;

import io.reactivex.annotations.Nullable;
import io.reactivex.functions.Consumer;
import javax.annotation.Nullable;

/**
* Utility class to inject handlers to certain standard AutoDispose operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.uber.autodispose;

import io.reactivex.annotations.Nullable;
import javax.annotation.Nullable;

final class AutoDisposeUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
import org.reactivestreams.Subscription;

/**
Expand Down Expand Up @@ -48,7 +49,8 @@ enum AutoSubscriptionHelper implements Subscription {
* @param next the next Subscription, expected to be non-null
* @return true if the validation succeeded
*/
static boolean validate(Subscription current, Subscription next) {
static boolean validate(@Nullable Subscription current, Subscription next) {
//noinspection ConstantConditions left as is from original RxJava implementation
if (next == null) {
RxJavaPlugins.onError(new NullPointerException("next is null"));
return false;
Expand Down Expand Up @@ -113,7 +115,7 @@ static boolean isCancelled(Subscription s) {
* holds the {@link #CANCELLED} instance.
* @see #replace(AtomicReference, Subscription)
*/
static boolean set(AtomicReference<Subscription> field, Subscription s) {
static boolean set(AtomicReference<Subscription> field, @Nullable Subscription s) {
for (; ; ) {
Subscription current = field.get();
if (current == CANCELLED) {
Expand Down Expand Up @@ -175,7 +177,7 @@ static boolean setIfNotSet(AtomicReference<Subscription> field, Subscription s)
* holds the {@link #CANCELLED} instance.
* @see #set(AtomicReference, Subscription)
*/
static boolean replace(AtomicReference<Subscription> field, Subscription s) {
static boolean replace(AtomicReference<Subscription> field, @Nullable Subscription s) {
for (; ; ) {
Subscription current = field.get();
if (current == CANCELLED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import io.reactivex.Observable;
import io.reactivex.annotations.CheckReturnValue;
import io.reactivex.annotations.Nullable;
import io.reactivex.functions.Function;
import javax.annotation.Nullable;

/**
* An interface that, when implemented, provides information to AutoDispose to allow it to resolve
Expand Down
16 changes: 10 additions & 6 deletions autodispose/src/main/java/com/uber/autodispose/ScopeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package com.uber.autodispose;

import java.util.concurrent.Callable;

import io.reactivex.Maybe;
import io.reactivex.MaybeSource;
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import java.util.concurrent.Callable;

/**
* Utilities for dealing with scopes, usually for providers. This includes factories for resolving
Expand Down Expand Up @@ -76,8 +76,10 @@ public static <E> Maybe<LifecycleEndNotification> deferredResolvedLifecycle(
E lastEvent = provider.peekLifecycle();
if (checkStartBoundary && lastEvent == null) {
LifecycleNotStartedException exception = new LifecycleNotStartedException();
if (AutoDisposePlugins.getOutsideLifecycleHandler() != null) {
AutoDisposePlugins.getOutsideLifecycleHandler().accept(exception);
Consumer<? super OutsideLifecycleException> handler
= AutoDisposePlugins.getOutsideLifecycleHandler();
if (handler != null) {
handler.accept(exception);
return Maybe.just(LifecycleEndNotification.INSTANCE);
} else {
throw exception;
Expand All @@ -89,8 +91,10 @@ public static <E> Maybe<LifecycleEndNotification> deferredResolvedLifecycle(
.apply(lastEvent);
} catch (Exception e) {
if (checkEndBoundary && e instanceof LifecycleEndedException) {
if (AutoDisposePlugins.getOutsideLifecycleHandler() != null) {
AutoDisposePlugins.getOutsideLifecycleHandler().accept((LifecycleEndedException) e);
Consumer<? super OutsideLifecycleException> handler
= AutoDisposePlugins.getOutsideLifecycleHandler();
if (handler != null) {
handler.accept((LifecycleEndedException) e);
return Maybe.just(LifecycleEndNotification.INSTANCE);
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package com.uber.autodispose;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.annotations.Nullable;
import io.reactivex.functions.Function;
import io.reactivex.subjects.BehaviorSubject;
import javax.annotation.Nullable;

/**
* Test utility to create {@link LifecycleScopeProvider} instances for tests.
Expand Down Expand Up @@ -66,7 +65,7 @@ public static TestLifecycleScopeProvider createInitial(TestLifecycle initialValu

@Override public Function<TestLifecycle, TestLifecycle> correspondingEvents() {
return new Function<TestLifecycle, TestLifecycle>() {
@Override public TestLifecycle apply(@NonNull TestLifecycle testLifecycle) {
@Override public TestLifecycle apply(TestLifecycle testLifecycle) {
switch (testLifecycle) {
case STARTED:
return TestLifecycle.STOPPED;
Expand Down
22 changes: 22 additions & 0 deletions autodispose/src/main/java/com/uber/autodispose/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2017. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* AutoDispose is an RxJava 2 tool for automatically binding the execution of RxJava 2 streams to a
* provided scope via disposal/cancellation.
*/
@javax.annotation.ParametersAreNonnullByDefault
package com.uber.autodispose;
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
import io.reactivex.Maybe;
import io.reactivex.MaybeEmitter;
import io.reactivex.MaybeOnSubscribe;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Cancellable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Predicate;
import io.reactivex.observers.TestObserver;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.MaybeSubject;

import java.util.concurrent.atomic.AtomicInteger;

import org.junit.After;
import org.junit.Test;

Expand Down Expand Up @@ -67,7 +64,7 @@ public class AutoDisposeMaybeObserverTest {
Maybe.just(new BClass())
.to(new MaybeScoper<AClass>(Maybe.never()))
.subscribe(new Consumer<AClass>() {
@Override public void accept(@NonNull AClass aClass) throws Exception {
@Override public void accept(AClass aClass) throws Exception {

}
});
Expand All @@ -87,7 +84,7 @@ public class AutoDisposeMaybeObserverTest {
.subscribe(o);
source.to(new MaybeScoper<Integer>(lifecycle))
.subscribe(new Consumer<Integer>() {
@Override public void accept(@NonNull Integer integer) throws Exception {
@Override public void accept(Integer integer) throws Exception {

}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Cancellable;
import io.reactivex.functions.Consumer;
Expand All @@ -30,7 +29,6 @@
import io.reactivex.subjects.MaybeSubject;
import io.reactivex.subjects.PublishSubject;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.After;
import org.junit.Test;

Expand Down Expand Up @@ -69,7 +67,7 @@ public class AutoDisposeObserverTest {
Observable.just(new BClass())
.to(new ObservableScoper<AClass>(Maybe.never()))
.subscribe(new Consumer<AClass>() {
@Override public void accept(@NonNull AClass aClass) throws Exception {
@Override public void accept(AClass aClass) throws Exception {

}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.reactivex.Single;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Cancellable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Predicate;
Expand All @@ -29,7 +28,6 @@
import io.reactivex.subjects.MaybeSubject;
import io.reactivex.subjects.SingleSubject;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.After;
import org.junit.Test;

Expand Down Expand Up @@ -68,7 +66,7 @@ public class AutoDisposeSingleObserverTest {
Single.just(new BClass())
.to(new SingleScoper<AClass>(Maybe.never()))
.subscribe(new Consumer<AClass>() {
@Override public void accept(@NonNull AClass aClass) throws Exception {
@Override public void accept(AClass aClass) throws Exception {

}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
import io.reactivex.Maybe;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Cancellable;
import io.reactivex.functions.Consumer;
Expand All @@ -32,7 +31,6 @@
import io.reactivex.subscribers.TestSubscriber;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.After;
import org.junit.Test;

Expand Down Expand Up @@ -71,7 +69,7 @@ public class AutoDisposeSubscriberTest {
Flowable.just(new BClass())
.to(new FlowableScoper<AClass>(Maybe.never()))
.subscribe(new Consumer<AClass>() {
@Override public void accept(@NonNull AClass aClass) throws Exception {
@Override public void accept(AClass aClass) throws Exception {

}
});
Expand Down
5 changes: 2 additions & 3 deletions autodispose/src/test/java/com/uber/autodispose/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.reactivex.Maybe;
import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.MaybeSubject;
Expand Down Expand Up @@ -53,11 +52,11 @@ static ScopeProvider makeProvider(final MaybeSubject<Integer> scope) {
static LifecycleScopeProvider<Integer> makeLifecycleProvider(
final BehaviorSubject<Integer> lifecycle) {
return new LifecycleScopeProvider<Integer>() {
@NonNull @Override public Observable<Integer> lifecycle() {
@Override public Observable<Integer> lifecycle() {
return lifecycle;
}

@NonNull @Override public Function<Integer, Integer> correspondingEvents() {
@Override public Function<Integer, Integer> correspondingEvents() {
return CORRESPONDING_EVENTS;
}

Expand Down
3 changes: 2 additions & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def kotlin = [
]

def misc = [
errorProneAnnotations: "com.google.errorprone:error_prone_annotations:${versions.errorProne}"
errorProneAnnotations: "com.google.errorprone:error_prone_annotations:${versions.errorProne}",
jsr305: 'com.google.code.findbugs:jsr305:3.0.2'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces after the jsr305 to match the width till the : on the previous line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project doesn't follow that pattern since it often damages git history

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright ignore that then :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

]

def rx = [
Expand Down