summaryrefslogtreecommitdiff
path: root/src/com/google/doclava/Doclava.java
blob: a484fbd22b770fabf732463564ce80a550bac0df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
/*
 * Copyright (C) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.doclava;

import static java.util.stream.Collectors.toList;

import com.google.clearsilver.jsilver.JSilver;
import com.google.clearsilver.jsilver.data.Data;
import com.google.clearsilver.jsilver.resourceloader.ClassResourceLoader;
import com.google.clearsilver.jsilver.resourceloader.CompositeResourceLoader;
import com.google.clearsilver.jsilver.resourceloader.FileSystemResourceLoader;
import com.google.clearsilver.jsilver.resourceloader.ResourceLoader;
import com.google.doclava.Errors.ErrorMessage;
import com.google.doclava.Errors.LintBaselineEntry;
import com.google.doclava.javadoc.RootDocImpl;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.Doc;
import com.sun.javadoc.MemberDoc;
import com.sun.javadoc.RootDoc;
import com.sun.javadoc.Type;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.lang.model.SourceVersion;
import jdk.javadoc.doclet.Doclet;
import jdk.javadoc.doclet.DocletEnvironment;
import jdk.javadoc.doclet.Reporter;

public class Doclava implements Doclet {

  private static final String SDK_CONSTANT_ANNOTATION = "android.annotation.SdkConstant";
  private static final String SDK_CONSTANT_TYPE_ACTIVITY_ACTION =
      "android.annotation.SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION";
  private static final String SDK_CONSTANT_TYPE_BROADCAST_ACTION =
      "android.annotation.SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION";
  private static final String SDK_CONSTANT_TYPE_SERVICE_ACTION =
      "android.annotation.SdkConstant.SdkConstantType.SERVICE_ACTION";
  private static final String SDK_CONSTANT_TYPE_CATEGORY =
      "android.annotation.SdkConstant.SdkConstantType.INTENT_CATEGORY";
  private static final String SDK_CONSTANT_TYPE_FEATURE =
      "android.annotation.SdkConstant.SdkConstantType.FEATURE";
  private static final String SDK_WIDGET_ANNOTATION = "android.annotation.Widget";
  private static final String SDK_LAYOUT_ANNOTATION = "android.annotation.Layout";

  private static final int TYPE_NONE = 0;
  private static final int TYPE_WIDGET = 1;
  private static final int TYPE_LAYOUT = 2;
  private static final int TYPE_LAYOUT_PARAM = 3;

  public static final int SHOW_PUBLIC = 0x00000001;
  public static final int SHOW_PROTECTED = 0x00000003;
  public static final int SHOW_PACKAGE = 0x00000007;
  public static final int SHOW_PRIVATE = 0x0000000f;
  public static final int SHOW_HIDDEN = 0x0000001f;

  public static int showLevel = SHOW_PROTECTED;

  public static final boolean SORT_BY_NAV_GROUPS = true;
  /* Debug output for PageMetadata, format urls from site root */
  public static boolean META_DBG=false;
  /* Generate the static html docs with devsite tempating only */
  public static boolean DEVSITE_STATIC_ONLY = false;
  /* Don't resolve @link refs found in devsite pages */
  public static boolean DEVSITE_IGNORE_JDLINKS = false;
  /* Show Preview navigation and process preview docs */
  public static boolean INCLUDE_PREVIEW = false;
  /* output en, es, ja without parent intl/ container */
  public static boolean USE_DEVSITE_LOCALE_OUTPUT_PATHS = false;
  /* generate navtree.js without other docs */
  public static boolean NAVTREE_ONLY = false;
  /* Generate reference navtree.js with all inherited members */
  public static boolean AT_LINKS_NAVTREE = false;
  public static boolean METALAVA_API_SINCE = false;
  public static String outputPathBase = "/";
  public static ArrayList<String> inputPathHtmlDirs = new ArrayList<String>();
  public static ArrayList<String> inputPathHtmlDir2 = new ArrayList<String>();
  public static String inputPathResourcesDir;
  public static String outputPathResourcesDir;
  public static String outputPathHtmlDirs;
  public static String outputPathHtmlDir2;
  /* Javadoc output directory and included in url path */
  public static String javadocDir = "reference/";
  public static String htmlExtension;

  public static RootDoc root;
  public static ArrayList<String[]> mHDFData = new ArrayList<String[]>();
  public static List<PageMetadata.Node> sTaglist = new ArrayList<PageMetadata.Node>();
  public static ArrayList<SampleCode> sampleCodes = new ArrayList<SampleCode>();
  public static ArrayList<SampleCode> sampleCodeGroups = new ArrayList<SampleCode>();
  public static Data samplesNavTree;
  public static Map<Character, String> escapeChars = new HashMap<Character, String>();
  public static String title = "";
  public static SinceTagger sinceTagger = new SinceTagger();
  public static ArtifactTagger artifactTagger = new ArtifactTagger();
  public static HashSet<String> knownTags = new HashSet<String>();
  public static FederationTagger federationTagger = new FederationTagger();
  public static boolean showUnannotated = false;
  public static Set<String> showAnnotations = new HashSet<String>();
  public static Set<String> hideAnnotations = new HashSet<String>();
  public static boolean showAnnotationOverridesVisibility = false;
  public static Set<String> hiddenPackages = new HashSet<String>();
  public static boolean includeAssets = true;
  public static boolean includeDefaultAssets = true;
  private static boolean generateDocs = true;
  private static boolean parseComments = false;
  private static String yamlNavFile = null;
  public static boolean documentAnnotations = false;
  public static String documentAnnotationsPath = null;
  public static Map<String, String> annotationDocumentationMap = null;
  public static boolean referenceOnly = false;
  public static boolean staticOnly = false;
  public static boolean yamlV2 = false; /* whether to build the new version of the yaml file */
  public static boolean devsite = false; /* whether to build docs for devsite */
  public static AuxSource auxSource = new EmptyAuxSource();
  public static Linter linter = new EmptyLinter();
  public static boolean android = false;
  public static String manifestFile = null;
  public static String compatConfig = null;
  public static Map<String, String> manifestPermissions = new HashMap<>();

  public static JSilver jSilver = null;

  //API reference extensions
  private static boolean gmsRef = false;
  private static boolean gcmRef = false;
  public static String libraryRoot = null;
  private static boolean samplesRef = false;
  private static boolean sac = false;

    private static ArrayList<String> knownTagsFiles = new ArrayList<>();
    private static String keepListFile;
    private static String proguardFile;
    private static String proofreadFile;
    private static String todoFile;
    private static String lintBaselineFile;
    private static String stubsDir;
    private static HashSet<String> stubPackages;
    private static HashSet<String> stubImportPackages;
    private static boolean stubSourceOnly;
    private static boolean keepStubComments;
    private static String sdkValuePath;
    private static String apiFile;
    private static String dexApiFile;
    private static String removedApiFile;
    private static String removedDexApiFile;
    private static String exactApiFile;
    private static String privateApiFile;
    private static String privateDexApiFile;
    private static String apiMappingFile;
    private static boolean offlineMode;

    @Override
    public void init(Locale locale, Reporter reporter) {
        keepListFile = null;
        proguardFile = null;
        proofreadFile = null;
        todoFile = null;
        sdkValuePath = null;
        stubsDir = null;
        // Create the dependency graph for the stubs  directory
        offlineMode = false;
        apiFile = null;
        dexApiFile = null;
        removedApiFile = null;
        removedDexApiFile = null;
        exactApiFile = null;
        privateApiFile = null;
        privateDexApiFile = null;
        apiMappingFile = null;
        stubPackages = null;
        stubImportPackages = null;
        stubSourceOnly = false;
        keepStubComments = false;
    }

    @Override
    public String getName() {
        return "Doclava";
    }

    /**
     * @implNote
     * {@code -overview} option used to be a built-in parameter in javadoc
     * tool, and with new Doclet APIs it was moved to
     * {@link jdk.javadoc.doclet.StandardDoclet}, so we have to implement this
     * functionality by ourselves.
     */
    @Override
    public Set<? extends Option> getSupportedOptions() {
        Set<Doclet.Option> options = new HashSet<>();

        options.add(
                new Option() {
                    private final List<String> names = List.of("-overview");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return "Pick overview documentation from HTML file";
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        // TODO(nikitai): implement "overview" file inclusion.
                        //  This used to be built in javadoc tool but in new Doclet APIs it was
                        //  removed from default functionality and moved to StandardDoclet
                        //  implementation. In our case we need to implement this on our own.
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-d");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return "Destination directory for output files";
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<directory>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        outputPathBase = outputPathHtmlDirs = ClearPage.outputDir
                                = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-templatedir");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return "Templates for jSilver template engine used to generate docs";
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<directory>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        ClearPage.addTemplateDir(arguments.get(0));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-hdf");
                    @Override public int          getArgumentCount() { return 2; }
                    @Override public String       getDescription() {
                        return """
                                Doclava uses the jSilver template engine to render docs. This
                                option adds a key-value pair to the global data holder object which
                                is passed to all render calls. Think of it as a list of default
                                parameters for jSilver.""";
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<key> <value>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        mHDFData.add(new String[] { arguments.get(0), arguments.get(1) });
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-knowntags");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return """
                                List of non-standard tags used in sources.
                                Example: ${ANDROID_BUILD_TOP}/libcore/known_oj_tags.txt""";
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        knownTagsFiles.add(arguments.get(0));
                        return true; }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-apidocsdir");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return """
                                Javadoc output directory path relative to root, which is specified \
                                with '-d root'

                                Default value: 'reference/'""";
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<path>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        javadocDir = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-toroot");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return """
                                Relative path to documentation root.
                                If set, use <path> as a (relative or absolute) link to \
                                documentation root in .html pages.

                                If not set, an auto-generated path traversal links will be used, \
                                e.g. “../../../”.
                                """;
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<path>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        ClearPage.toroot = arguments.get(0);
                        return true; }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-samplecode");
                    @Override public int          getArgumentCount() { return 3; }
                    @Override public String       getDescription() {
                        return """
                                Adds a browsable sample code project from <source> directory under \
                                <dest> path relative to root (specified with '-d' <directory>) and \
                                named <title>.
                                """;
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() {
                        return "<source> <dest> <title>";
                    }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        sampleCodes.add(new SampleCode(arguments.get(0), arguments.get(1), arguments.get(2)));
                        samplesRef = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-samplegroup");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return "Add a sample code project group";
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<group>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        sampleCodeGroups.add(new SampleCode(null, null, arguments.get(0)));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-samplesdir");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() {
                        return """
                                Directory where to look for samples. Android uses \
                                ${ANDROID_BUILD_TOP}/development/samples/browseable.
                                """;
                    }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<directory>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        samplesRef = true;
                        getSampleProjects(new File(arguments.get(0)));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-htmldir");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<path>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        inputPathHtmlDirs.add(arguments.get(0));
                        ClearPage.htmlDirs = inputPathHtmlDirs;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-htmldir2");
                    @Override public int          getArgumentCount() { return 2; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() {
                        return "<input_path> <output_path>";
                    }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        if (arguments.get(1).equals("default")) {
                            inputPathHtmlDir2.add(arguments.get(0));
                        } else {
                            inputPathHtmlDir2.add(arguments.get(0));
                            outputPathHtmlDir2 = arguments.get(1);
                        }
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-resourcesdir");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<path>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        inputPathResourcesDir = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-resourcesoutdir");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<path>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        outputPathResourcesDir = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-title");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<title>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        Doclava.title = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-werror");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        Errors.setWarningsAreErrors(true);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-lerror");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        // b/270335653: disable lint warnings as errors until new findings are addressed.
                        // Errors.setLintsAreErrors(true);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-lintbaseline");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return "Allowed lint errors"; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        lintBaselineFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-error");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<code_value>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        try {
                            int level = Integer.parseInt(arguments.get(0));
                            Errors.setErrorLevel(level, Errors.ERROR);
                            return true;
                        } catch (NumberFormatException e) {
                            return false;
                        }
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-warning");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<code_value>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        try {
                            int level = Integer.parseInt(arguments.get(0));
                            Errors.setErrorLevel(level, Errors.WARNING);
                            return true;
                        } catch (NumberFormatException e) {
                            return false;
                        }
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-lint");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<code_value>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        try {
                            int level = Integer.parseInt(arguments.get(0));
                            Errors.setErrorLevel(level, Errors.LINT);
                            return true;
                        } catch (NumberFormatException e) {
                            return false;
                        }
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-hide");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<code_value>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        try {
                            int level = Integer.parseInt(arguments.get(0));
                            Errors.setErrorLevel(level, Errors.HIDDEN);
                            return true;
                        } catch (NumberFormatException e) {
                            return false;
                        }
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-keeplist");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<list>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        keepListFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-showUnannotated");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showUnannotated = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-showAnnotation");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<annotation>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showAnnotations.add(arguments.get(0));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-hideAnnotation");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<annotation>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        hideAnnotations.add(arguments.get(0));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-showAnnotationOverridesVisibility");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showAnnotationOverridesVisibility = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-hidePackage");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<package>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        hiddenPackages.add(arguments.get(0));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-proguard");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<arg>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        proguardFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-proofread");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<arg>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        proofreadFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-todo");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        todoFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-public");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showLevel = SHOW_PUBLIC;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-protected");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showLevel = SHOW_PROTECTED;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-package");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showLevel = SHOW_PACKAGE;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-private");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showLevel = SHOW_PRIVATE;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-hidden");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        showLevel = SHOW_HIDDEN;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-stubs");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<stubs>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        stubsDir = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-stubpackages");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<packages>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        stubPackages = new HashSet<>();
                        stubPackages.addAll(Arrays.asList(arguments.get(0).split(":")));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-stubimportpackages");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<packages>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        stubImportPackages = new HashSet<>();
                        for (String pkg : arguments.get(0).split(":")) {
                            stubImportPackages.add(pkg);
                            hiddenPackages.add(pkg);
                        }
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-stubsourceonly");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        stubSourceOnly = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-keepstubcomments");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        keepStubComments = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-sdkvalues");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<path>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        sdkValuePath = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-api");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        apiFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-dexApi");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        dexApiFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-removedApi");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        removedApiFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-removedDexApi");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        removedDexApiFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-exactApi");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        exactApiFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-privateApi");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        privateApiFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-privateDexApi");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        privateDexApiFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-apiMapping");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        apiMappingFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-nodocs");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        generateDocs = false;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-noassets");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        includeAssets = false;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-nodefaultassets");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        includeDefaultAssets = false;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-parsecomments");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        parseComments = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-metalavaApiSince");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        METALAVA_API_SINCE = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-since");
                    @Override public int          getArgumentCount() { return 2; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<major> <minor>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        sinceTagger.addVersion(arguments.get(0), arguments.get(1));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-artifact");
                    @Override public int          getArgumentCount() { return 2; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<arg1> <arg2>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        artifactTagger.addArtifact(arguments.get(0), arguments.get(1));
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-offlinemode");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        // TODO(nikitai): This option is not used anywhere, consider removing.
                        offlineMode = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-metadataDebug");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        META_DBG = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-includePreview");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        INCLUDE_PREVIEW = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-ignoreJdLinks");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        if (DEVSITE_STATIC_ONLY) {
                            DEVSITE_IGNORE_JDLINKS = true;
                        }
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-federate");
                    @Override public int          getArgumentCount() { return 2; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<name> <URL>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        try {
                            String name = arguments.get(0);
                            URL federationURL = new URL(arguments.get(1));
                            federationTagger.addSiteUrl(name, federationURL);
                        } catch (MalformedURLException e) {
                            System.err.println("Could not parse URL for federation: " + arguments.get(0));
                            return false;
                        }
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-federationapi");
                    @Override public int          getArgumentCount() { return 2; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<name> <file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        String name = arguments.get(0);
                        String file = arguments.get(1);
                        federationTagger.addSiteApi(name, file);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-gmsref");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        gmsRef = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-gcmref");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        gcmRef = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-yaml");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        yamlNavFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-dac_libraryroot");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<library_root>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        libraryRoot = ensureSlash(arguments.get(0));
                        mHDFData.add(new String[] {"library.root", arguments.get(0)});
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-dac_dataname");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<data_name>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        mHDFData.add(new String[] {"dac_dataname", arguments.get(0)});
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-documentannotations");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<path>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        documentAnnotations = true;
                        documentAnnotationsPath = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-referenceonly");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        referenceOnly = true;
                        mHDFData.add(new String[] {"referenceonly", "1"});
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-staticonly");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        staticOnly = true;
                        mHDFData.add(new String[] {"staticonly", "1"});
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-navtreeonly");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        NAVTREE_ONLY = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-atLinksNavtree");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        AT_LINKS_NAVTREE = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-yamlV2");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        yamlV2 = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-devsite");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        devsite = true;
                        // Don't copy any assets to devsite output
                        includeAssets = false;
                        USE_DEVSITE_LOCALE_OUTPUT_PATHS = true;
                        mHDFData.add(new String[] {"devsite", "1"});
                        if (staticOnly) {
                            DEVSITE_STATIC_ONLY = true;
                            System.out.println("  ... Generating static html only for devsite");
                        }
                        if (yamlNavFile == null) {
                            // Use _toc.yaml as default to avoid clobbering possible manual _book.yaml files
                            yamlNavFile = "_toc.yaml";
                        }
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-android");
                    @Override public int          getArgumentCount() { return 0; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return ""; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        auxSource = new AndroidAuxSource();
                        linter = new AndroidLinter();
                        android = true;
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-manifest");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<file>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        manifestFile = arguments.get(0);
                        return true;
                    }
                }
        );

        options.add(
                new Option() {
                    private final List<String> names = List.of("-compatconfig");
                    @Override public int          getArgumentCount() { return 1; }
                    @Override public String       getDescription() { return ""; }
                    @Override public Option.Kind  getKind() { return Option.Kind.STANDARD; }
                    @Override public List<String> getNames() { return names; }
                    @Override public String       getParameters() { return "<config>"; }
                    @Override public boolean      process(String opt, List<String> arguments) {
                        compatConfig = arguments.get(0);
                        return true;
                    }
                }
        );

        return options;
    }

    @Override
    public SourceVersion getSupportedSourceVersion() {
        return SourceVersion.latest();
    }

    @Override
    public boolean run(DocletEnvironment environment) {
        return start(environment);
    }

    public static boolean checkLevel(int level) {
        return (showLevel & level) == level;
    }

  /**
   * Returns true if we should parse javadoc comments,
   * reporting errors in the process.
   */
  public static boolean parseComments() {
    return generateDocs || parseComments;
  }

  public static boolean checkLevel(boolean pub, boolean prot, boolean pkgp, boolean priv,
      boolean hidden) {
    if (hidden && !checkLevel(SHOW_HIDDEN)) {
      return false;
    }
    if (pub && checkLevel(SHOW_PUBLIC)) {
      return true;
    }
    if (prot && checkLevel(SHOW_PROTECTED)) {
      return true;
    }
    if (pkgp && checkLevel(SHOW_PACKAGE)) {
      return true;
    }
    if (priv && checkLevel(SHOW_PRIVATE)) {
      return true;
    }
    return false;
  }

  public static void main(String[] args) {
    throw new UnsupportedOperationException("Not yet implemented");
  }

  public static boolean start(DocletEnvironment environment) {
    root = new RootDocImpl(environment);

    // If the caller has not explicitly requested that unannotated classes and members should be
    // shown in the output then only show them if no annotations were provided.
    if (!showUnannotated && showAnnotations.isEmpty()) {
      showUnannotated = true;
    }

    if (!readKnownTagsFiles(knownTags, knownTagsFiles)) {
      return false;
    }
    if (!readManifest()) {
      return false;
    }
    if (!readLintBaselineFile(lintBaselineFile)) {
      return false;
    }

    // Set up the data structures
    Converter.makeInfo(root);

    if (generateDocs) {
      ClearPage.addBundledTemplateDir("assets/customizations");
      ClearPage.addBundledTemplateDir("assets/templates");

      List<ResourceLoader> resourceLoaders = new ArrayList<ResourceLoader>();
      List<String> templates = ClearPage.getTemplateDirs();
      for (String tmpl : templates) {
        resourceLoaders.add(new FileSystemResourceLoader(tmpl));
      }
      // If no custom template path is provided, and this is a devsite build,
      // then use the bundled templates-sdk/ files by default
      if (templates.isEmpty() && devsite) {
        resourceLoaders.add(new ClassResourceLoader(Doclava.class, "/assets/templates-sdk"));
      }

      templates = ClearPage.getBundledTemplateDirs();
      for (String tmpl : templates) {
          // TODO - remove commented line - it's here for debugging purposes
        //  resourceLoaders.add(new FileSystemResourceLoader("/Volumes/Android/master/external/doclava/res/" + tmpl));
        resourceLoaders.add(new ClassResourceLoader(Doclava.class, '/'+tmpl));
      }

      ResourceLoader compositeResourceLoader = new CompositeResourceLoader(resourceLoaders);
      jSilver = new JSilver(compositeResourceLoader);

      if (!Doclava.readTemplateSettings()) {
        return false;
      }

      // if requested, only generate the navtree for ds use-case
      if (NAVTREE_ONLY) {
        if (AT_LINKS_NAVTREE) {
          AtLinksNavTree.writeAtLinksNavTree(javadocDir);
        } else if (yamlV2) {
          // Generate DAC-formatted left-nav for devsite
          NavTree.writeYamlTree2(javadocDir, yamlNavFile);
        } else {
          // This shouldn't happen; this is the legacy DAC left nav file
          NavTree.writeNavTree(javadocDir, "");
        }
        return true;
      }

      // don't do ref doc tasks in devsite static-only builds
      if (!DEVSITE_STATIC_ONLY) {
        // Load additional data structures from federated sites.
        for(FederatedSite site : federationTagger.getSites()) {
          Converter.addApiInfo(site.apiInfo());
        }

        // Apply @since tags from the XML file
        sinceTagger.tagAll(Converter.rootClasses());

        // Apply @artifact tags from the XML file
        artifactTagger.tagAll(Converter.rootClasses());

        // Apply details of federated documentation
        federationTagger.tagAll(Converter.rootClasses());

        // Files for proofreading
        if (proofreadFile != null) {
          Proofread.initProofread(proofreadFile);
        }
        if (todoFile != null) {
          TodoFile.writeTodoFile(todoFile);
        }

        if (samplesRef) {
          // always write samples without offlineMode behaviors
          writeSamples(false, sampleCodes, SORT_BY_NAV_GROUPS);
        }
      }
      if (!referenceOnly) {
        // HTML2 Pages -- Generate Pages from optional secondary dir
        if (!inputPathHtmlDir2.isEmpty()) {
          if (!outputPathHtmlDir2.isEmpty()) {
            ClearPage.outputDir = outputPathBase + "/" + outputPathHtmlDir2;
          }
          ClearPage.htmlDirs = inputPathHtmlDir2;
          writeHTMLPages();
          ClearPage.htmlDirs = inputPathHtmlDirs;
        }

        // HTML Pages
        if (!ClearPage.htmlDirs.isEmpty()) {
          ClearPage.htmlDirs = inputPathHtmlDirs;
          if (USE_DEVSITE_LOCALE_OUTPUT_PATHS) {
            ClearPage.outputDir = outputPathHtmlDirs + "/en/";
          } else {
            ClearPage.outputDir = outputPathHtmlDirs;
          }
          writeHTMLPages();
        }
      }

      writeResources();

      writeAssets();

      // don't do ref doc tasks in devsite static-only builds
      if (!DEVSITE_STATIC_ONLY) {
        // Navigation tree
        String refPrefix = new String();
        if(gmsRef){
          refPrefix = "gms-";
        } else if(gcmRef){
          refPrefix = "gcm-";
        }

        // Packages Pages
        writePackages(refPrefix + "packages" + htmlExtension);

        // Classes
        writeClassLists();
        writeClasses();
        writeHierarchy();
        writeCompatConfig();
        // writeKeywords();

        // Write yaml tree.
        if (yamlNavFile != null) {
          if (yamlV2) {
            // Generate DAC-formatted left-nav for devsite
            NavTree.writeYamlTree2(javadocDir, yamlNavFile);
          } else {
            // Generate legacy devsite left-nav (shows sub-classes nested under parent class)
            NavTree.writeYamlTree(javadocDir, yamlNavFile);
          }
        } else {
          // This shouldn't happen; this is the legacy DAC left nav file
          NavTree.writeNavTree(javadocDir, refPrefix);
        }

        // Lists for JavaScript
        writeLists();
        if (keepListFile != null) {
          writeKeepList(keepListFile);
        }

        Proofread.finishProofread(proofreadFile);

        if (sdkValuePath != null) {
          writeSdkValues(sdkValuePath);
        }
      }
      // Write metadata for all processed files to jd_lists_unified in out dir
      if (!sTaglist.isEmpty()) {
        PageMetadata.WriteListByLang(sTaglist);
        // For devsite (ds) reference only, write samples_metadata to out dir
        if ((devsite) && (!DEVSITE_STATIC_ONLY)) {
          PageMetadata.WriteSamplesListByLang(sTaglist);
        }
      }
    }

    // Stubs
    if (stubsDir != null || apiFile != null || dexApiFile != null || proguardFile != null
        || removedApiFile != null || removedDexApiFile != null || exactApiFile != null
        || privateApiFile != null || privateDexApiFile != null || apiMappingFile != null) {
      Stubs.writeStubsAndApi(stubsDir, apiFile, dexApiFile, proguardFile, removedApiFile,
          removedDexApiFile, exactApiFile, privateApiFile, privateDexApiFile, apiMappingFile,
          stubPackages, stubImportPackages, stubSourceOnly, keepStubComments);
    }

    Errors.printErrors();

    return !Errors.hadError;
  }

  private static void writeIndex(String dir) {
    Data data = makeHDF();
    ClearPage.write(data, "index.cs", dir + "index" + htmlExtension);
  }

  private static boolean readTemplateSettings() {
    Data data = makeHDF();

    // The .html extension is hard-coded in several .cs files,
    // and so you cannot currently set it as a property.
    htmlExtension = ".html";
    // htmlExtension = data.getValue("template.extension", ".html");
    int i = 0;
    while (true) {
      String k = data.getValue("template.escape." + i + ".key", "");
      String v = data.getValue("template.escape." + i + ".value", "");
      if ("".equals(k)) {
        break;
      }
      if (k.length() != 1) {
        System.err.println("template.escape." + i + ".key must have a length of 1: " + k);
        return false;
      }
      escapeChars.put(k.charAt(0), v);
      i++;
    }
    return true;
  }

    private static boolean readKnownTagsFiles(HashSet<String> knownTags,
            ArrayList<String> knownTagsFiles) {
        for (String fn: knownTagsFiles) {
           BufferedReader in = null;
           try {
               in = new BufferedReader(new FileReader(fn));
               int lineno = 0;
               boolean fail = false;
               while (true) {
                   lineno++;
                   String line = in.readLine();
                   if (line == null) {
                       break;
                   }
                   line = line.trim();
                   if (line.length() == 0) {
                       continue;
                   } else if (line.charAt(0) == '#') {
                       continue;
                   }
                   String[] words = line.split("\\s+", 2);
                   if (words.length == 2) {
                       if (words[1].charAt(0) != '#') {
                           System.err.println(fn + ":" + lineno
                                   + ": Only one tag allowed per line: " + line);
                           fail = true;
                           continue;
                       }
                   }
                   knownTags.add(words[0]);
               }
               if (fail) {
                   return false;
               }
           } catch (IOException ex) {
               System.err.println("Error reading file: " + fn + " (" + ex.getMessage() + ")");
               return false;
           } finally {
               if (in != null) {
                   try {
                       in.close();
                   } catch (IOException e) {
                   }
               }
           }
        }
        return true;
    }

    private static boolean readLintBaselineFile(String lintBaselineFile) {
        if (lintBaselineFile == null) {
          return true;
        }
        try (BufferedReader reader = new BufferedReader(new FileReader(lintBaselineFile))) {
            List<LintBaselineEntry> baseline =
                    reader.lines()
                        .filter(l -> !l.trim().isEmpty() && !l.startsWith("//"))
                        .map(ErrorMessage::parse)
                        .filter(e -> e != null)
                        .collect(toList());
            Errors.setLintBaseline(baseline);
            return true;
        } catch (IOException exception) {
            exception.printStackTrace(System.err);
            return false;
        }
    }

  private static boolean readManifest() {
    manifestPermissions.clear();
    if (manifestFile == null) {
      return true;
    }
    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(manifestFile));
        ByteArrayOutputStream out = new ByteArrayOutputStream()) {
      byte[] buffer = new byte[1024];
      int count;
      while ((count = in.read(buffer)) != -1) {
        out.write(buffer, 0, count);
      }
      final Matcher m = Pattern.compile("(?s)<permission "
          + "[^>]*android:name=\"([^\">]+)\""
          + "[^>]*android:protectionLevel=\"([^\">]+)\"").matcher(out.toString());
      while (m.find()) {
        manifestPermissions.put(m.group(1), m.group(2));
      }
    } catch (IOException e) {
      Errors.error(Errors.PARSE_ERROR, (SourcePositionInfo) null,
          "Failed to parse " + manifestFile + ": " + e);
      return false;
    }
    return true;
  }

  public static String escape(String s) {
    if (escapeChars.size() == 0) {
      return s;
    }
    StringBuffer b = null;
    int begin = 0;
    final int N = s.length();
    for (int i = 0; i < N; i++) {
      char c = s.charAt(i);
      String mapped = escapeChars.get(c);
      if (mapped != null) {
        if (b == null) {
          b = new StringBuffer(s.length() + mapped.length());
        }
        if (begin != i) {
          b.append(s.substring(begin, i));
        }
        b.append(mapped);
        begin = i + 1;
      }
    }
    if (b != null) {
      if (begin != N) {
        b.append(s.substring(begin, N));
      }
      return b.toString();
    }
    return s;
  }

  public static void setPageTitle(Data data, String title) {
    String s = title;
    if (Doclava.title.length() > 0) {
      s += " - " + Doclava.title;
    }
    data.setValue("page.title", s);
  }

  public static Data makeHDF() {
    Data data = jSilver.createData();

    for (String[] p : mHDFData) {
      data.setValue(p[0], p[1]);
    }

    return data;
  }

  public static Data makePackageHDF() {
    Data data = makeHDF();
    Collection<ClassInfo> classes = Converter.rootClasses();

    SortedMap<String, PackageInfo> sorted = new TreeMap<String, PackageInfo>();
    for (ClassInfo cl : classes) {
      PackageInfo pkg = cl.containingPackage();
      String name;
      if (pkg == null) {
        name = "";
      } else {
        name = pkg.name();
      }
      sorted.put(name, pkg);
    }

    int i = 0;
    for (Map.Entry<String, PackageInfo> entry : sorted.entrySet()) {
      String s = entry.getKey();
      PackageInfo pkg = entry.getValue();

      if (pkg.isHiddenOrRemoved()) {
        continue;
      }
      boolean allHiddenOrRemoved = true;
      int pass = 0;
      ClassInfo[] classesToCheck = null;
      while (pass < 6) {
        switch (pass) {
          case 0:
            classesToCheck = pkg.ordinaryClasses();
            break;
          case 1:
            classesToCheck = pkg.enums();
            break;
          case 2:
            classesToCheck = pkg.errors();
            break;
          case 3:
            classesToCheck = pkg.exceptions();
            break;
          case 4:
            classesToCheck = pkg.interfaces();
            break;
          case 5:
            classesToCheck = pkg.annotations();
            break;
          default:
            System.err.println("Error reading package: " + pkg.name());
            break;
        }
        for (ClassInfo cl : classesToCheck) {
          if (!cl.isHiddenOrRemoved()) {
            allHiddenOrRemoved = false;
            break;
          }
        }
        if (!allHiddenOrRemoved) {
          break;
        }
        pass++;
      }
      if (allHiddenOrRemoved) {
        continue;
      }
      if(gmsRef){
          data.setValue("reference.gms", "true");
      } else if(gcmRef){
          data.setValue("reference.gcm", "true");
      }
      data.setValue("reference", "1");
      if (METALAVA_API_SINCE) {
        data.setValue("reference.apilevels", (pkg.getSince() != null) ? "1" : "0");
      } else {
        data.setValue("reference.apilevels", sinceTagger.hasVersions() ? "1" : "0");
      }
      data.setValue("reference.artifacts", artifactTagger.hasArtifacts() ? "1" : "0");
      data.setValue("docs.packages." + i + ".name", s);
      data.setValue("docs.packages." + i + ".link", pkg.htmlPage());
      data.setValue("docs.packages." + i + ".since", pkg.getSince());
      TagInfo.makeHDF(data, "docs.packages." + i + ".shortDescr", pkg.firstSentenceTags());
      i++;
    }

    sinceTagger.writeVersionNames(data);
    return data;
  }

  private static void writeDirectory(File dir, String relative, JSilver js) {
    File[] files = dir.listFiles();
    int i, count = files.length;
    for (i = 0; i < count; i++) {
      File f = files[i];
      if (f.isFile()) {
        String templ = relative + f.getName();
        int len = templ.length();
        if (len > 3 && ".cs".equals(templ.substring(len - 3))) {
          Data data = makePackageHDF();
          String filename = templ.substring(0, len - 3) + htmlExtension;
          ClearPage.write(data, templ, filename, js);
        } else if (len > 3 && ".jd".equals(templ.substring(len - 3))) {
          Data data = makePackageHDF();
          String filename = templ.substring(0, len - 3) + htmlExtension;
          DocFile.writePage(f.getAbsolutePath(), relative, filename, data);
        } else if(!f.getName().equals(".DS_Store")){
              Data data = makeHDF();
              String hdfValue = data.getValue("sac") == null ? "" : data.getValue("sac");
              boolean allowExcepted = hdfValue.equals("true") ? true : false;
              boolean append = false;
              ClearPage.copyFile(allowExcepted, f, templ, append);
        }
      } else if (f.isDirectory()) {
        writeDirectory(f, relative + f.getName() + "/", js);
      }
    }
  }

  public static void writeHTMLPages() {
    for (String htmlDir : ClearPage.htmlDirs) {
      File f = new File(htmlDir);
      if (!f.isDirectory()) {
        System.err.println("htmlDir not a directory: " + htmlDir);
        continue;
      }

      ResourceLoader loader = new FileSystemResourceLoader(f);
      JSilver js = new JSilver(loader);
      writeDirectory(f, "", js);
    }
  }

  /* copy files supplied by the -resourcesdir flag */
  public static void writeResources() {
    if (inputPathResourcesDir != null && !inputPathResourcesDir.isEmpty()) {
      try {
        File f = new File(inputPathResourcesDir);
        if (!f.isDirectory()) {
          System.err.println("resourcesdir is not a directory: " + inputPathResourcesDir);
          return;
        }

        ResourceLoader loader = new FileSystemResourceLoader(f);
        JSilver js = new JSilver(loader);
        writeDirectory(f, outputPathResourcesDir, js);
      } catch(Exception e) {
        System.err.println("Could not copy resourcesdir: " + e);
      }
    }
  }

  public static void writeAssets() {
    if (!includeAssets) return;
    JarFile thisJar = JarUtils.jarForClass(Doclava.class, null);
    if ((thisJar != null) && (includeDefaultAssets)) {
      try {
        List<String> templateDirs = ClearPage.getBundledTemplateDirs();
        for (String templateDir : templateDirs) {
          String assetsDir = templateDir + "/assets";
          JarUtils.copyResourcesToDirectory(thisJar, assetsDir, ClearPage.outputDir + "/assets");
        }
      } catch (IOException e) {
        System.err.println("Error copying assets directory.");
        e.printStackTrace();
        return;
      }
    }

    //write the project-specific assets
    List<String> templateDirs = ClearPage.getTemplateDirs();
    for (String templateDir : templateDirs) {
      File assets = new File(templateDir + "/assets");
      if (assets.isDirectory()) {
        writeDirectory(assets, "assets/", null);
      }
    }

    // Create the timestamp.js file based on .cs file
    Data timedata = Doclava.makeHDF();
    ClearPage.write(timedata, "timestamp.cs", "timestamp.js");
  }

  /** Go through the docs and generate meta-data about each
      page to use in search suggestions */
  public static void writeLists() {

    // Write the lists for API references
    Data data = makeHDF();

    Collection<ClassInfo> classes = Converter.rootClasses();

    SortedMap<String, Object> sorted = new TreeMap<String, Object>();
    for (ClassInfo cl : classes) {
      if (cl.isHiddenOrRemoved()) {
        continue;
      }
      sorted.put(cl.qualifiedName(), cl);
      PackageInfo pkg = cl.containingPackage();
      String name;
      if (pkg == null) {
        name = "";
      } else {
        name = pkg.name();
      }
      sorted.put(name, pkg);
    }

    int i = 0;
    String listDir = javadocDir;
    if (USE_DEVSITE_LOCALE_OUTPUT_PATHS) {
      if (libraryRoot != null) {
        listDir = listDir + libraryRoot;
      }
    }
    for (String s : sorted.keySet()) {
      data.setValue("docs.pages." + i + ".id", "" + i);
      data.setValue("docs.pages." + i + ".label", s);

      Object o = sorted.get(s);
      if (o instanceof PackageInfo) {
        PackageInfo pkg = (PackageInfo) o;
        data.setValue("docs.pages." + i + ".link", pkg.htmlPage());
        data.setValue("docs.pages." + i + ".type", "package");
        data.setValue("docs.pages." + i + ".deprecated", pkg.isDeprecated() ? "true" : "false");
      } else if (o instanceof ClassInfo) {
        ClassInfo cl = (ClassInfo) o;
        data.setValue("docs.pages." + i + ".link", cl.htmlPage());
        data.setValue("docs.pages." + i + ".type", "class");
        data.setValue("docs.pages." + i + ".deprecated", cl.isDeprecated() ? "true" : "false");
      }
      i++;
    }
    ClearPage.write(data, "lists.cs", listDir + "lists.js");


    // Write the lists for JD documents (if there are HTML directories to process)
    // Skip this for devsite builds
    if ((inputPathHtmlDirs.size() > 0) && (!devsite)) {
      Data jddata = makeHDF();
      Iterator counter = new Iterator();
      for (String htmlDir : inputPathHtmlDirs) {
        File dir = new File(htmlDir);
        if (!dir.isDirectory()) {
          continue;
        }
        writeJdDirList(dir, jddata, counter);
      }
      ClearPage.write(jddata, "jd_lists.cs", javadocDir + "jd_lists.js");
    }
  }

  private static class Iterator {
    int i = 0;
  }

  /** Write meta-data for a JD file, used for search suggestions */
  private static void writeJdDirList(File dir, Data data, Iterator counter) {
    File[] files = dir.listFiles();
    int i, count = files.length;
    // Loop all files in given directory
    for (i = 0; i < count; i++) {
      File f = files[i];
      if (f.isFile()) {
        String filePath = f.getAbsolutePath();
        String templ = f.getName();
        int len = templ.length();
        // If it's a .jd file we want to process
        if (len > 3 && ".jd".equals(templ.substring(len - 3))) {
          // remove the directories below the site root
          String webPath = filePath.substring(filePath.indexOf("docs/html/") + 10,
              filePath.length());
          // replace .jd with .html
          webPath = webPath.substring(0, webPath.length() - 3) + htmlExtension;
          // Parse the .jd file for properties data at top of page
          Data hdf = Doclava.makeHDF();
          String filedata = DocFile.readFile(filePath);
          Matcher lines = DocFile.LINE.matcher(filedata);
          String line = null;
          // Get each line to add the key-value to hdf
          while (lines.find()) {
            line = lines.group(1);
            if (line.length() > 0) {
              // Stop when we hit the body
              if (line.equals("@jd:body")) {
                break;
              }
              Matcher prop = DocFile.PROP.matcher(line);
              if (prop.matches()) {
                String key = prop.group(1);
                String value = prop.group(2);
                hdf.setValue(key, value);
              } else {
                break;
              }
            }
          } // done gathering page properties

          // Insert the goods into HDF data (title, link, tags, type)
          String title = hdf.getValue("page.title", "");
          title = title.replaceAll("\"", "'");
          // if there's a <span> in the title, get rid of it
          if (title.indexOf("<span") != -1) {
            String[] splitTitle = title.split("<span(.*?)</span>");
            title = splitTitle[0];
            for (int j = 1; j < splitTitle.length; j++) {
              title.concat(splitTitle[j]);
            }
          }

          StringBuilder tags =  new StringBuilder();
          String tagsList = hdf.getValue("page.tags", "");
          if (!tagsList.equals("")) {
            tagsList = tagsList.replaceAll("\"", "");
            String[] tagParts = tagsList.split(",");
            for (int iter = 0; iter < tagParts.length; iter++) {
              tags.append("\"");
              tags.append(tagParts[iter].trim());
              tags.append("\"");
              if (iter < tagParts.length - 1) {
                tags.append(",");
              }
            }
          }

          String dirName = (webPath.indexOf("/") != -1)
                  ? webPath.substring(0, webPath.indexOf("/")) : "";

          if (!"".equals(title) &&
              !"intl".equals(dirName) &&
              !hdf.getBooleanValue("excludeFromSuggestions")) {
            data.setValue("docs.pages." + counter.i + ".label", title);
            data.setValue("docs.pages." + counter.i + ".link", webPath);
            data.setValue("docs.pages." + counter.i + ".tags", tags.toString());
            data.setValue("docs.pages." + counter.i + ".type", dirName);
            counter.i++;
          }
        }
      } else if (f.isDirectory()) {
        writeJdDirList(f, data, counter);
      }
    }
  }

  public static void cantStripThis(ClassInfo cl, HashSet<ClassInfo> notStrippable) {
    if (!notStrippable.add(cl)) {
      // slight optimization: if it already contains cl, it already contains
      // all of cl's parents
      return;
    }
    ClassInfo supr = cl.superclass();
    if (supr != null) {
      cantStripThis(supr, notStrippable);
    }
    for (ClassInfo iface : cl.interfaces()) {
      cantStripThis(iface, notStrippable);
    }
  }

  private static String getPrintableName(ClassInfo cl) {
    ClassInfo containingClass = cl.containingClass();
    if (containingClass != null) {
      // This is an inner class.
      String baseName = cl.name();
      baseName = baseName.substring(baseName.lastIndexOf('.') + 1);
      return getPrintableName(containingClass) + '$' + baseName;
    }
    return cl.qualifiedName();
  }

  /**
   * Writes the list of classes that must be present in order to provide the non-hidden APIs known
   * to javadoc.
   *
   * @param filename the path to the file to write the list to
   */
  public static void writeKeepList(String filename) {
    HashSet<ClassInfo> notStrippable = new HashSet<ClassInfo>();
    Collection<ClassInfo> all = Converter.allClasses().stream().sorted(ClassInfo.comparator)
        .collect(Collectors.toList());

    // If a class is public and not hidden, then it and everything it derives
    // from cannot be stripped. Otherwise we can strip it.
    for (ClassInfo cl : all) {
      if (cl.isPublic() && !cl.isHiddenOrRemoved()) {
        cantStripThis(cl, notStrippable);
      }
    }
    PrintStream stream = null;
    try {
      stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)));
      for (ClassInfo cl : notStrippable) {
        stream.println(getPrintableName(cl));
      }
    } catch (FileNotFoundException e) {
      System.err.println("error writing file: " + filename);
    } finally {
      if (stream != null) {
        stream.close();
      }
    }
  }

  private static PackageInfo[] sVisiblePackages = null;

  public static PackageInfo[] choosePackages() {
    if (sVisiblePackages != null) {
      return sVisiblePackages;
    }

    Collection<ClassInfo> classes = Converter.rootClasses();
    SortedMap<String, PackageInfo> sorted = new TreeMap<String, PackageInfo>();
    for (ClassInfo cl : classes) {
      PackageInfo pkg = cl.containingPackage();
      String name;
      if (pkg == null) {
        name = "";
      } else {
        name = pkg.name();
      }
      sorted.put(name, pkg);
    }

    ArrayList<PackageInfo> result = new ArrayList<PackageInfo>();

    for (String s : sorted.keySet()) {
      PackageInfo pkg = sorted.get(s);

      if (pkg.isHiddenOrRemoved()) {
        continue;
      }

      boolean allHiddenOrRemoved = true;
      int pass = 0;
      ClassInfo[] classesToCheck = null;
      while (pass < 6) {
        switch (pass) {
          case 0:
            classesToCheck = pkg.ordinaryClasses();
            break;
          case 1:
            classesToCheck = pkg.enums();
            break;
          case 2:
            classesToCheck = pkg.errors();
            break;
          case 3:
            classesToCheck = pkg.exceptions();
            break;
          case 4:
            classesToCheck = pkg.interfaces();
            break;
          case 5:
            classesToCheck = pkg.annotations();
            break;
          default:
            System.err.println("Error reading package: " + pkg.name());
            break;
        }
        for (ClassInfo cl : classesToCheck) {
          if (!cl.isHiddenOrRemoved()) {
            allHiddenOrRemoved = false;
            break;
          }
        }
        if (!allHiddenOrRemoved) {
          break;
        }
        pass++;
      }
      if (allHiddenOrRemoved) {
        continue;
      }

      result.add(pkg);
    }

    sVisiblePackages = result.toArray(new PackageInfo[result.size()]);
    return sVisiblePackages;
  }

  public static void writePackages(String filename) {
    Data data = makePackageHDF();

    int i = 0;
    for (PackageInfo pkg : choosePackages()) {
      writePackage(pkg);

      data.setValue("docs.packages." + i + ".name", pkg.name());
      data.setValue("docs.packages." + i + ".link", pkg.htmlPage());
      TagInfo.makeHDF(data, "docs.packages." + i + ".shortDescr", pkg.firstSentenceTags());

      i++;
    }

    setPageTitle(data, "Package Index");

    TagInfo.makeHDF(data, "root.descr", Converter.convertTags(root.inlineTags(), null));

    String packageDir = javadocDir;
    if (USE_DEVSITE_LOCALE_OUTPUT_PATHS) {
      if (libraryRoot != null) {
        packageDir = packageDir + libraryRoot;
      }
    }
    data.setValue("page.not-api", "true");
    ClearPage.write(data, "packages.cs", packageDir + filename);
    ClearPage.write(data, "package-list.cs", packageDir + "package-list");

    Proofread.writePackages(filename, Converter.convertTags(root.inlineTags(), null));
  }

  public static void writePackage(PackageInfo pkg) {
    // these this and the description are in the same directory,
    // so it's okay
    Data data = makePackageHDF();

    String name = pkg.name();

    data.setValue("package.name", name);
    data.setValue("package.since", pkg.getSince());
    data.setValue("package.descr", "...description...");
    pkg.setFederatedReferences(data, "package");

    makeClassListHDF(data, "package.annotations", ClassInfo.sortByName(pkg.annotations()));
    makeClassListHDF(data, "package.interfaces", ClassInfo.sortByName(pkg.interfaces()));
    makeClassListHDF(data, "package.classes", ClassInfo.sortByName(pkg.ordinaryClasses()));
    makeClassListHDF(data, "package.enums", ClassInfo.sortByName(pkg.enums()));
    makeClassListHDF(data, "package.exceptions", ClassInfo.sortByName(pkg.exceptions()));
    makeClassListHDF(data, "package.errors", ClassInfo.sortByName(pkg.errors()));
    TagInfo.makeHDF(data, "package.shortDescr", pkg.firstSentenceTags());
    TagInfo.makeHDF(data, "package.descr", pkg.inlineTags());

    String filename = pkg.htmlPage();
    setPageTitle(data, name);
    ClearPage.write(data, "package.cs", filename);

    Proofread.writePackage(filename, pkg.inlineTags());
  }

  public static void writeClassLists() {
    int i;
    Data data = makePackageHDF();

    ClassInfo[] classes = PackageInfo.filterHiddenAndRemoved(
        Converter.convertClasses(root.classes()));
    if (classes.length == 0) {
      return;
    }

    Sorter[] sorted = new Sorter[classes.length];
    for (i = 0; i < sorted.length; i++) {
      ClassInfo cl = classes[i];
      String name = cl.name();
      sorted[i] = new Sorter(name, cl);
    }

    Arrays.sort(sorted);

    // make a pass and resolve ones that have the same name
    int firstMatch = 0;
    String lastName = sorted[0].label;
    for (i = 1; i < sorted.length; i++) {
      String s = sorted[i].label;
      if (!lastName.equals(s)) {
        if (firstMatch != i - 1) {
          // there were duplicates
          for (int j = firstMatch; j < i; j++) {
            PackageInfo pkg = ((ClassInfo) sorted[j].data).containingPackage();
            if (pkg != null) {
              sorted[j].label = sorted[j].label + " (" + pkg.name() + ")";
            }
          }
        }
        firstMatch = i;
        lastName = s;
      }
    }

    // and sort again
    Arrays.sort(sorted);

    for (i = 0; i < sorted.length; i++) {
      String s = sorted[i].label;
      ClassInfo cl = (ClassInfo) sorted[i].data;
      char first = Character.toUpperCase(s.charAt(0));
      cl.makeShortDescrHDF(data, "docs.classes." + first + '.' + i);
    }

    String packageDir = javadocDir;
    if (USE_DEVSITE_LOCALE_OUTPUT_PATHS) {
      if (libraryRoot != null) {
        packageDir = packageDir + libraryRoot;
      }
    }

    data.setValue("page.not-api", "true");
    setPageTitle(data, "Class Index");
    ClearPage.write(data, "classes.cs", packageDir + "classes" + htmlExtension);

    if (!devsite) {
      // Index page redirects to the classes.html page, so use the same directory
      // This page is not needed for devsite builds, which should instead use _redirects.yaml
      writeIndex(packageDir);
    }
  }

  // we use the word keywords because "index" means something else in html land
  // the user only ever sees the word index
  /*
   * public static void writeKeywords() { ArrayList<KeywordEntry> keywords = new
   * ArrayList<KeywordEntry>();
   *
   * ClassInfo[] classes = PackageInfo.filterHiddenAndRemoved(Converter.convertClasses(root.classes()));
   *
   * for (ClassInfo cl: classes) { cl.makeKeywordEntries(keywords); }
   *
   * HDF data = makeHDF();
   *
   * Collections.sort(keywords);
   *
   * int i=0; for (KeywordEntry entry: keywords) { String base = "keywords." + entry.firstChar() +
   * "." + i; entry.makeHDF(data, base); i++; }
   *
   * setPageTitle(data, "Index"); ClearPage.write(data, "keywords.cs", javadocDir + "keywords" +
   * htmlExtension); }
   */

  public static void writeHierarchy() {
    Collection<ClassInfo> classes = Converter.rootClasses();
    ArrayList<ClassInfo> info = new ArrayList<ClassInfo>();
    for (ClassInfo cl : classes) {
      if (!cl.isHiddenOrRemoved()) {
        info.add(cl);
      }
    }
    Data data = makePackageHDF();
    Hierarchy.makeHierarchy(data, info.toArray(new ClassInfo[info.size()]));
    setPageTitle(data, "Class Hierarchy");
    ClearPage.write(data, "hierarchy.cs", javadocDir + "hierarchy" + htmlExtension);
  }

  public static void writeClasses() {
    Collection<ClassInfo> classes = Converter.rootClasses();

    for (ClassInfo cl : classes) {
      Data data = makePackageHDF();
      if (!cl.isHiddenOrRemoved()) {
        writeClass(cl, data);
      }
    }
  }

  public static void writeClass(ClassInfo cl, Data data) {
    cl.makeHDF(data);
    setPageTitle(data, cl.name());
    String outfile = cl.htmlPage();
    ClearPage.write(data, "class.cs", outfile);
    Proofread.writeClass(cl.htmlPage(), cl);
  }

  public static void makeClassListHDF(Data data, String base, ClassInfo[] classes) {
    for (int i = 0; i < classes.length; i++) {
      ClassInfo cl = classes[i];
      if (!cl.isHiddenOrRemoved()) {
        cl.makeShortDescrHDF(data, base + "." + i);
      }
    }
  }

  public static String linkTarget(String source, String target) {
    String[] src = source.split("/");
    String[] tgt = target.split("/");

    int srclen = src.length;
    int tgtlen = tgt.length;

    int same = 0;
    while (same < (srclen - 1) && same < (tgtlen - 1) && (src[same].equals(tgt[same]))) {
      same++;
    }

    String s = "";

    int up = srclen - same - 1;
    for (int i = 0; i < up; i++) {
      s += "../";
    }


    int N = tgtlen - 1;
    for (int i = same; i < N; i++) {
      s += tgt[i] + '/';
    }
    s += tgt[tgtlen - 1];

    return s;
  }

  /**
   * Returns true if the given element has an @hide, @removed or @pending annotation.
   */
  private static boolean hasHideOrRemovedAnnotation(Doc doc) {
    String comment = doc.getRawCommentText();
    return comment.indexOf("@hide") != -1 || comment.indexOf("@pending") != -1 ||
        comment.indexOf("@removed") != -1;
  }

  /**
   * Returns true if the given element is hidden.
   */
  private static boolean isHiddenOrRemoved(Doc doc) {
    // Methods, fields, constructors.
    if (doc instanceof MemberDoc) {
      return hasHideOrRemovedAnnotation(doc);
    }

    // Classes, interfaces, enums, annotation types.
    if (doc instanceof ClassDoc) {
      ClassDoc classDoc = (ClassDoc) doc;

      // Check the containing package.
      if (hasHideOrRemovedAnnotation(classDoc.containingPackage())) {
        return true;
      }

      // Check the class doc and containing class docs if this is a
      // nested class.
      ClassDoc current = classDoc;
      do {
        if (hasHideOrRemovedAnnotation(current)) {
          return true;
        }

        current = current.containingClass();
      } while (current != null);
    }

    return false;
  }

  /**
   * Filters out hidden and removed elements.
   */
  private static Object filterHiddenAndRemoved(Object o, Class<?> expected) {
    if (o == null) {
      return null;
    }

    Class type = o.getClass();
    if (type.getName().startsWith("com.sun.")) {
      // TODO: Implement interfaces from superclasses, too.
      return Proxy
          .newProxyInstance(type.getClassLoader(), type.getInterfaces(), new HideHandler(o));
    } else if (o instanceof Object[]) {
      Class<?> componentType = expected.getComponentType();
      Object[] array = (Object[]) o;
      List<Object> list = new ArrayList<Object>(array.length);
      for (Object entry : array) {
        if ((entry instanceof Doc) && isHiddenOrRemoved((Doc) entry)) {
          continue;
        }
        list.add(filterHiddenAndRemoved(entry, componentType));
      }
      return list.toArray((Object[]) Array.newInstance(componentType, list.size()));
    } else {
      return o;
    }
  }

  /**
   * Filters hidden elements out of method return values.
   */
  private static class HideHandler implements InvocationHandler {

    private final Object target;

    public HideHandler(Object target) {
      this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      String methodName = method.getName();
      if (args != null) {
        if (methodName.equals("compareTo") || methodName.equals("equals")
            || methodName.equals("overrides") || methodName.equals("subclassOf")) {
          args[0] = unwrap(args[0]);
        }
      }

      if (methodName.equals("getRawCommentText")) {
        return filterComment((String) method.invoke(target, args));
      }

      // escape "&" in disjunctive types.
      if (proxy instanceof Type && methodName.equals("toString")) {
        return ((String) method.invoke(target, args)).replace("&", "&amp;");
      }

      try {
        return filterHiddenAndRemoved(method.invoke(target, args), method.getReturnType());
      } catch (InvocationTargetException e) {
        throw e.getTargetException();
      }
    }

    private String filterComment(String s) {
      if (s == null) {
        return null;
      }

      s = s.trim();

      // Work around off by one error
      while (s.length() >= 5 && s.charAt(s.length() - 5) == '{') {
        s += "&nbsp;";
      }

      return s;
    }

    private static Object unwrap(Object proxy) {
      if (proxy instanceof Proxy) return ((HideHandler) Proxy.getInvocationHandler(proxy)).target;
      return proxy;
    }
  }

  /**
   * Collect the values used by the Dev tools and write them in files packaged with the SDK
   *
   * @param output the ouput directory for the files.
   */
  private static void writeSdkValues(String output) {
    ArrayList<String> activityActions = new ArrayList<String>();
    ArrayList<String> broadcastActions = new ArrayList<String>();
    ArrayList<String> serviceActions = new ArrayList<String>();
    ArrayList<String> categories = new ArrayList<String>();
    ArrayList<String> features = new ArrayList<String>();

    ArrayList<ClassInfo> layouts = new ArrayList<ClassInfo>();
    ArrayList<ClassInfo> widgets = new ArrayList<ClassInfo>();
    ArrayList<ClassInfo> layoutParams = new ArrayList<ClassInfo>();

    Collection<ClassInfo> classes = Converter.allClasses();

    // The topmost LayoutParams class - android.view.ViewGroup.LayoutParams
    ClassInfo topLayoutParams = null;

    // Go through all the fields of all the classes, looking SDK stuff.
    for (ClassInfo clazz : classes) {

      // first check constant fields for the SdkConstant annotation.
      ArrayList<FieldInfo> fields = clazz.allSelfFields();
      for (FieldInfo field : fields) {
        Object cValue = field.constantValue();
        if (cValue != null) {
            ArrayList<AnnotationInstanceInfo> annotations = field.annotations();
          if (!annotations.isEmpty()) {
            for (AnnotationInstanceInfo annotation : annotations) {
              if (SDK_CONSTANT_ANNOTATION.equals(annotation.type().qualifiedName())) {
                if (!annotation.elementValues().isEmpty()) {
                  String type = annotation.elementValues().get(0).valueString();
                  if (SDK_CONSTANT_TYPE_ACTIVITY_ACTION.equals(type)) {
                    activityActions.add(cValue.toString());
                  } else if (SDK_CONSTANT_TYPE_BROADCAST_ACTION.equals(type)) {
                    broadcastActions.add(cValue.toString());
                  } else if (SDK_CONSTANT_TYPE_SERVICE_ACTION.equals(type)) {
                    serviceActions.add(cValue.toString());
                  } else if (SDK_CONSTANT_TYPE_CATEGORY.equals(type)) {
                    categories.add(cValue.toString());
                  } else if (SDK_CONSTANT_TYPE_FEATURE.equals(type)) {
                    features.add(cValue.toString());
                  }
                }
                break;
              }
            }
          }
        }
      }

      // Now check the class for @Widget or if its in the android.widget package
      // (unless the class is hidden or abstract, or non public)
      if (clazz.isHiddenOrRemoved() == false && clazz.isPublic() && clazz.isAbstract() == false) {
        boolean annotated = false;
        ArrayList<AnnotationInstanceInfo> annotations = clazz.annotations();
        if (!annotations.isEmpty()) {
          for (AnnotationInstanceInfo annotation : annotations) {
            if (SDK_WIDGET_ANNOTATION.equals(annotation.type().qualifiedName())) {
              widgets.add(clazz);
              annotated = true;
              break;
            } else if (SDK_LAYOUT_ANNOTATION.equals(annotation.type().qualifiedName())) {
              layouts.add(clazz);
              annotated = true;
              break;
            }
          }
        }

        if (annotated == false) {
          if (topLayoutParams == null
              && "android.view.ViewGroup.LayoutParams".equals(clazz.qualifiedName())) {
            topLayoutParams = clazz;
          }
          // let's check if this is inside android.widget or android.view
          if (isIncludedPackage(clazz)) {
            // now we check what this class inherits either from android.view.ViewGroup
            // or android.view.View, or android.view.ViewGroup.LayoutParams
            int type = checkInheritance(clazz);
            switch (type) {
              case TYPE_WIDGET:
                widgets.add(clazz);
                break;
              case TYPE_LAYOUT:
                layouts.add(clazz);
                break;
              case TYPE_LAYOUT_PARAM:
                layoutParams.add(clazz);
                break;
            }
          }
        }
      }
    }

    // now write the files, whether or not the list are empty.
    // the SDK built requires those files to be present.

    Collections.sort(activityActions);
    writeValues(output + "/activity_actions.txt", activityActions);

    Collections.sort(broadcastActions);
    writeValues(output + "/broadcast_actions.txt", broadcastActions);

    Collections.sort(serviceActions);
    writeValues(output + "/service_actions.txt", serviceActions);

    Collections.sort(categories);
    writeValues(output + "/categories.txt", categories);

    Collections.sort(features);
    writeValues(output + "/features.txt", features);

    // before writing the list of classes, we do some checks, to make sure the layout params
    // are enclosed by a layout class (and not one that has been declared as a widget)
    for (int i = 0; i < layoutParams.size();) {
      ClassInfo clazz = layoutParams.get(i);
      ClassInfo containingClass = clazz.containingClass();
      boolean remove = containingClass == null || layouts.indexOf(containingClass) == -1;
      // Also ensure that super classes of the layout params are in android.widget or android.view.
      while (!remove && (clazz = clazz.superclass()) != null && !clazz.equals(topLayoutParams)) {
        remove = !isIncludedPackage(clazz);
      }
      if (remove) {
        layoutParams.remove(i);
      } else {
        i++;
      }
    }

    writeClasses(output + "/widgets.txt", widgets, layouts, layoutParams);
  }

  /**
   * Check if the clazz is in package android.view or android.widget
   */
  private static boolean isIncludedPackage(ClassInfo clazz) {
    String pckg = clazz.containingPackage().name();
    return "android.widget".equals(pckg) || "android.view".equals(pckg);
  }

  /**
   * Writes a list of values into a text files.
   *
   * @param pathname the absolute os path of the output file.
   * @param values the list of values to write.
   */
  private static void writeValues(String pathname, ArrayList<String> values) {
    FileWriter fw = null;
    BufferedWriter bw = null;
    try {
      fw = new FileWriter(pathname, false);
      bw = new BufferedWriter(fw);

      for (String value : values) {
        bw.append(value).append('\n');
      }
    } catch (IOException e) {
      // pass for now
    } finally {
      try {
        if (bw != null) bw.close();
      } catch (IOException e) {
        // pass for now
      }
      try {
        if (fw != null) fw.close();
      } catch (IOException e) {
        // pass for now
      }
    }
  }

  /**
   * Writes the widget/layout/layout param classes into a text files.
   *
   * @param pathname the absolute os path of the output file.
   * @param widgets the list of widget classes to write.
   * @param layouts the list of layout classes to write.
   * @param layoutParams the list of layout param classes to write.
   */
  private static void writeClasses(String pathname, ArrayList<ClassInfo> widgets,
      ArrayList<ClassInfo> layouts, ArrayList<ClassInfo> layoutParams) {
    FileWriter fw = null;
    BufferedWriter bw = null;
    try {
      fw = new FileWriter(pathname, false);
      bw = new BufferedWriter(fw);

      // write the 3 types of classes.
      for (ClassInfo clazz : widgets) {
        writeClass(bw, clazz, 'W');
      }
      for (ClassInfo clazz : layoutParams) {
        writeClass(bw, clazz, 'P');
      }
      for (ClassInfo clazz : layouts) {
        writeClass(bw, clazz, 'L');
      }
    } catch (IOException e) {
      // pass for now
    } finally {
      try {
        if (bw != null) bw.close();
      } catch (IOException e) {
        // pass for now
      }
      try {
        if (fw != null) fw.close();
      } catch (IOException e) {
        // pass for now
      }
    }
  }

  /**
   * Writes a class name and its super class names into a {@link BufferedWriter}.
   *
   * @param writer the BufferedWriter to write into
   * @param clazz the class to write
   * @param prefix the prefix to put at the beginning of the line.
   * @throws IOException
   */
  private static void writeClass(BufferedWriter writer, ClassInfo clazz, char prefix)
      throws IOException {
    writer.append(prefix).append(clazz.qualifiedName());
    ClassInfo superClass = clazz;
    while ((superClass = superClass.superclass()) != null) {
      writer.append(' ').append(superClass.qualifiedName());
    }
    writer.append('\n');
  }

  /**
   * Checks the inheritance of {@link ClassInfo} objects. This method return
   * <ul>
   * <li>{@link #TYPE_LAYOUT}: if the class extends <code>android.view.ViewGroup</code></li>
   * <li>{@link #TYPE_WIDGET}: if the class extends <code>android.view.View</code></li>
   * <li>{@link #TYPE_LAYOUT_PARAM}: if the class extends
   * <code>android.view.ViewGroup$LayoutParams</code></li>
   * <li>{@link #TYPE_NONE}: in all other cases</li>
   * </ul>
   *
   * @param clazz the {@link ClassInfo} to check.
   */
  private static int checkInheritance(ClassInfo clazz) {
    if ("android.view.ViewGroup".equals(clazz.qualifiedName())) {
      return TYPE_LAYOUT;
    } else if ("android.view.View".equals(clazz.qualifiedName())) {
      return TYPE_WIDGET;
    } else if ("android.view.ViewGroup.LayoutParams".equals(clazz.qualifiedName())) {
      return TYPE_LAYOUT_PARAM;
    }

    ClassInfo parent = clazz.superclass();
    if (parent != null) {
      return checkInheritance(parent);
    }

    return TYPE_NONE;
  }

  /**
   * Ensures a trailing '/' at the end of a string.
   */
  static String ensureSlash(String path) {
    return path.endsWith("/") ? path : path + "/";
  }

  /**
  * Process sample projects. Generate the TOC for the samples groups and project
  * and write it to a cs var, which is then written to files during templating to
  * html output. Collect metadata from sample project _index.jd files. Copy html
  * and specific source file types to the output directory.
  */
  public static void writeSamples(boolean offlineMode, ArrayList<SampleCode> sampleCodes,
      boolean sortNavByGroups) {
    samplesNavTree = makeHDF();

    // Go through samples processing files. Create a root list for SC nodes,
    // pass it to SCs for their NavTree children and append them.
    List<SampleCode.Node> samplesList = new ArrayList<SampleCode.Node>();
    List<SampleCode.Node> sampleGroupsRootNodes = null;
    for (SampleCode sc : sampleCodes) {
      samplesList.add(sc.setSamplesTOC(offlineMode));
     }
    if (sortNavByGroups) {
      sampleGroupsRootNodes = new ArrayList<SampleCode.Node>();
      for (SampleCode gsc : sampleCodeGroups) {
        String link =  ClearPage.toroot + "samples/" + gsc.mTitle.replaceAll(" ", "").trim().toLowerCase() + ".html";
        sampleGroupsRootNodes.add(new SampleCode.Node.Builder().setLabel(gsc.mTitle).setLink(link).setType("groupholder").build());
      }
    }
    // Pass full samplesList to SC to render the samples TOC to sampleNavTree hdf
    if (!offlineMode) {
      SampleCode.writeSamplesNavTree(samplesList, sampleGroupsRootNodes);
    }
    // Iterate the samplecode projects writing the files to out
    for (SampleCode sc : sampleCodes) {
      sc.writeSamplesFiles(offlineMode);
    }
  }

  /**
  * Given an initial samples directory root, walk through the directory collecting
  * sample code project roots and adding them to an array of SampleCodes.
  * @param rootDir Root directory holding all browseable sample code projects,
  *        defined in frameworks/base/Android.mk as "-sampleDir path".
  */
  public static void getSampleProjects(File rootDir) {
    for (File f : rootDir.listFiles()) {
      String name = f.getName();
      if (f.isDirectory()) {
        if (isValidSampleProjectRoot(f)) {
          sampleCodes.add(new SampleCode(f.getAbsolutePath(), "samples/" + name, name));
        } else {
          getSampleProjects(f);
        }
      }
    }
  }

  /**
  * Test whether a given directory is the root directory for a sample code project.
  * Root directories must contain a valid _index.jd file and a src/ directory
  * or a module directory that contains a src/ directory.
  */
  public static boolean isValidSampleProjectRoot(File dir) {
    File indexJd = new File(dir, "_index.jd");
    if (!indexJd.exists()) {
      return false;
    }
    File srcDir = new File(dir, "src");
    if (srcDir.exists()) {
      return true;
    } else {
      // Look for a src/ directory one level below the root directory, so
      // modules are supported.
      for (File childDir : dir.listFiles()) {
        if (childDir.isDirectory()) {
          srcDir = new File(childDir, "src");
          if (srcDir.exists()) {
            return true;
          }
        }
      }
      return false;
    }
  }

  public static String getDocumentationStringForAnnotation(String annotationName) {
    if (!documentAnnotations) return null;
    if (annotationDocumentationMap == null) {
      annotationDocumentationMap = new HashMap<String, String>();
      // parse the file for map
      try {
        BufferedReader in = new BufferedReader(
            new FileReader(documentAnnotationsPath));
        try {
          String line = in.readLine();
          String[] split;
          while (line != null) {
            split = line.split(":");
            annotationDocumentationMap.put(split[0], split[1]);
            line = in.readLine();
          }
        } finally {
          in.close();
        }
      } catch (IOException e) {
        System.err.println("Unable to open annotations documentation file for reading: "
            + documentAnnotationsPath);
      }
    }
    return annotationDocumentationMap.get(annotationName);
  }

  public static void writeCompatConfig() {
    if (compatConfig == null) {
      return;
    }
    CompatInfo config = CompatInfo.readCompatConfig(compatConfig);
    Data data = makeHDF();
    config.makeHDF(data);
    setPageTitle(data, "Compatibility changes");
    // TODO - should we write the output to some other path?
    String outfile = "compatchanges.html";
    ClearPage.write(data, "compatchanges.cs", outfile);
  }

}