Skip to content

Commit 7ff1eef

Browse files
tonycosentiniakarnokd
authored andcommitted
Annotate function interfaces. (#5023)
1 parent ee004ad commit 7ff1eef

File tree

14 files changed

+77
-12
lines changed

14 files changed

+77
-12
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2016-present, RxJava Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.annotations;
15+
16+
import java.lang.annotation.Documented;
17+
import java.lang.annotation.Retention;
18+
import java.lang.annotation.Target;
19+
20+
import static java.lang.annotation.ElementType.FIELD;
21+
import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
22+
import static java.lang.annotation.ElementType.METHOD;
23+
import static java.lang.annotation.ElementType.PARAMETER;
24+
import static java.lang.annotation.RetentionPolicy.CLASS;
25+
26+
@Documented
27+
@Target(value = {FIELD, METHOD, PARAMETER, LOCAL_VARIABLE})
28+
@Retention(value = CLASS)
29+
public @interface NonNull { }
30+

src/main/java/io/reactivex/functions/BiConsumer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that accepts two values (of possibly different types).
1820
* @param <T1> the first value type
@@ -26,5 +28,5 @@ public interface BiConsumer<T1, T2> {
2628
* @param t2 the second value
2729
* @throws Exception on error
2830
*/
29-
void accept(T1 t1, T2 t2) throws Exception;
31+
void accept(@NonNull T1 t1, @NonNull T2 t2) throws Exception;
3032
}

src/main/java/io/reactivex/functions/BiFunction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that computes a value based on multiple input values.
1820
* @param <T1> the first value type
@@ -28,5 +30,6 @@ public interface BiFunction<T1, T2, R> {
2830
* @return the result value
2931
* @throws Exception on error
3032
*/
31-
R apply(T1 t1, T2 t2) throws Exception;
33+
@NonNull
34+
R apply(@NonNull T1 t1, @NonNull T2 t2) throws Exception;
3235
}

src/main/java/io/reactivex/functions/BiPredicate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that returns true or false for the given input values.
1820
* @param <T1> the first value
@@ -27,5 +29,5 @@ public interface BiPredicate<T1, T2> {
2729
* @return the boolean result
2830
* @throws Exception on error
2931
*/
30-
boolean test(T1 t1, T2 t2) throws Exception;
32+
boolean test(@NonNull T1 t1, @NonNull T2 t2) throws Exception;
3133
}

src/main/java/io/reactivex/functions/Consumer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that accepts a single value.
1820
* @param <T> the value type
@@ -23,5 +25,5 @@ public interface Consumer<T> {
2325
* @param t the value
2426
* @throws Exception on error
2527
*/
26-
void accept(T t) throws Exception;
28+
void accept(@NonNull T t) throws Exception;
2729
}

src/main/java/io/reactivex/functions/Function.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface that takes a value and returns another value, possibly with a
1820
* different type and allows throwing a checked exception.
@@ -27,5 +29,6 @@ public interface Function<T, R> {
2729
* @return the output value
2830
* @throws Exception on error
2931
*/
30-
R apply(T t) throws Exception;
32+
@NonNull
33+
R apply(@NonNull T t) throws Exception;
3134
}

src/main/java/io/reactivex/functions/Function3.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that computes a value based on multiple input values.
1820
* @param <T1> the first value type
@@ -29,5 +31,6 @@ public interface Function3<T1, T2, T3, R> {
2931
* @return the result value
3032
* @throws Exception on error
3133
*/
32-
R apply(T1 t1, T2 t2, T3 t3) throws Exception;
34+
@NonNull
35+
R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3) throws Exception;
3336
}

src/main/java/io/reactivex/functions/Function4.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that computes a value based on multiple input values.
1820
* @param <T1> the first value type
@@ -31,5 +33,6 @@ public interface Function4<T1, T2, T3, T4, R> {
3133
* @return the result value
3234
* @throws Exception on error
3335
*/
34-
R apply(T1 t1, T2 t2, T3 t3, T4 t4) throws Exception;
36+
@NonNull
37+
R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4) throws Exception;
3538
}

src/main/java/io/reactivex/functions/Function5.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that computes a value based on multiple input values.
1820
* @param <T1> the first value type
@@ -33,5 +35,6 @@ public interface Function5<T1, T2, T3, T4, T5, R> {
3335
* @return the result value
3436
* @throws Exception on error
3537
*/
36-
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Exception;
38+
@NonNull
39+
R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4, @NonNull T5 t5) throws Exception;
3740
}

src/main/java/io/reactivex/functions/Function6.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.functions;
1515

16+
import io.reactivex.annotations.NonNull;
17+
1618
/**
1719
* A functional interface (callback) that computes a value based on multiple input values.
1820
* @param <T1> the first value type
@@ -35,5 +37,6 @@ public interface Function6<T1, T2, T3, T4, T5, T6, R> {
3537
* @return the result value
3638
* @throws Exception on error
3739
*/
38-
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) throws Exception;
40+
@NonNull
41+
R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4, @NonNull T5 t5, @NonNull T6 t6) throws Exception;
3942
}

0 commit comments

Comments
 (0)