Debian Codegraph @

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

raw
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.rxjava3.validators;
15
16 import static org.junit.Assert.*;
17
18 import java.util.List;
19 import java.util.regex.Pattern;
20
21 import org.junit.Test;
22
23 import io.reactivex.rxjava3.testsupport.TestHelper;
24 import io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod;
25
26 /**
27 * Check if the method wording is consistent with the target base type.
28 */
29 public class JavadocWording {
30
31 public static int lineNumber(CharSequence s, int index) {
32 int cnt = 1;
33 for (int i = 0; i < index; i++) {
34 if (s.charAt(i) == '\n') {
35 cnt++;
36 }
37 }
38 return cnt;
39 }
40
41 @Test
42 public void maybeDocRefersToMaybeTypes() throws Exception {
43 List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Maybe"), "Maybe");
44
45 assertFalse(list.isEmpty());
46
47 StringBuilder e = new StringBuilder();
48
49 for (RxMethod m : list) {
50 int jdx;
51 if (m.javadoc != null) {
52 jdx = 0;
53 for (;;) {
54 int idx = m.javadoc.indexOf("onNext", jdx);
55 if (idx >= 0) {
56 if (!m.signature.contains("Publisher")
57 && !m.signature.contains("Flowable")
58 && !m.signature.contains("Observable")
59 && !m.signature.contains("ObservableSource")) {
60 e.append("java.lang.RuntimeException: Maybe doc mentions onNext but no Flowable/Observable in signature\r\n at io.reactivex.rxjava3.core.")
61 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
62 }
63
64 jdx = idx + 6;
65 } else {
66 break;
67 }
68 }
69 jdx = 0;
70 for (;;) {
71 int idx = m.javadoc.indexOf("Subscriber", jdx);
72 if (idx >= 0) {
73 if (!m.signature.contains("Publisher")
74 && !m.signature.contains("Flowable")
75 && !m.signature.contains("TestSubscriber")
76 ) {
77 e.append("java.lang.RuntimeException: Maybe doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.")
78 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
79 }
80
81 jdx = idx + 6;
82 } else {
83 break;
84 }
85 }
86 jdx = 0;
87 for (;;) {
88 int idx = m.javadoc.indexOf(" Subscription", jdx);
89 if (idx >= 0) {
90 if (!m.signature.contains("Publisher")
91 && !m.signature.contains("Flowable")
92 ) {
93 e.append("java.lang.RuntimeException: Maybe doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.")
94 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
95 }
96
97 jdx = idx + 6;
98 } else {
99 break;
100 }
101 }
102 jdx = 0;
103 for (;;) {
104 int idx = m.javadoc.indexOf("Observer", jdx);
105 if (idx >= 0) {
106 if (!m.signature.contains("ObservableSource")
107 && !m.signature.contains("Observable")
108 && !m.signature.contains("TestObserver")) {
109
110 if (idx < 5 || !m.javadoc.substring(idx - 5, idx + 8).equals("MaybeObserver")) {
111 e.append("java.lang.RuntimeException: Maybe doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.")
112 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
113 }
114 }
115
116 jdx = idx + 6;
117 } else {
118 break;
119 }
120 }
121 jdx = 0;
122 for (;;) {
123 int idx = m.javadoc.indexOf("Publisher", jdx);
124 if (idx >= 0) {
125 if (!m.signature.contains("Publisher")) {
126 if (idx == 0 || !m.javadoc.substring(idx - 1, idx + 9).equals("(Publisher")) {
127 e.append("java.lang.RuntimeException: Maybe doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.")
128 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
129 }
130 }
131
132 jdx = idx + 6;
133 } else {
134 break;
135 }
136 }
137 jdx = 0;
138 for (;;) {
139 int idx = m.javadoc.indexOf("Flowable", jdx);
140 if (idx >= 0) {
141 if (!m.signature.contains("Flowable")) {
142 Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Flowable");
143 if (!p.matcher(m.javadoc).find()) {
144 e.append("java.lang.RuntimeException: Maybe doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.")
145 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
146 }
147 }
148 jdx = idx + 6;
149 } else {
150 break;
151 }
152 }
153 jdx = 0;
154 for (;;) {
155 int idx = m.javadoc.indexOf("Single", jdx);
156 if (idx >= 0 && m.javadoc.indexOf("Single#", jdx) != idx) {
157 int j = m.javadoc.indexOf("#toSingle", jdx);
158 int k = m.javadoc.indexOf("{@code Single", jdx);
159 if (!m.signature.contains("Single") && (j + 3 != idx && k + 7 != idx)) {
160 e.append("java.lang.RuntimeException: Maybe doc mentions Single but not in the signature\r\n at io.reactivex.rxjava3.core.")
161 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
162 }
163 jdx = idx + 6;
164 } else {
165 break;
166 }
167 }
168 jdx = 0;
169 for (;;) {
170 int idx = m.javadoc.indexOf("SingleSource", jdx);
171 if (idx >= 0) {
172 if (!m.signature.contains("SingleSource")) {
173 e.append("java.lang.RuntimeException: Maybe doc mentions SingleSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
174 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
175 }
176 jdx = idx + 6;
177 } else {
178 break;
179 }
180 }
181 jdx = 0;
182 for (;;) {
183 int idx = m.javadoc.indexOf("Observable", jdx);
184 if (idx >= 0) {
185 if (!m.signature.contains("Observable")) {
186 Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Observable");
187 if (!p.matcher(m.javadoc).find()) {
188 e.append("java.lang.RuntimeException: Maybe doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.")
189 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
190 }
191 }
192 jdx = idx + 6;
193 } else {
194 break;
195 }
196 }
197 jdx = 0;
198 for (;;) {
199 int idx = m.javadoc.indexOf("ObservableSource", jdx);
200 if (idx >= 0) {
201 if (!m.signature.contains("ObservableSource")) {
202 e.append("java.lang.RuntimeException: Maybe doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
203 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
204 }
205 jdx = idx + 6;
206 } else {
207 break;
208 }
209 }
210
211 checkAtReturnAndSignatureMatch("Maybe", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
212
213 aOrAn(e, m, "Maybe");
214 missingClosingDD(e, m, "Maybe", "io.reactivex.rxjava3.core");
215 backpressureMentionedWithoutAnnotation(e, m, "Maybe");
216 }
217 }
218
219 if (e.length() != 0) {
220 System.out.println(e);
221
222 fail(e.toString());
223 }
224 }
225
226 @Test
227 public void flowableDocRefersToFlowableTypes() throws Exception {
228 List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Flowable"), "Flowable");
229
230 assertFalse(list.isEmpty());
231
232 StringBuilder e = new StringBuilder();
233
234 for (RxMethod m : list) {
235 int jdx;
236 if (m.javadoc != null) {
237 jdx = 0;
238 for (;;) {
239 int idx = m.javadoc.indexOf("onSuccess", jdx);
240 if (idx >= 0) {
241 if (!m.signature.contains("Maybe")
242 && !m.signature.contains("MaybeSource")
243 && !m.signature.contains("Single")
244 && !m.signature.contains("SingleSource")) {
245 e.append("java.lang.RuntimeException: Flowable doc mentions onSuccess\r\n at io.reactivex.rxjava3.core.")
246 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
247 }
248
249 jdx = idx + 6;
250 } else {
251 break;
252 }
253 }
254 jdx = 0;
255 for (;;) {
256 int idx = m.javadoc.indexOf(" Observer", jdx);
257 if (idx >= 0) {
258 if (!m.signature.contains("ObservableSource")
259 && !m.signature.contains("Observable")) {
260 e.append("java.lang.RuntimeException: Flowable doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.")
261 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
262 }
263
264 jdx = idx + 6;
265 } else {
266 break;
267 }
268 }
269 jdx = 0;
270 for (;;) {
271 int idx = m.javadoc.indexOf(" SingleObserver", jdx);
272 if (idx >= 0) {
273 if (!m.signature.contains("SingleSource")
274 && !m.signature.contains("Single")) {
275 e.append("java.lang.RuntimeException: Flowable doc mentions SingleObserver but not using Single\r\n at io.reactivex.rxjava3.core.")
276 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
277 }
278
279 jdx = idx + 6;
280 } else {
281 break;
282 }
283 }
284 jdx = 0;
285 for (;;) {
286 int idx = m.javadoc.indexOf(" MaybeObserver", jdx);
287 if (idx >= 0) {
288 if (!m.signature.contains("MaybeSource")
289 && !m.signature.contains("Maybe")) {
290 e.append("java.lang.RuntimeException: Flowable doc mentions MaybeObserver but not using Maybe\r\n at io.reactivex.rxjava3.core.")
291 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
292 }
293
294 jdx = idx + 6;
295 } else {
296 break;
297 }
298 }
299 jdx = 0;
300 for (;;) {
301 int idx = m.javadoc.indexOf(" Disposable", jdx);
302 if (idx >= 0) {
303 if (!m.signature.contains("Observable")
304 && !m.signature.contains("ObservableSource")
305 && !m.signature.contains("Single")
306 && !m.signature.contains("SingleSource")
307 && !m.signature.contains("Completable")
308 && !m.signature.contains("CompletableSource")
309 && !m.signature.contains("Maybe")
310 && !m.signature.contains("MaybeSource")
311 && !m.signature.contains("Disposable")
312 && !m.signature.contains("void subscribe")
313 ) {
314 CharSequence subSequence = m.javadoc.subSequence(idx - 6, idx + 11);
315 if (idx < 6 || !subSequence.equals("{@link Disposable")) {
316 e.append("java.lang.RuntimeException: Flowable doc mentions Disposable but not using Flowable\r\n at io.reactivex.rxjava3.core.")
317 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
318 }
319 }
320
321 jdx = idx + 6;
322 } else {
323 break;
324 }
325 }
326 jdx = 0;
327 for (;;) {
328 int idx = m.javadoc.indexOf("Observable", jdx);
329 if (idx >= 0) {
330 if (!m.signature.contains("Observable")) {
331 e.append("java.lang.RuntimeException: Flowable doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.")
332 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
333 }
334
335 jdx = idx + 6;
336 } else {
337 break;
338 }
339 }
340 jdx = 0;
341 for (;;) {
342 int idx = m.javadoc.indexOf("ObservableSource", jdx);
343 if (idx >= 0) {
344 if (!m.signature.contains("ObservableSource")) {
345 e.append("java.lang.RuntimeException: Flowable doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
346 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
347 }
348 jdx = idx + 6;
349 } else {
350 break;
351 }
352 }
353
354 checkAtReturnAndSignatureMatch("Flowable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "ConnectableFlowable", "ParallelFlowable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
355
356 aOrAn(e, m, "Flowable");
357 missingClosingDD(e, m, "Flowable", "io.reactivex.rxjava3.core");
358 backpressureMentionedWithoutAnnotation(e, m, "Flowable");
359 }
360 }
361
362 if (e.length() != 0) {
363 System.out.println(e);
364
365 fail(e.toString());
366 }
367 }
368
369 @Test
370 public void parallelFlowableDocRefersToCorrectTypes() throws Exception {
371 List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("ParallelFlowable", "io.reactivex.rxjava3.parallel"), "ParallelFlowable");
372
373 assertFalse(list.isEmpty());
374
375 StringBuilder e = new StringBuilder();
376
377 for (RxMethod m : list) {
378 int jdx;
379 if (m.javadoc != null) {
380 jdx = 0;
381 for (;;) {
382 int idx = m.javadoc.indexOf("onSuccess", jdx);
383 if (idx >= 0) {
384 if (!m.signature.contains("Maybe")
385 && !m.signature.contains("MaybeSource")
386 && !m.signature.contains("Single")
387 && !m.signature.contains("SingleSource")) {
388 e.append("java.lang.RuntimeException: Flowable doc mentions onSuccess\r\n at io.reactivex.rxjava3.core.")
389 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
390 }
391
392 jdx = idx + 6;
393 } else {
394 break;
395 }
396 }
397 jdx = 0;
398 for (;;) {
399 int idx = m.javadoc.indexOf(" Observer", jdx);
400 if (idx >= 0) {
401 if (!m.signature.contains("ObservableSource")
402 && !m.signature.contains("Observable")) {
403 e.append("java.lang.RuntimeException: Flowable doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.")
404 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
405 }
406
407 jdx = idx + 6;
408 } else {
409 break;
410 }
411 }
412 jdx = 0;
413 for (;;) {
414 int idx = m.javadoc.indexOf(" SingleObserver", jdx);
415 if (idx >= 0) {
416 if (!m.signature.contains("SingleSource")
417 && !m.signature.contains("Single")) {
418 e.append("java.lang.RuntimeException: Flowable doc mentions SingleObserver but not using Single\r\n at io.reactivex.rxjava3.core.")
419 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
420 }
421
422 jdx = idx + 6;
423 } else {
424 break;
425 }
426 }
427 jdx = 0;
428 for (;;) {
429 int idx = m.javadoc.indexOf(" MaybeObserver", jdx);
430 if (idx >= 0) {
431 if (!m.signature.contains("MaybeSource")
432 && !m.signature.contains("Maybe")) {
433 e.append("java.lang.RuntimeException: Flowable doc mentions MaybeObserver but not using Maybe\r\n at io.reactivex.rxjava3.core.")
434 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
435 }
436
437 jdx = idx + 6;
438 } else {
439 break;
440 }
441 }
442 jdx = 0;
443 for (;;) {
444 int idx = m.javadoc.indexOf(" Disposable", jdx);
445 if (idx >= 0) {
446 if (!m.signature.contains("Observable")
447 && !m.signature.contains("ObservableSource")
448 && !m.signature.contains("Single")
449 && !m.signature.contains("SingleSource")
450 && !m.signature.contains("Completable")
451 && !m.signature.contains("CompletableSource")
452 && !m.signature.contains("Maybe")
453 && !m.signature.contains("MaybeSource")
454 && !m.signature.contains("Disposable")
455 ) {
456 CharSequence subSequence = m.javadoc.subSequence(idx - 6, idx + 11);
457 if (idx < 6 || !subSequence.equals("{@link Disposable")) {
458 e.append("java.lang.RuntimeException: Flowable doc mentions Disposable but not using Flowable\r\n at io.reactivex.rxjava3.core.")
459 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
460 }
461 }
462
463 jdx = idx + 6;
464 } else {
465 break;
466 }
467 }
468 jdx = 0;
469 for (;;) {
470 int idx = m.javadoc.indexOf("Observable", jdx);
471 if (idx >= 0) {
472 if (!m.signature.contains("Observable")) {
473 e.append("java.lang.RuntimeException: Flowable doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.")
474 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
475 }
476
477 jdx = idx + 6;
478 } else {
479 break;
480 }
481 }
482 jdx = 0;
483 for (;;) {
484 int idx = m.javadoc.indexOf("ObservableSource", jdx);
485 if (idx >= 0) {
486 if (!m.signature.contains("ObservableSource")) {
487 e.append("java.lang.RuntimeException: Flowable doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
488 .append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
489 }
490 jdx = idx + 6;
491 } else {
492 break;
493 }
494 }
495
496 checkAtReturnAndSignatureMatch("ParallelFlowable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "ConnectableFlowable", "ParallelFlowable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
497
498 aOrAn(e, m, "ParallelFlowable");
499 missingClosingDD(e, m, "ParallelFlowable", "io.reactivex.rxjava3.parallel");
500 backpressureMentionedWithoutAnnotation(e, m, "ParallelFlowable");
501 }
502 }
503
504 if (e.length() != 0) {
505 System.out.println(e);
506
507 fail(e.toString());
508 }
509 }
510
511 @Test
512 public void observableDocRefersToObservableTypes() throws Exception {
513 List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Observable"), "Observable");
514
515 assertFalse(list.isEmpty());
516
517 StringBuilder e = new StringBuilder();
518
519 for (RxMethod m : list) {
520 int jdx;
521 if (m.javadoc != null) {
522 jdx = 0;
523 for (;;) {
524 int idx = m.javadoc.indexOf("onSuccess", jdx);
525 if (idx >= 0) {
526 if (!m.signature.contains("Maybe")
527 && !m.signature.contains("MaybeSource")
528 && !m.signature.contains("Single")
529 && !m.signature.contains("SingleSource")) {
530 e.append("java.lang.RuntimeException: Observable doc mentions onSuccess\r\n at io.reactivex.rxjava3.core.")
531 .append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
532 }
533
534 jdx = idx + 6;
535 } else {
536 break;
537 }
538 }
539 jdx = 0;
540 for (;;) {
541 int idx = m.javadoc.indexOf(" Subscription", jdx);
542 if (idx >= 0) {
543 if (!m.signature.contains("Flowable")
544 && !m.signature.contains("Publisher")
545 ) {
546 e.append("java.lang.RuntimeException: Observable doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.")
547 .append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
548 }
549
550 jdx = idx + 6;
551 } else {
552 break;
553 }
554 }
555 jdx = 0;
556 for (;;) {
557 int idx = m.javadoc.indexOf("Flowable", jdx);
558 if (idx >= 0) {
559 if (!m.signature.contains("Flowable")) {
560 if (idx < 6 || !m.javadoc.substring(idx - 6, idx + 8).equals("@link Flowable")) {
561 e.append("java.lang.RuntimeException: Observable doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.")
562 .append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
563 }
564 }
565
566 jdx = idx + 6;
567 } else {
568 break;
569 }
570 }
571 jdx = 0;
572 for (;;) {
573 int idx = m.javadoc.indexOf("Publisher", jdx);
574 if (idx >= 0) {
575 if (!m.signature.contains("Publisher")) {
576 e.append("java.lang.RuntimeException: Observable doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.")
577 .append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
578 }
579 jdx = idx + 6;
580 } else {
581 break;
582 }
583 }
584 jdx = 0;
585 for (;;) {
586 int idx = m.javadoc.indexOf("Subscriber", jdx);
587 if (idx >= 0) {
588 if (!m.signature.contains("Publisher")
589 && !m.signature.contains("Flowable")) {
590 e.append("java.lang.RuntimeException: Observable doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.")
591 .append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
592 }
593
594 jdx = idx + 6;
595 } else {
596 break;
597 }
598 }
599 checkAtReturnAndSignatureMatch("Observable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "ConnectableObservable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
600
601 aOrAn(e, m, "Observable");
602 missingClosingDD(e, m, "Observable", "io.reactivex.rxjava3.core");
603 backpressureMentionedWithoutAnnotation(e, m, "Observable");
604 }
605 }
606
607 if (e.length() != 0) {
608 System.out.println(e);
609
610 fail(e.toString());
611 }
612 }
613
614 @Test
615 public void singleDocRefersToSingleTypes() throws Exception {
616 List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Single"), "Single");
617
618 assertFalse(list.isEmpty());
619
620 StringBuilder e = new StringBuilder();
621
622 for (RxMethod m : list) {
623 int jdx;
624 if (m.javadoc != null) {
625 jdx = 0;
626 for (;;) {
627 int idx = m.javadoc.indexOf("onNext", jdx);
628 if (idx >= 0) {
629 if (!m.signature.contains("Publisher")
630 && !m.signature.contains("Flowable")
631 && !m.signature.contains("Observable")
632 && !m.signature.contains("ObservableSource")) {
633 e.append("java.lang.RuntimeException: Single doc mentions onNext but no Flowable/Observable in signature\r\n at io.reactivex.rxjava3.core.")
634 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
635 }
636
637 jdx = idx + 6;
638 } else {
639 break;
640 }
641 }
642 jdx = 0;
643 for (;;) {
644 int idx = m.javadoc.indexOf("Subscriber", jdx);
645 if (idx >= 0) {
646 if (!m.signature.contains("Publisher")
647 && !m.signature.contains("Flowable")
648 && !m.signature.contains("TestSubscriber")) {
649 e.append("java.lang.RuntimeException: Single doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.")
650 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
651 }
652
653 jdx = idx + 6;
654 } else {
655 break;
656 }
657 }
658 jdx = 0;
659 for (;;) {
660 int idx = m.javadoc.indexOf(" Subscription", jdx);
661 if (idx >= 0) {
662 if (!m.signature.contains("Flowable")
663 && !m.signature.contains("Publisher")
664 ) {
665 e.append("java.lang.RuntimeException: Single doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.")
666 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
667 }
668
669 jdx = idx + 6;
670 } else {
671 break;
672 }
673 }
674 jdx = 0;
675 for (;;) {
676 int idx = m.javadoc.indexOf("Observer", jdx);
677 if (idx >= 0) {
678 if (!m.signature.contains("ObservableSource")
679 && !m.signature.contains("Observable")
680 && !m.signature.contains("TestObserver")) {
681
682 if (idx < 6 || !m.javadoc.substring(idx - 6, idx + 8).equals("SingleObserver")) {
683 e.append("java.lang.RuntimeException: Single doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.")
684 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
685 }
686 }
687
688 jdx = idx + 6;
689 } else {
690 break;
691 }
692 }
693 jdx = 0;
694 for (;;) {
695 int idx = m.javadoc.indexOf("Publisher", jdx);
696 if (idx >= 0) {
697 if (!m.signature.contains("Publisher")) {
698 if (idx == 0 || !m.javadoc.substring(idx - 1, idx + 9).equals("(Publisher")) {
699 e.append("java.lang.RuntimeException: Single doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.")
700 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
701 }
702 }
703
704 jdx = idx + 6;
705 } else {
706 break;
707 }
708 }
709 jdx = 0;
710 for (;;) {
711 int idx = m.javadoc.indexOf(" Flowable", jdx);
712 if (idx >= 0) {
713 if (!m.signature.contains("Flowable")) {
714 e.append("java.lang.RuntimeException: Single doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.")
715 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
716 }
717 jdx = idx + 6;
718 } else {
719 break;
720 }
721 }
722 jdx = 0;
723 for (;;) {
724 int idx = m.javadoc.indexOf(" Maybe", jdx);
725 if (idx >= 0) {
726 if (!m.signature.contains("Maybe")) {
727 e.append("java.lang.RuntimeException: Single doc mentions Maybe but not in the signature\r\n at io.reactivex.rxjava3.core.")
728 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
729 }
730 jdx = idx + 6;
731 } else {
732 break;
733 }
734 }
735 jdx = 0;
736 for (;;) {
737 int idx = m.javadoc.indexOf(" MaybeSource", jdx);
738 if (idx >= 0) {
739 if (!m.signature.contains("MaybeSource")) {
740 e.append("java.lang.RuntimeException: Single doc mentions SingleSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
741 .append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
742 }
743 jdx = idx + 6;
744 } else {
745 break;
746 }
747 }
748 jdx = 0;
749 for (;;) {
750 int idx = m.javadoc.indexOf(" Observable", jdx);
751 if (idx >= 0) {
752 if (!m.signature.contains("Observable")) {
753 e.append("java.lang.RuntimeException: Single doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.")
754 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
755 }
756 jdx = idx + 6;
757 } else {
758 break;
759 }
760 }
761 jdx = 0;
762 for (;;) {
763 int idx = m.javadoc.indexOf(" ObservableSource", jdx);
764 if (idx >= 0) {
765 if (!m.signature.contains("ObservableSource")) {
766 e.append("java.lang.RuntimeException: Single doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
767 .append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
768 }
769 jdx = idx + 6;
770 } else {
771 break;
772 }
773 }
774
775 checkAtReturnAndSignatureMatch("Single", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
776
777 aOrAn(e, m, "Single");
778 missingClosingDD(e, m, "Single", "io.reactivex.rxjava3.core");
779 backpressureMentionedWithoutAnnotation(e, m, "Single");
780 }
781 }
782
783 if (e.length() != 0) {
784 System.out.println(e);
785
786 fail(e.toString());
787 }
788 }
789
790 @Test
791 public void completableDocRefersToCompletableTypes() throws Exception {
792 List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Completable"), "Completable");
793
794 assertFalse(list.isEmpty());
795
796 StringBuilder e = new StringBuilder();
797
798 for (RxMethod m : list) {
799 int jdx;
800 if (m.javadoc != null) {
801 jdx = 0;
802 for (;;) {
803 int idx = m.javadoc.indexOf("onNext", jdx);
804 if (idx >= 0) {
805 if (!m.signature.contains("Publisher")
806 && !m.signature.contains("Flowable")
807 && !m.signature.contains("Observable")
808 && !m.signature.contains("ObservableSource")) {
809 e.append("java.lang.RuntimeException: Completable doc mentions onNext but no Flowable/Observable in signature\r\n at io.reactivex.rxjava3.core.")
810 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
811 }
812
813 jdx = idx + 6;
814 } else {
815 break;
816 }
817 }
818 jdx = 0;
819 for (;;) {
820 int idx = m.javadoc.indexOf("Subscriber", jdx);
821 if (idx >= 0) {
822 if (!m.signature.contains("Publisher")
823 && !m.signature.contains("Flowable")
824 && !m.signature.contains("TestSubscriber")) {
825 e.append("java.lang.RuntimeException: Completable doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.")
826 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
827 }
828
829 jdx = idx + 6;
830 } else {
831 break;
832 }
833 }
834 jdx = 0;
835 for (;;) {
836 int idx = m.javadoc.indexOf(" Subscription", jdx);
837 if (idx >= 0) {
838 if (!m.signature.contains("Flowable")
839 && !m.signature.contains("Publisher")
840 ) {
841 e.append("java.lang.RuntimeException: Completable doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.")
842 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
843 }
844
845 jdx = idx + 6;
846 } else {
847 break;
848 }
849 }
850 jdx = 0;
851 for (;;) {
852 int idx = m.javadoc.indexOf("Observer", jdx);
853 if (idx >= 0) {
854 if (!m.signature.contains("ObservableSource")
855 && !m.signature.contains("Observable")
856 && !m.signature.contains("TestObserver")) {
857
858 if (idx < 11 || !m.javadoc.substring(idx - 11, idx + 8).equals("CompletableObserver")) {
859 e.append("java.lang.RuntimeException: Completable doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.")
860 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
861 }
862 }
863
864 jdx = idx + 6;
865 } else {
866 break;
867 }
868 }
869 jdx = 0;
870 for (;;) {
871 int idx = m.javadoc.indexOf("Publisher", jdx);
872 if (idx >= 0) {
873 if (!m.signature.contains("Publisher")) {
874 if (idx == 0 || !m.javadoc.substring(idx - 1, idx + 9).equals("(Publisher")) {
875 e.append("java.lang.RuntimeException: Completable doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.")
876 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
877 }
878 }
879
880 jdx = idx + 6;
881 } else {
882 break;
883 }
884 }
885 jdx = 0;
886 for (;;) {
887 int idx = m.javadoc.indexOf("Flowable", jdx);
888 if (idx >= 0) {
889 if (!m.signature.contains("Flowable")) {
890 Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Flowable");
891 if (!p.matcher(m.javadoc).find()) {
892 e.append("java.lang.RuntimeException: Completable doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.")
893 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
894 }
895 }
896 jdx = idx + 6;
897 } else {
898 break;
899 }
900 }
901 jdx = 0;
902 for (;;) {
903 int idx = m.javadoc.indexOf("Single", jdx);
904 if (idx >= 0) {
905 if (!m.signature.contains("Single")) {
906 Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Single");
907 if (!p.matcher(m.javadoc).find()) {
908 e.append("java.lang.RuntimeException: Completable doc mentions Single but not in the signature\r\n at io.reactivex.rxjava3.core.")
909 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
910 }
911 }
912 jdx = idx + 6;
913 } else {
914 break;
915 }
916 }
917 jdx = 0;
918 for (;;) {
919 int idx = m.javadoc.indexOf("SingleSource", jdx);
920 if (idx >= 0) {
921 if (!m.signature.contains("SingleSource")) {
922 Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*SingleSource");
923 if (!p.matcher(m.javadoc).find()) {
924 e.append("java.lang.RuntimeException: Completable doc mentions SingleSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
925 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
926 }
927 }
928 jdx = idx + 6;
929 } else {
930 break;
931 }
932 }
933 jdx = 0;
934 for (;;) {
935 int idx = m.javadoc.indexOf(" Observable", jdx);
936 if (idx >= 0) {
937 if (!m.signature.contains("Observable")) {
938 Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Observable");
939 if (!p.matcher(m.javadoc).find()) {
940 e.append("java.lang.RuntimeException: Completable doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.")
941 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
942 }
943 }
944 jdx = idx + 6;
945 } else {
946 break;
947 }
948 }
949 jdx = 0;
950 for (;;) {
951 int idx = m.javadoc.indexOf("ObservableSource", jdx);
952 if (idx >= 0) {
953 if (!m.signature.contains("ObservableSource")) {
954 Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*ObservableSource");
955 if (!p.matcher(m.javadoc).find()) {
956 e.append("java.lang.RuntimeException: Completable doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.")
957 .append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
958 }
959 }
960 jdx = idx + 6;
961 } else {
962 break;
963 }
964 }
965
966 checkAtReturnAndSignatureMatch("Completable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
967
968 aOrAn(e, m, "Completable");
969 missingClosingDD(e, m, "Completable", "io.reactivex.rxjava3.core");
970 backpressureMentionedWithoutAnnotation(e, m, "Completable");
971 }
972 }
973
974 if (e.length() != 0) {
975 System.out.println(e);
976
977 fail(e.toString());
978 }
979 }
980
981 static void checkAtReturnAndSignatureMatch(String className, RxMethod m, StringBuilder e, String... types) {
982 for (String t : types) {
983 String regex;
984 if (t.contains("Completable")) {
985 regex = "(?s).*?\\s" + t + "\\s+\\w+\\(.*";
986 } else {
987 regex = "(?s).*?\\s" + t + "\\<.*?\\>\\s+\\w+\\(.*";
988 }
989 if (m.signature.matches(regex)) {
990 for (String at : AT_RETURN_WORDS) {
991 for (String u : types) {
992 if (!t.equals(u)) {
993 int idx = m.javadoc.indexOf(at + "{@code " + u);
994 if (idx >= 0) {
995 e.append("Returns ").append(t)
996 .append(" but docs return ")
997 .append(u)
998 .append("\r\n at io.reactivex.rxjava3.core.")
999 .append(className)
1000 .append(".method(")
1001 .append(className)
1002 .append(".java:")
1003 .append(m.javadocLine + lineNumber(m.javadoc, idx) - 1)
1004 .append(")\r\n\r\n");
1005 }
1006 }
1007 }
1008 }
1009 }
1010 }
1011 }
1012
1013 static void aOrAn(StringBuilder e, RxMethod m, String baseTypeName) {
1014 aOrAn(e, m, " an", "Single", baseTypeName);
1015 aOrAn(e, m, " an", "Maybe", baseTypeName);
1016 aOrAn(e, m, " a", "Observer", baseTypeName);
1017 aOrAn(e, m, " a", "Observable", baseTypeName);
1018 aOrAn(e, m, " an", "Publisher", baseTypeName);
1019 aOrAn(e, m, " an", "Subscriber", baseTypeName);
1020 aOrAn(e, m, " an", "Flowable", baseTypeName);
1021
1022 aOrAn(e, m, " a", "Observable", baseTypeName);
1023
1024 }
1025
1026 static void aOrAn(StringBuilder e, RxMethod m, String wrongPre, String word, String baseTypeName) {
1027 int jdx = 0;
1028 int idx;
1029 for (;;) {
1030 idx = m.javadoc.indexOf(wrongPre + " " + word, jdx);
1031 if (idx >= 0) {
1032 e.append("java.lang.RuntimeException: a/an typo ")
1033 .append(word)
1034 .append("\r\n at io.reactivex.rxjava3.core.")
1035 .append(baseTypeName)
1036 .append(".method(")
1037 .append(baseTypeName)
1038 .append(".java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
1039 jdx = idx + 6;
1040 } else {
1041 break;
1042 }
1043 }
1044
1045 jdx = 0;
1046 for (;;) {
1047 idx = m.javadoc.indexOf(wrongPre + " {@link " + word, jdx);
1048 if (idx >= 0) {
1049 e.append("java.lang.RuntimeException: a/an typo ")
1050 .append(word)
1051 .append("\r\n at io.reactivex.rxjava3.core.")
1052 .append(baseTypeName)
1053 .append(".method(")
1054 .append(baseTypeName)
1055 .append(".java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
1056 jdx = idx + 6;
1057 } else {
1058 break;
1059 }
1060 }
1061
1062 jdx = 0;
1063 for (;;) {
1064 idx = m.javadoc.indexOf(wrongPre + " {@linkplain " + word, jdx);
1065 if (idx >= 0) {
1066 e.append("java.lang.RuntimeException: a/an typo ")
1067 .append(word)
1068 .append("\r\n at io.reactivex.rxjava3.core.")
1069 .append(baseTypeName)
1070 .append(".method(")
1071 .append(baseTypeName)
1072 .append(".java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
1073 jdx = idx + 6;
1074 } else {
1075 break;
1076 }
1077 }
1078
1079 jdx = 0;
1080 for (;;) {
1081 idx = m.javadoc.indexOf(wrongPre + " {@code " + word, jdx);
1082 if (idx >= 0) {
1083 e.append("java.lang.RuntimeException: a/an typo ")
1084 .append(word)
1085 .append("\r\n at io.reactivex.rxjava3.core.")
1086 .append(baseTypeName)
1087 .append(".method(")
1088 .append(baseTypeName)
1089 .append(".java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
1090 jdx = idx + 6;
1091 } else {
1092 break;
1093 }
1094 }
1095
1096 // remove linebreaks and multi-spaces
1097 String javadoc2 = m.javadoc.replace("\n", " ").replace("\r", " ")
1098 .replace(" * ", " ")
1099 .replaceAll("\\s+", " ");
1100
1101 // strip {@xxx } tags
1102 int kk = 0;
1103 for (;;) {
1104 int jj = javadoc2.indexOf("{@", kk);
1105 if (jj < 0) {
1106 break;
1107 }
1108 int nn = javadoc2.indexOf(" ", jj + 2);
1109 int mm = javadoc2.indexOf("}", jj + 2);
1110
1111 javadoc2 = javadoc2.substring(0, jj) + javadoc2.substring(nn + 1, mm) + javadoc2.substring(mm + 1);
1112
1113 kk = mm + 1;
1114 }
1115
1116 jdx = 0;
1117 for (;;) {
1118 idx = javadoc2.indexOf(wrongPre + " " + word, jdx);
1119 if (idx >= 0) {
1120 e.append("java.lang.RuntimeException: a/an typo ")
1121 .append(word)
1122 .append("\r\n at io.reactivex.rxjava3.core.")
1123 .append(baseTypeName)
1124 .append(".method(")
1125 .append(baseTypeName)
1126 .append(".java:").append(m.javadocLine).append(")\r\n\r\n");
1127 jdx = idx + wrongPre.length() + 1 + word.length();
1128 } else {
1129 break;
1130 }
1131 }
1132 }
1133
1134 static void missingClosingDD(StringBuilder e, RxMethod m, String baseTypeName, String packageName) {
1135 int jdx = 0;
1136 for (;;) {
1137 int idx1 = m.javadoc.indexOf("<dd>", jdx);
1138 int idx2 = m.javadoc.indexOf("</dd>", jdx);
1139
1140 if (idx1 < 0 && idx2 < 0) {
1141 break;
1142 }
1143
1144 int idx3 = m.javadoc.indexOf("<dd>", idx1 + 4);
1145
1146 if (idx1 > 0 && idx2 > 0 && (idx3 < 0 || (idx2 < idx3 && idx3 > 0))) {
1147 jdx = idx2 + 5;
1148 } else {
1149 e.append("java.lang.RuntimeException: unbalanced <dd></dd> ")
1150 .append("\r\n at ")
1151 .append(packageName)
1152 .append(".")
1153 .append(baseTypeName)
1154 .append(".method(")
1155 .append(baseTypeName)
1156 .append(".java:").append(m.javadocLine + lineNumber(m.javadoc, idx1) - 1).append(")\r\n\r\n");
1157 break;
1158 }
1159 }
1160 }
1161
1162 static void backpressureMentionedWithoutAnnotation(StringBuilder e, RxMethod m, String baseTypeName) {
1163 if (m.backpressureDocLine > 0 && m.backpressureKind == null) {
1164 e.append("java.lang.RuntimeException: backpressure documented but not annotated ")
1165 .append("\r\n at io.reactivex.rxjava3.core.")
1166 .append(baseTypeName)
1167 .append(".method(")
1168 .append(baseTypeName)
1169 .append(".java:").append(m.backpressureDocLine).append(")\r\n\r\n");
1170 }
1171 }
1172
1173 static final String[] AT_RETURN_WORDS = { "@return a ", "@return an ", "@return the new ", "@return a new " };
1174 }