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

Add CheckReturnValue annotation #4881

Merged
merged 3 commits into from
Nov 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/main/java/io/reactivex/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ public final void subscribe(CompletableObserver s) {
* @throws NullPointerException if {@code observer} is null
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <E extends CompletableObserver> E subscribeWith(E observer) {
subscribe(observer);
Expand Down Expand Up @@ -1871,6 +1872,7 @@ public final Completable unsubscribeOn(final Scheduler scheduler) {
* @return the new TestObserver instance
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<Void> test() {
TestObserver<Void> ts = new TestObserver<Void>();
Expand All @@ -1889,6 +1891,7 @@ public final TestObserver<Void> test() {
* @return the new TestObserver instance
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<Void> test(boolean cancelled) {
TestObserver<Void> ts = new TestObserver<Void>();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/reactivex/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12266,6 +12266,7 @@ public final void subscribe(Subscriber<? super T> s) {
* @throws NullPointerException if {@code subscriber} is null
* @since 2.0
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.SPECIAL)
@SchedulerSupport(SchedulerSupport.NONE)
public final <E extends Subscriber<? super T>> E subscribeWith(E subscriber) {
Expand Down Expand Up @@ -15303,6 +15304,7 @@ public final <U, R> Flowable<R> zipWith(Publisher<? extends U> other,
* @return the new TestSubscriber instance
* @since 2.0
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
@SchedulerSupport(SchedulerSupport.NONE)
public final TestSubscriber<T> test() { // NoPMD
Expand All @@ -15324,6 +15326,7 @@ public final TestSubscriber<T> test() { // NoPMD
* @return the new TestSubscriber instance
* @since 2.0
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
public final TestSubscriber<T> test(long initialRequest) { // NoPMD
Expand All @@ -15347,6 +15350,7 @@ public final TestSubscriber<T> test(long initialRequest) { // NoPMD
* @return the new TestSubscriber instance
* @since 2.0
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
public final TestSubscriber<T> test(long initialRequest, boolean cancel) { // NoPMD
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3625,6 +3625,7 @@ public final Maybe<T> subscribeOn(Scheduler scheduler) {
* @return the input {@code subscriber}
* @throws NullPointerException if {@code subscriber} is null
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <E extends MaybeObserver<? super T>> E subscribeWith(E observer) {
subscribe(observer);
Expand Down Expand Up @@ -3954,6 +3955,7 @@ public final <U, R> Maybe<R> zipWith(MaybeSource<? extends U> other, BiFunction<
* </dl>
* @return the new TestObserver instance
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<T> test() {
TestObserver<T> ts = new TestObserver<T>();
Expand All @@ -3971,6 +3973,7 @@ public final TestObserver<T> test() {
* Maybe.
* @return the new TestObserver instance
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<T> test(boolean cancelled) {
TestObserver<T> ts = new TestObserver<T>();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -10224,6 +10224,7 @@ public final void subscribe(Observer<? super T> observer) {
* @throws NullPointerException if {@code observer} is null
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <E extends Observer<? super T>> E subscribeWith(E observer) {
subscribe(observer);
Expand Down Expand Up @@ -12872,6 +12873,7 @@ public final <U, R> Observable<R> zipWith(ObservableSource<? extends U> other,
* @return the new TestObserver instance
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<T> test() { // NoPMD
TestObserver<T> ts = new TestObserver<T>();
Expand All @@ -12891,6 +12893,7 @@ public final TestObserver<T> test() { // NoPMD
* @return the new TestObserver instance
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<T> test(boolean dispose) { // NoPMD
TestObserver<T> ts = new TestObserver<T>();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,7 @@ public final void subscribe(SingleObserver<? super T> subscriber) {
* @throws NullPointerException if {@code observer} is null
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <E extends SingleObserver<? super T>> E subscribeWith(E observer) {
subscribe(observer);
Expand Down Expand Up @@ -2946,6 +2947,7 @@ public final <U, R> Single<R> zipWith(SingleSource<U> other, BiFunction<? super
* @return the new TestObserver instance
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<T> test() {
TestObserver<T> ts = new TestObserver<T>();
Expand All @@ -2964,6 +2966,7 @@ public final TestObserver<T> test() {
* @return the new TestObserver instance
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<T> test(boolean cancelled) {
TestObserver<T> ts = new TestObserver<T>();
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/io/reactivex/annotations/CheckReturnValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2016 Netflix, Inc.
*
* 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.
*/

package io.reactivex.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marks methods whose return values should be checked.
*
* @since 2.0.2 - experimental
*/
@Retention(RetentionPolicy.RUNTIME)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: static import makes it a little bit better

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I know however for RxJava it's common to not static import them (look at BackpressureSupport & SchedulerSupport) so I left it that way. I leave the final decision up to David.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine as is.

@Documented
@Target(ElementType.METHOD)
Copy link
Contributor

Choose a reason for hiding this comment

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

And here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same as above

@Experimental
public @interface CheckReturnValue {

}