Skip to content

Commit 5756066

Browse files
authored
4.x: Hide documentation in sealed interfaces [1/x] (#8028)
* 4.x: Hide documentation in sealed interfaces [1/x] This should reduce the file size of the main classes while also keeping docks in IDEs. * Fix a couple of lint and other generics issues * Finally fix checkstyle.
1 parent 043687c commit 5756066

File tree

16 files changed

+148
-82
lines changed

16 files changed

+148
-82
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ java {
6565

6666
tasks.withType(JavaCompile) {
6767
options.compilerArgs << "-parameters"
68+
options.compilerArgs += '-Xlint:-module'
69+
options.compilerArgs += '-Xlint:unchecked'
6870
}
6971

7072
apply from: file("gradle/javadoc_cleanup.gradle")

config/checkstyle/checkstyle.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<module name="Checker">
1212
<property name="severity" value="warning"/>
1313
<module name="SuppressionFilter">
14-
<property name="file" value="${project_loc}/config/checkstyle/suppressions.xml"/>
14+
<property name="file" value="${config_loc}/suppressions.xml"/>
1515
<property name="optional" value="false"/>
1616
</module>
1717
<module name="BeforeExecutionExclusionFileFilter">
@@ -28,6 +28,6 @@
2828
</module>
2929
<module name="Header">
3030
<property name="fileExtensions" value="java"/>
31-
<property name="headerFile" value="${project_loc}/config/license/HEADER_JAVA"/>
31+
<property name="headerFile" value="${config_loc}/../license/HEADER_JAVA"/>
3232
</module>
3333
</module>

config/checkstyle/suppressions.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
<suppressions>
88

9-
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*[\\/]src[\\/]main[\\/]java[\\/]io[\\/]reactivex[\\/]rxjava4[\\/]internal[\\/].*\.java$"/>
10-
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*[\\/]src[\\/]test[\\/]java[\\/].*\.java$"/>
11-
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*[\\/]src[\\/]jmh[\\/]java[\\/].*\.java$"/>
12-
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*Test\.java$"/>
13-
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*Perf\.java$"/>
9+
<suppress checks="MissingJavadocMethod|JavadocMethod" files=".*[\\/]src[\\/]main[\\/]java[\\/]io[\\/]reactivex[\\/]rxjava4[\\/]internal[\\/].*\.java$"/>
10+
<suppress checks="MissingJavadocMethod|JavadocMethod" files=".*[\\/]src[\\/]test[\\/]java[\\/].*\.java$"/>
11+
<suppress checks="MissingJavadocMethod|JavadocMethod" files=".*[\\/]src[\\/]jmh[\\/]java[\\/].*\.java$"/>
12+
<suppress checks="MissingJavadocMethod|JavadocMethod" files=".*Test\.java$"/>
13+
<suppress checks="MissingJavadocMethod|JavadocMethod" files=".*Perf\.java$"/>
1414

1515
</suppressions>

src/jmh/java/io/reactivex/rxjava4/core/BinaryFlatMapPerf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import io.reactivex.rxjava4.functions.Function;
2424

25-
@SuppressWarnings("exports")
25+
@SuppressWarnings("exports")
2626
@BenchmarkMode(Mode.Throughput)
2727
@Warmup(iterations = 5)
2828
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)

src/main/java/io/reactivex/rxjava4/core/Flowable.java

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.stream.*;
2020

2121
import io.reactivex.rxjava4.annotations.*;
22+
import io.reactivex.rxjava4.core.docs.FlowableDocBasic;
2223
import io.reactivex.rxjava4.disposables.*;
2324
import io.reactivex.rxjava4.exceptions.*;
2425
import io.reactivex.rxjava4.flowables.*;
@@ -153,7 +154,9 @@
153154
* @see ParallelFlowable
154155
* @see io.reactivex.rxjava4.subscribers.DisposableSubscriber
155156
*/
156-
public abstract class Flowable<@NonNull T> implements Publisher<T> {
157+
public abstract non-sealed class Flowable<@NonNull T> implements Publisher<T>,
158+
FlowableDocBasic<T>
159+
{
157160
/** The default buffer size. */
158161
static final int BUFFER_SIZE;
159162
static {
@@ -10146,29 +10149,12 @@ public final Single<T> elementAtOrError(long index) {
1014610149
return RxJavaPlugins.onAssembly(new FlowableElementAtSingle<>(this, index, null));
1014710150
}
1014810151

10149-
/**
10150-
* Filters items emitted by the current {@code Flowable} by only emitting those that satisfy a specified predicate.
10151-
* <p>
10152-
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/filter.v3.png" alt="">
10153-
* <dl>
10154-
* <dt><b>Backpressure:</b></dt>
10155-
* <dd>The operator doesn't interfere with backpressure which is determined by the current {@code Flowable}'s backpressure
10156-
* behavior.</dd>
10157-
* <dt><b>Scheduler:</b></dt>
10158-
* <dd>{@code filter} does not operate by default on a particular {@link Scheduler}.</dd>
10159-
* </dl>
10160-
*
10161-
* @param predicate
10162-
* a function that evaluates each item emitted by the current {@code Flowable}, returning {@code true}
10163-
* if it passes the filter
10164-
* @return the new {@code Flowable} instance
10165-
* @throws NullPointerException if {@code predicate} is {@code null}
10166-
* @see <a href="http://reactivex.io/documentation/operators/filter.html">ReactiveX operators documentation: Filter</a>
10167-
*/
10152+
/** {@inheritDoc} */
1016810153
@CheckReturnValue
1016910154
@NonNull
1017010155
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
1017110156
@SchedulerSupport(SchedulerSupport.NONE)
10157+
@Override
1017210158
public final Flowable<T> filter(@NonNull Predicate<? super T> predicate) {
1017310159
Objects.requireNonNull(predicate, "predicate is null");
1017410160
return RxJavaPlugins.onAssembly(new FlowableFilter<>(this, predicate));
@@ -12038,31 +12024,12 @@ public final Single<T> lastOrError() {
1203812024
return RxJavaPlugins.onAssembly(new FlowableLift<>(this, lifter));
1203912025
}
1204012026

12041-
/**
12042-
* Returns a {@code Flowable} that applies a specified function to each item emitted by the current {@code Flowable} and
12043-
* emits the results of these function applications.
12044-
* <p>
12045-
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/map.v3.png" alt="">
12046-
* <dl>
12047-
* <dt><b>Backpressure:</b></dt>
12048-
* <dd>The operator doesn't interfere with backpressure which is determined by the current {@code Flowable}'s backpressure
12049-
* behavior.</dd>
12050-
* <dt><b>Scheduler:</b></dt>
12051-
* <dd>{@code map} does not operate by default on a particular {@link Scheduler}.</dd>
12052-
* </dl>
12053-
*
12054-
* @param <R> the output type
12055-
* @param mapper
12056-
* a function to apply to each item emitted by the current {@code Flowable}
12057-
* @return the new {@code Flowable} instance
12058-
* @throws NullPointerException if {@code mapper} is {@code null}
12059-
* @see <a href="http://reactivex.io/documentation/operators/map.html">ReactiveX operators documentation: Map</a>
12060-
* @see #mapOptional(Function)
12061-
*/
12027+
/** {@inheritDoc} */
1206212028
@CheckReturnValue
1206312029
@NonNull
1206412030
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
1206512031
@SchedulerSupport(SchedulerSupport.NONE)
12032+
@Override
1206612033
public final <@NonNull R> Flowable<R> map(@NonNull Function<? super T, ? extends R> mapper) {
1206712034
Objects.requireNonNull(mapper, "mapper is null");
1206812035
return RxJavaPlugins.onAssembly(new FlowableMap<>(this, mapper));
@@ -20896,7 +20863,7 @@ public final Stream<T> blockingStream(int prefetch) {
2089620863
ObjectHelper.verifyPositive(prefetch, "prefetch");
2089720864
return RxJavaPlugins.onAssembly(new FlowableFlatMapStream<>(this, mapper, prefetch));
2089820865
}
20899-
20866+
2090020867
/**
2090120868
* Construct a {@code Flowable} and use the given {@code generator}
2090220869
* to generate items on demand while running on the given {@link ExecutorService}.
@@ -20948,7 +20915,7 @@ public final Stream<T> blockingStream(int prefetch) {
2094820915
}
2094920916

2095020917
/**
20951-
* Returns a {@code Flowable} that turns an upstream item an upstream item into
20918+
* Returns a {@code Flowable} that turns an upstream item an upstream item into
2095220919
* zero or more downstream values by running on the given {@link ExecutorService}.
2095320920
* <p>
2095420921
* <dl>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
package io.reactivex.rxjava4.core.docs;
14+
15+
import io.reactivex.rxjava4.annotations.*;
16+
import io.reactivex.rxjava4.core.*;
17+
import io.reactivex.rxjava4.functions.*;
18+
19+
/**
20+
* Documents a set of operators so that the main Flowable source file is not cluttered.
21+
* @param <T> the element type of the flow
22+
*/
23+
public sealed interface FlowableDocBasic<T> permits Flowable {
24+
/**
25+
* Returns a {@code Flowable} that applies a specified function to each item emitted by the current {@code Flowable} and
26+
* emits the results of these function applications.
27+
* <p>
28+
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/map.v3.png" alt="">
29+
* <dl>
30+
* <dt><b>Backpressure:</b></dt>
31+
* <dd>The operator doesn't interfere with backpressure which is determined by the current {@code Flowable}'s backpressure
32+
* behavior.</dd>
33+
* <dt><b>Scheduler:</b></dt>
34+
* <dd>{@code map} does not operate by default on a particular {@link Scheduler}.</dd>
35+
* </dl>
36+
*
37+
* @param <R> the output type
38+
* @param mapper
39+
* a function to apply to each item emitted by the current {@code Flowable}
40+
* @return the new {@code Flowable} instance
41+
* @throws NullPointerException if {@code mapper} is {@code null}
42+
* @see <a href="http://reactivex.io/documentation/operators/map.html">ReactiveX operators documentation: Map</a>
43+
* @see #mapOptional(Function)
44+
*/
45+
@CheckReturnValue
46+
@NonNull
47+
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
48+
@SchedulerSupport(SchedulerSupport.NONE)
49+
<@NonNull R> Flowable<R> map(@NonNull Function<? super T, ? extends R> mapper);
50+
51+
/**
52+
* Filters items emitted by the current {@code Flowable} by only emitting those that satisfy a specified predicate.
53+
* <p>
54+
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/filter.v3.png" alt="">
55+
* <dl>
56+
* <dt><b>Backpressure:</b></dt>
57+
* <dd>The operator doesn't interfere with backpressure which is determined by the current {@code Flowable}'s backpressure
58+
* behavior.</dd>
59+
* <dt><b>Scheduler:</b></dt>
60+
* <dd>{@code filter} does not operate by default on a particular {@link Scheduler}.</dd>
61+
* </dl>
62+
*
63+
* @param predicate
64+
* a function that evaluates each item emitted by the current {@code Flowable}, returning {@code true}
65+
* if it passes the filter
66+
* @return the new {@code Flowable} instance
67+
* @throws NullPointerException if {@code predicate} is {@code null}
68+
* @see <a href="http://reactivex.io/documentation/operators/filter.html">ReactiveX operators documentation: Filter</a>
69+
*/
70+
@CheckReturnValue
71+
@NonNull
72+
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
73+
@SchedulerSupport(SchedulerSupport.NONE)
74+
Flowable<T> filter(@NonNull Predicate<? super T> predicate);
75+
76+
}

src/main/java/io/reactivex/rxjava4/internal/virtual/FlowableVirtualCreateExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected void subscribeActual(Subscriber<? super T> s) {
4848
executor.submit(parent);
4949
}
5050

51-
static final class ExecutorVirtualCreateSubscription<T> extends AtomicLong
51+
static final class ExecutorVirtualCreateSubscription<T> extends AtomicLong
5252
implements Subscription, Callable<Void>, VirtualEmitter<T> {
5353

5454
private static final long serialVersionUID = -6959205135542203083L;

src/main/java/io/reactivex/rxjava4/plugins/RxJavaPlugins.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import java.lang.Thread.UncaughtExceptionHandler;
1717
import java.util.Objects;
1818
import java.util.concurrent.*;
19-
20-
import static java.util.concurrent.Flow.*;
19+
import java.util.concurrent.Flow.Subscriber;
2120

2221
import io.reactivex.rxjava4.annotations.*;
2322
import io.reactivex.rxjava4.core.*;
@@ -115,7 +114,7 @@ public final class RxJavaPlugins {
115114

116115
@SuppressWarnings("rawtypes")
117116
@Nullable
118-
static volatile BiFunction<? super ParallelFlowable, @NonNull ? super Subscriber[], @NonNull ? extends Subscriber[]> onParallelSubscribe;
117+
static volatile BiFunction<? super ParallelFlowable, @NonNull ? super Subscriber<@NonNull ?>[], @NonNull ? extends Subscriber<@NonNull ?>[]> onParallelSubscribe;
119118

120119
@Nullable
121120
static volatile BooleanSupplier onBeforeBlocking;
@@ -1008,12 +1007,12 @@ public static CompletableObserver onSubscribe(@NonNull Completable source, @NonN
10081007
* @param subscribers the array of subscribers
10091008
* @return the value returned by the hook
10101009
*/
1011-
@SuppressWarnings({ "rawtypes" })
1010+
@SuppressWarnings({ "unchecked" })
10121011
@NonNull
1013-
public static <@NonNull T> Subscriber<? super T>[] onSubscribe(@NonNull ParallelFlowable<T> source, @NonNull Subscriber<? super T>[] subscribers) {
1014-
BiFunction<? super ParallelFlowable, @NonNull ? super Subscriber[], @NonNull ? extends Subscriber[]> f = onParallelSubscribe;
1012+
public static <@NonNull T> Subscriber<? super T>[] onSubscribe(@NonNull ParallelFlowable<? extends T> source, @NonNull Subscriber<? super T>[] subscribers) {
1013+
var f = onParallelSubscribe;
10151014
if (f != null) {
1016-
return apply(f, source, subscribers);
1015+
return (@NonNull Subscriber<@NonNull ? super @NonNull T>[]) apply(f, source, subscribers);
10171016
}
10181017
return subscribers;
10191018
}
@@ -1161,7 +1160,7 @@ public static void setOnParallelAssembly(@Nullable Function<? super ParallelFlow
11611160
* @since 3.1.0
11621161
*/
11631162
@SuppressWarnings("rawtypes")
1164-
public static void setOnParallelSubscribe(@Nullable BiFunction<? super ParallelFlowable, @NonNull ? super Subscriber[], @NonNull ? extends Subscriber[]> handler) {
1163+
public static void setOnParallelSubscribe(@Nullable BiFunction<? super ParallelFlowable, @NonNull ? super Subscriber<@NonNull ?>[], @NonNull ? extends Subscriber<@NonNull ?>[]> handler) {
11651164
if (lockdown) {
11661165
throw new IllegalStateException("Plugins can't be changed anymore");
11671166
}
@@ -1176,7 +1175,7 @@ public static void setOnParallelSubscribe(@Nullable BiFunction<? super ParallelF
11761175
*/
11771176
@SuppressWarnings("rawtypes")
11781177
@Nullable
1179-
public static BiFunction<? super ParallelFlowable, @NonNull ? super Subscriber[], @NonNull ? extends Subscriber[]> getOnParallelSubscribe() {
1178+
public static BiFunction<? super ParallelFlowable, @NonNull ? super Subscriber<@NonNull ?>[], @NonNull ? extends Subscriber<@NonNull ?>[]> getOnParallelSubscribe() {
11801179
return onParallelSubscribe;
11811180
}
11821181

@@ -1355,7 +1354,7 @@ public static Scheduler createExecutorScheduler(@NonNull Executor executor, bool
13551354
* @return the result of the function call
13561355
*/
13571356
@NonNull
1358-
static <@NonNull T, @NonNull U, @NonNull R> R apply(@NonNull BiFunction<T, U, R> f, @NonNull T t, @NonNull U u) {
1357+
static <@NonNull T, @NonNull U, @NonNull R> R apply(@NonNull BiFunction<? super T, ? super U, ? extends R> f, @NonNull T t, @NonNull U u) {
13591358
try {
13601359
return f.apply(t, u);
13611360
} catch (Throwable ex) {

src/test/java/io/reactivex/rxjava4/plugins/RxJavaPluginsTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,12 @@ public void onComplete() {
589589
.assertComplete();
590590
}
591591

592-
@SuppressWarnings("rawtypes")
593592
@Test
594593
public void parallelFlowableStart() {
595594
try {
596-
RxJavaPlugins.setOnParallelSubscribe(new BiFunction<ParallelFlowable, Subscriber[], Subscriber[]>() {
597-
@Override
598-
public Subscriber[] apply(ParallelFlowable f, final Subscriber[] t) {
599-
return new Subscriber[] { new Subscriber() {
595+
RxJavaPlugins.setOnParallelSubscribe((_, t) -> {
596+
var result = new Subscriber<?>[] {
597+
new Subscriber<Object>() {
600598

601599
@Override
602600
public void onSubscribe(Subscription s) {
@@ -606,7 +604,7 @@ public void onSubscribe(Subscription s) {
606604
@SuppressWarnings("unchecked")
607605
@Override
608606
public void onNext(Object value) {
609-
t[0].onNext((Integer)value - 9);
607+
((Subscriber<Integer>)t[0]).onNext(((Integer)value - 9));
610608
}
611609

612610
@Override
@@ -621,8 +619,9 @@ public void onComplete() {
621619

622620
}
623621
};
622+
return result;
624623
}
625-
});
624+
);
626625

627626
Flowable.range(10, 3)
628627
.parallel(1)

src/test/java/io/reactivex/rxjava4/tck/BaseTck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public static void before() {
6262
@AfterClass
6363
public static void after() {
6464
service.shutdown();
65-
}
66-
65+
}
66+
6767
/**
6868
* Creates an Iterable with the specified number of elements or an infinite one if
6969
* {@code elements >} {@link Integer#MAX_VALUE}.

0 commit comments

Comments
 (0)