Skip to content

Commit ecfb6b7

Browse files
authored
3.x: Improve Javadocs of Completable and some others (#6809)
1 parent 641e801 commit ecfb6b7

File tree

10 files changed

+729
-674
lines changed

10 files changed

+729
-674
lines changed

src/main/java/io/reactivex/rxjava3/core/Completable.java

Lines changed: 566 additions & 526 deletions
Large diffs are not rendered by default.

src/main/java/io/reactivex/rxjava3/core/Observable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5261,7 +5261,7 @@ public final Iterable<T> blockingIterable() {
52615261
@SchedulerSupport(SchedulerSupport.NONE)
52625262
@NonNull
52635263
public final Iterable<T> blockingIterable(int capacityHint) {
5264-
ObjectHelper.verifyPositive(capacityHint, "bufferSize");
5264+
ObjectHelper.verifyPositive(capacityHint, "capacityHint");
52655265
return new BlockingObservableIterable<>(this, capacityHint);
52665266
}
52675267

src/main/java/io/reactivex/rxjava3/disposables/Disposable.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public interface Disposable {
4141
* executed exactly once when the {@code Disposable} is disposed.
4242
* @param run the Runnable to wrap
4343
* @return the new Disposable instance
44+
* @throws NullPointerException if {@code run} is {@code null}
4445
* @since 3.0.0
4546
*/
4647
@NonNull
@@ -52,14 +53,15 @@ static Disposable fromRunnable(@NonNull Runnable run) {
5253
/**
5354
* Construct a {@code Disposable} by wrapping a {@link Action} that is
5455
* executed exactly once when the {@code Disposable} is disposed.
55-
* @param run the Action to wrap
56+
* @param action the Action to wrap
5657
* @return the new Disposable instance
58+
* @throws NullPointerException if {@code action} is {@code null}
5759
* @since 3.0.0
5860
*/
5961
@NonNull
60-
static Disposable fromAction(@NonNull Action run) {
61-
Objects.requireNonNull(run, "run is null");
62-
return new ActionDisposable(run);
62+
static Disposable fromAction(@NonNull Action action) {
63+
Objects.requireNonNull(action, "action is null");
64+
return new ActionDisposable(action);
6365
}
6466

6567
/**
@@ -69,6 +71,7 @@ static Disposable fromAction(@NonNull Action run) {
6971
* The {@code Future} is cancelled with {@code mayInterruptIfRunning == true}.
7072
* @param future the Future to wrap
7173
* @return the new Disposable instance
74+
* @throws NullPointerException if {@code future} is {@code null}
7275
* @see #fromFuture(Future, boolean)
7376
* @since 3.0.0
7477
*/
@@ -84,6 +87,7 @@ static Disposable fromFuture(@NonNull Future<?> future) {
8487
* @param future the Future to wrap
8588
* @param allowInterrupt if true, the future cancel happens via {@code Future.cancel(true)}
8689
* @return the new Disposable instance
90+
* @throws NullPointerException if {@code future} is {@code null}
8791
* @since 3.0.0
8892
*/
8993
@NonNull
@@ -97,6 +101,7 @@ static Disposable fromFuture(@NonNull Future<?> future, boolean allowInterrupt)
97101
* cancelled exactly once when the {@code Disposable} is disposed.
98102
* @param subscription the Runnable to wrap
99103
* @return the new Disposable instance
104+
* @throws NullPointerException if {@code subscription} is {@code null}
100105
* @since 3.0.0
101106
*/
102107
@NonNull
@@ -110,6 +115,7 @@ static Disposable fromSubscription(@NonNull Subscription subscription) {
110115
* closed exactly once when the {@code Disposable} is disposed.
111116
* @param autoCloseable the AutoCloseable to wrap
112117
* @return the new Disposable instance
118+
* @throws NullPointerException if {@code autoCloseable} is {@code null}
113119
* @since 3.0.0
114120
*/
115121
@NonNull
@@ -123,10 +129,12 @@ static Disposable fromAutoCloseable(@NonNull AutoCloseable autoCloseable) {
123129
* disposed when the returned {@code AutoCloseable} is closed.
124130
* @param disposable the Disposable instance
125131
* @return the new AutoCloseable instance
132+
* @throws NullPointerException if {@code disposable} is {@code null}
126133
* @since 3.0.0
127134
*/
128135
@NonNull
129136
static AutoCloseable toAutoCloseable(@NonNull Disposable disposable) {
137+
Objects.requireNonNull(disposable, "disposable is null");
130138
return disposable::dispose;
131139
}
132140

src/main/java/io/reactivex/rxjava3/flowables/ConnectableFlowable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ public final Flowable<T> refCount(int subscriberCount, long timeout, @NonNull Ti
249249
* @param unit the time unit of the timeout
250250
* @param scheduler the target scheduler to wait on before disconnecting
251251
* @return the new Flowable instance
252+
* @throws NullPointerException if {@code unit} or {@code scheduler} is {@code null}
253+
* @throws IllegalArgumentException if {@code subscriberCount} is non-positive
252254
* @since 2.2
253255
*/
254256
@CheckReturnValue

src/main/java/io/reactivex/rxjava3/observables/ConnectableObservable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ public final Observable<T> refCount(int subscriberCount, long timeout, @NonNull
224224
* @param unit the time unit of the timeout
225225
* @param scheduler the target scheduler to wait on before disconnecting
226226
* @return the new Observable instance
227+
* @throws IllegalArgumentException if {@code subscriberCount} is non-positive
228+
* @throws NullPointerException if {@code unit} or {@code scheduler} is {@code null}
227229
* @since 2.2
228230
*/
229231
@CheckReturnValue

src/main/java/io/reactivex/rxjava3/processors/BehaviorProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public static <T> BehaviorProcessor<T> create() {
204204
* the item that will be emitted first to any {@link Subscriber} as long as the
205205
* {@link BehaviorProcessor} has not yet observed any items from its source {@code Observable}
206206
* @return the constructed {@link BehaviorProcessor}
207+
* @throws NullPointerException if {@code defaultValue} is {@code null}
207208
*/
208209
@CheckReturnValue
209210
@NonNull

src/main/java/io/reactivex/rxjava3/processors/MulticastProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ public static <T> MulticastProcessor<T> create(boolean refCount) {
192192
* @param bufferSize the prefetch amount
193193
* @param <T> the input and output value type
194194
* @return the new MulticastProcessor instance
195+
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
195196
*/
196197
@CheckReturnValue
197198
@NonNull
198199
public static <T> MulticastProcessor<T> create(int bufferSize) {
200+
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
199201
return new MulticastProcessor<>(bufferSize, false);
200202
}
201203

@@ -207,10 +209,12 @@ public static <T> MulticastProcessor<T> create(int bufferSize) {
207209
* is cancelled
208210
* @param <T> the input and output value type
209211
* @return the new MulticastProcessor instance
212+
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
210213
*/
211214
@CheckReturnValue
212215
@NonNull
213216
public static <T> MulticastProcessor<T> create(int bufferSize, boolean refCount) {
217+
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
214218
return new MulticastProcessor<>(bufferSize, refCount);
215219
}
216220

@@ -223,7 +227,6 @@ public static <T> MulticastProcessor<T> create(int bufferSize, boolean refCount)
223227
*/
224228
@SuppressWarnings("unchecked")
225229
MulticastProcessor(int bufferSize, boolean refCount) {
226-
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
227230
this.bufferSize = bufferSize;
228231
this.limit = bufferSize - (bufferSize >> 2);
229232
this.wip = new AtomicInteger();

src/test/java/io/reactivex/rxjava3/validators/JavadocCodesAndLinks.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public void checkFlowable() throws Exception {
3535
checkSource("Flowable");
3636
}
3737

38+
@Test
39+
public void checkCompletable() throws Exception {
40+
checkSource("Completable");
41+
}
42+
3843
static void checkSource(String baseClassName) throws Exception {
3944
File f = TestHelper.findSource(baseClassName);
4045
if (f == null) {
@@ -346,15 +351,15 @@ static void blankRange(StringBuilder builder, int start, int end) {
346351

347352
"Exception", "Throwable", "NullPointerException", "IllegalStateException", "IllegalArgumentException", "MissingBackpressureException", "UndeliverableException",
348353
"OutOfMemoryError", "StackOverflowError", "NoSuchElementException", "ClassCastException", "CompositeException",
349-
"RuntimeException", "Error", "TimeoutException",
354+
"RuntimeException", "Error", "TimeoutException", "OnErrorNotImplementedException",
350355

351356
"false", "true", "onNext", "onError", "onComplete", "onSuccess", "onSubscribe", "null",
352357

353358
"ConnectableFlowable", "ConnectableObservable", "Subject", "FlowableProcessor", "Processor", "Scheduler",
354359

355360
"Optional", "CompletionStage", "Collector", "Collectors", "Schedulers", "RxJavaPlugins", "CompletableFuture",
356361

357-
"Object", "Integer", "Long", "Boolean", "LongConsumer",
362+
"Object", "Integer", "Long", "Boolean", "LongConsumer", "BooleanSupplier",
358363

359364
"GroupedFlowable", "GroupedObservable", "UnicastSubject", "UnicastProcessor",
360365

src/test/java/io/reactivex/rxjava3/validators/JavadocWording.java

Lines changed: 37 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -317,65 +317,7 @@ public void flowableDocRefersToFlowableTypes() throws Exception {
317317
}
318318
}
319319

320-
if (m.signature.matches("(?s).*?\\sSingle\\<.*?\\>\\s+\\w+\\(.*")) {
321-
for (String at : AT_RETURN_WORDS) {
322-
int idx = m.javadoc.indexOf(at + "{@code Flowable");
323-
if (idx >= 0) {
324-
e.append("Returns Single but docs return Flowable\r\n at io.reactivex.rxjava3.core.")
325-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
326-
}
327-
idx = m.javadoc.indexOf(at + "{@code Maybe");
328-
if (idx >= 0) {
329-
e.append("Returns Single but docs return Maybe\r\n at io.reactivex.rxjava3.core.")
330-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
331-
}
332-
idx = m.javadoc.indexOf(at + "{@code Publisher");
333-
if (idx >= 0) {
334-
e.append("Returns Single but docs return Publisher\r\n at io.reactivex.rxjava3.core.")
335-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
336-
}
337-
}
338-
}
339-
340-
if (m.signature.matches("(?s).*?\\sMaybe\\<.*\\>\\s+\\w+\\(.*")) {
341-
for (String at : AT_RETURN_WORDS) {
342-
int idx = m.javadoc.indexOf(at + "{@code Flowable");
343-
if (idx >= 0) {
344-
e.append("Returns Maybe but docs return Flowable\r\n at io.reactivex.rxjava3.core.")
345-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
346-
}
347-
idx = m.javadoc.indexOf(at + "{@code Single");
348-
if (idx >= 0) {
349-
e.append("Returns Maybe but docs return Single\r\n at io.reactivex.rxjava3.core.")
350-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
351-
}
352-
idx = m.javadoc.indexOf(at + "{@code Publisher");
353-
if (idx >= 0) {
354-
e.append("Returns Maybe but docs return Publisher\r\n at io.reactivex.rxjava3.core.")
355-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
356-
}
357-
}
358-
}
359-
360-
if (m.signature.matches("(?s).*?\\sCompletable\\s+\\w+\\(.*")) {
361-
for (String at : AT_RETURN_WORDS) {
362-
int idx = m.javadoc.indexOf(at + "{@code Flowable");
363-
if (idx >= 0) {
364-
e.append("Returns Completable but docs return Flowable\r\n at io.reactivex.rxjava3.core.")
365-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
366-
}
367-
idx = m.javadoc.indexOf(at + "{@code Single");
368-
if (idx >= 0) {
369-
e.append("Returns Completable but docs return Single\r\n at io.reactivex.rxjava3.core.")
370-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
371-
}
372-
idx = m.javadoc.indexOf(at + "{@code Maybe");
373-
if (idx >= 0) {
374-
e.append("Returns Completable but docs return Maybe\r\n at io.reactivex.rxjava3.core.")
375-
.append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
376-
}
377-
}
378-
}
320+
checkAtReturnAndSignatureMatch("Flowable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable");
379321

380322
aOrAn(e, m, "Flowable");
381323
missingClosingDD(e, m, "Flowable");
@@ -478,55 +420,7 @@ public void observableDocRefersToObservableTypes() throws Exception {
478420
break;
479421
}
480422
}
481-
if (m.signature.matches("(?s).*?\\sSingle\\<.*?\\>\\s+\\w+\\(.*")) {
482-
for (String at : AT_RETURN_WORDS) {
483-
int idx = m.javadoc.indexOf(at + "{@code Observable");
484-
if (idx >= 0) {
485-
e.append("Returns Single but docs return Observable\r\n at io.reactivex.rxjava3.core.")
486-
.append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
487-
}
488-
idx = m.javadoc.indexOf(at + "{@code Maybe");
489-
if (idx >= 0) {
490-
e.append("Returns Single but docs return Maybe\r\n at io.reactivex.rxjava3.core.")
491-
.append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
492-
}
493-
}
494-
}
495-
496-
if (m.signature.matches("(?s).*?\\sMaybe\\<.*?\\>\\s+\\w+\\(.*")) {
497-
for (String at : AT_RETURN_WORDS) {
498-
int idx = m.javadoc.indexOf(at + "{@code Observable");
499-
if (idx >= 0) {
500-
e.append("Returns Maybe but docs return Observable\r\n at io.reactivex.rxjava3.core.")
501-
.append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
502-
}
503-
idx = m.javadoc.indexOf(at + "{@code Single");
504-
if (idx >= 0) {
505-
e.append("Returns Maybe but docs return Single\r\n at io.reactivex.rxjava3.core.")
506-
.append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
507-
}
508-
}
509-
}
510-
511-
if (m.signature.matches("(?s).*?\\sCompletable\\s+\\w+\\(.*")) {
512-
for (String at : AT_RETURN_WORDS) {
513-
int idx = m.javadoc.indexOf(at + "{@code Observable");
514-
if (idx >= 0) {
515-
e.append("Returns Completable but docs return Observable\r\n at io.reactivex.rxjava3.core.")
516-
.append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
517-
}
518-
idx = m.javadoc.indexOf(at + "{@code Single");
519-
if (idx >= 0) {
520-
e.append("Returns Completable but docs return Single\r\n at io.reactivex.rxjava3.core.")
521-
.append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
522-
}
523-
idx = m.javadoc.indexOf(at + "{@code Maybe");
524-
if (idx >= 0) {
525-
e.append("Returns Completable but docs return Maybe\r\n at io.reactivex.rxjava3.core.")
526-
.append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
527-
}
528-
}
529-
}
423+
checkAtReturnAndSignatureMatch("Observable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable");
530424

531425
aOrAn(e, m, "Observable");
532426
missingClosingDD(e, m, "Observable");
@@ -890,6 +784,9 @@ public void completableDocRefersToCompletableTypes() throws Exception {
890784
break;
891785
}
892786
}
787+
788+
checkAtReturnAndSignatureMatch("Completable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable");
789+
893790
aOrAn(e, m, "Completable");
894791
missingClosingDD(e, m, "Completable");
895792
backpressureMentionedWithoutAnnotation(e, m, "Completable");
@@ -903,6 +800,38 @@ public void completableDocRefersToCompletableTypes() throws Exception {
903800
}
904801
}
905802

803+
static void checkAtReturnAndSignatureMatch(String className, RxMethod m, StringBuilder e, String... types) {
804+
for (String t : types) {
805+
String regex;
806+
if (t.contains("Completable")) {
807+
regex = "(?s).*?\\s" + t + "\\s+\\w+\\(.*";
808+
} else {
809+
regex = "(?s).*?\\s" + t + "\\<.*?\\>\\s+\\w+\\(.*";
810+
}
811+
if (m.signature.matches(regex)) {
812+
for (String at : AT_RETURN_WORDS) {
813+
for (String u : types) {
814+
if (!t.equals(u)) {
815+
int idx = m.javadoc.indexOf(at + "{@code " + u);
816+
if (idx >= 0) {
817+
e.append("Returns ").append(t)
818+
.append(" but docs return ")
819+
.append(u)
820+
.append("\r\n at io.reactivex.rxjava3.core.")
821+
.append(className)
822+
.append(".method(")
823+
.append(className)
824+
.append(".java:")
825+
.append(m.javadocLine + lineNumber(m.javadoc, idx) - 1)
826+
.append(")\r\n\r\n");
827+
}
828+
}
829+
}
830+
}
831+
}
832+
}
833+
}
834+
906835
static void aOrAn(StringBuilder e, RxMethod m, String baseTypeName) {
907836
aOrAn(e, m, " an", "Single", baseTypeName);
908837
aOrAn(e, m, " an", "Maybe", baseTypeName);

0 commit comments

Comments
 (0)