Skip to content

Commit 3148e03

Browse files
committed
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.
1 parent 7bf2a5f commit 3148e03

7 files changed

Lines changed: 117 additions & 51 deletions

File tree

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

Lines changed: 8 additions & 41 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));
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/test/java/io/reactivex/rxjava4/validators/BaseTypeParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public static List<RxMethod> parse(File f, String baseClassName) throws Exceptio
5353
StringBuilder b = JavadocForAnnotations.readFile(f);
5454

5555
int baseIndex = b.indexOf("public abstract class " + baseClassName);
56+
if (baseIndex < 0) {
57+
baseIndex = b.indexOf("public abstract non-sealed class " + baseClassName);
58+
}
5659

5760
if (baseIndex < 0) {
5861
throw new AssertionError("Wrong base class file: " + baseClassName);

src/test/java/io/reactivex/rxjava4/validators/JavadocForAnnotations.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ static final void scanFor(StringBuilder sourceCode, String annotation, String in
9090
int k = sourceCode.indexOf(inDoc, j);
9191

9292
if (k < 0 || k > idx) {
93-
// when printed on the console, IDEs will create a clickable link to help navigate to the offending point
94-
e.append("java.lang.RuntimeException: missing ").append(inDoc).append(" section\r\n")
95-
;
96-
int lc = lineNumber(sourceCode, idx);
97-
98-
e.append(" at io.reactivex.rxjava4.core.").append(baseClassName)
99-
.append(" (").append(baseClassName).append(".java:")
100-
.append(lc).append(")").append("\r\n\r\n");
93+
var subSource = sourceCode.substring(j, idx);
94+
if (!subSource.startsWith("/** {@inheritDoc} */")) {
95+
// when printed on the console, IDEs will create a clickable link to help navigate to the offending point
96+
e.append("java.lang.RuntimeException: missing ").append(inDoc).append(" section\r\n")
97+
;
98+
int lc = lineNumber(sourceCode, idx);
99+
100+
e.append(" at io.reactivex.rxjava4.core.").append(baseClassName)
101+
.append(" (").append(baseClassName).append(".java:")
102+
.append(lc).append(")").append("\r\n\r\n");
103+
}
101104
}
102105
}
103106

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,15 @@ static void aOrAn(StringBuilder e, RxMethod m, String wrongPre, String word, Str
11071107
}
11081108
int nn = javadoc2.indexOf(" ", jj + 2);
11091109
int mm = javadoc2.indexOf("}", jj + 2);
1110+
1111+
if (nn > mm) {
1112+
nn = mm - 1;
1113+
}
11101114

1111-
javadoc2 = javadoc2.substring(0, jj) + javadoc2.substring(nn + 1, mm) + javadoc2.substring(mm + 1);
1115+
var jd2 = javadoc2;
1116+
javadoc2 = jd2.substring(0, jj);
1117+
javadoc2 += jd2.substring(nn + 1, mm);
1118+
javadoc2 += jd2.substring(mm + 1);
11121119

11131120
kk = mm + 1;
11141121
}

src/test/java/io/reactivex/rxjava4/validators/NoAnonymousInnerClassesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class NoAnonymousInnerClassesTest {
2323

2424
@Test
2525
public void verify() throws Exception {
26-
URL u = NoAnonymousInnerClassesTest.class.getResource("/");
26+
URL u = NoAnonymousInnerClassesTest.class.getResource("");
2727
File f = new File(u.toURI());
2828

2929
String fs = f.toString().toLowerCase().replace("\\", "/");

src/test/java/io/reactivex/rxjava4/validators/ParamValidationNaming.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ static void processFile(Class<?> clazz) throws Exception {
249249
boolean found = false;
250250
for (int k = midx - 1; k >= 0; k--) {
251251
String linek = lines.get(k).trim();
252+
if (linek.startsWith("/** {@inheritDoc} */")) {
253+
found = true;
254+
// the docs in in the sealed doc class, skip the check
255+
break;
256+
}
252257
if (linek.startsWith("/**")) {
253258
break;
254259
}
@@ -366,6 +371,11 @@ static void processFile(Class<?> clazz) throws Exception {
366371
boolean found = false;
367372
for (int k = i - 1; k >= 0; k--) {
368373
String linek = lines.get(k).trim();
374+
if (linek.startsWith("/** {@inheritDoc} */")) {
375+
found = true;
376+
break;
377+
// the document is in the sealed doc interface
378+
}
369379
if (linek.startsWith("/**")) {
370380
break;
371381
}

0 commit comments

Comments
 (0)