• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.icu4j.srcgen;
17 
18 import static com.google.currysrc.api.process.Rules.createMandatoryRule;
19 import static com.google.currysrc.api.process.Rules.createOptionalRule;
20 
21 import org.eclipse.jdt.core.JavaCore;
22 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
23 
24 import com.google.common.collect.Lists;
25 import com.google.currysrc.Main;
26 import com.google.currysrc.aosp.Annotations;
27 import com.google.currysrc.api.RuleSet;
28 import com.google.currysrc.api.input.InputFileGenerator;
29 import com.google.currysrc.api.output.BasicOutputSourceFileGenerator;
30 import com.google.currysrc.api.output.OutputSourceFileGenerator;
31 import com.google.currysrc.api.process.Rule;
32 import com.google.currysrc.api.process.ast.BodyDeclarationLocator;
33 import com.google.currysrc.api.process.ast.BodyDeclarationLocators;
34 import com.google.currysrc.api.process.ast.TypeLocator;
35 import com.google.currysrc.processors.AddAnnotation;
36 import com.google.currysrc.processors.AddDefaultConstructor;
37 import com.google.currysrc.processors.HidePublicClasses;
38 import com.google.currysrc.processors.InsertHeader;
39 import com.google.currysrc.processors.ModifyQualifiedNames;
40 import com.google.currysrc.processors.ModifyStringLiterals;
41 import com.google.currysrc.processors.RemoveJavaDocTags;
42 import com.google.currysrc.processors.RenamePackage;
43 import com.google.currysrc.processors.ReplaceTextCommentScanner;
44 
45 import java.io.File;
46 import java.nio.file.Path;
47 import java.nio.file.Paths;
48 import java.util.Arrays;
49 import java.util.List;
50 import java.util.Map;
51 import java.util.stream.Collectors;
52 
53 /**
54  * Applies Android's ICU4J source code transformation rules. If you make any changes to this class
55  * then you should re-run the generate_android_icu4j.sh script.
56  */
57 public class Icu4jTransform {
58 
59   // The list of public ICU API classes exposed on Android. If you change this, you should change
60   // the INITIAL_DEPRECATED_SET below to include entries from the new classes.
61   static final String[] PUBLIC_API_CLASSES = new String[] {
62       /* ASCII order please. */
63       "android.icu.lang.UCharacter",
64       "android.icu.lang.UCharacter$BidiPairedBracketType",
65       "android.icu.lang.UCharacter$DecompositionType",
66       "android.icu.lang.UCharacter$EastAsianWidth",
67       "android.icu.lang.UCharacter$GraphemeClusterBreak",
68       "android.icu.lang.UCharacter$HangulSyllableType",
69       "android.icu.lang.UCharacter$IndicPositionalCategory",
70       "android.icu.lang.UCharacter$IndicSyllabicCategory",
71       "android.icu.lang.UCharacter$JoiningGroup",
72       "android.icu.lang.UCharacter$JoiningType",
73       "android.icu.lang.UCharacter$LineBreak",
74       "android.icu.lang.UCharacter$NumericType",
75       "android.icu.lang.UCharacter$SentenceBreak",
76       "android.icu.lang.UCharacter$UnicodeBlock",
77       "android.icu.lang.UCharacter$VerticalOrientation",
78       "android.icu.lang.UCharacter$WordBreak",
79       "android.icu.lang.UCharacterCategory",
80       "android.icu.lang.UCharacterDirection",
81       "android.icu.lang.UCharacterEnums",
82       "android.icu.lang.UCharacterEnums$ECharacterCategory",
83       "android.icu.lang.UCharacterEnums$ECharacterDirection",
84       "android.icu.lang.UProperty",
85       "android.icu.lang.UProperty$NameChoice",
86       "android.icu.lang.UScript",
87       "android.icu.lang.UScript$ScriptUsage",
88       "android.icu.math.BigDecimal",
89       "android.icu.math.MathContext",
90       "android.icu.number.CompactNotation",
91       "android.icu.number.CurrencyPrecision",
92       "android.icu.number.FormattedNumber",
93       "android.icu.number.FormattedNumberRange",
94       "android.icu.number.FractionPrecision",
95       "android.icu.number.IntegerWidth",
96       "android.icu.number.LocalizedNumberFormatter",
97       "android.icu.number.LocalizedNumberRangeFormatter",
98       "android.icu.number.Notation",
99       "android.icu.number.NumberFormatter",
100       "android.icu.number.NumberFormatter$DecimalSeparatorDisplay",
101       "android.icu.number.NumberFormatter$GroupingStrategy",
102       "android.icu.number.NumberFormatter$RoundingPriority",
103       "android.icu.number.NumberFormatter$SignDisplay",
104       "android.icu.number.NumberFormatter$TrailingZeroDisplay",
105       "android.icu.number.NumberFormatter$UnitWidth",
106       "android.icu.number.NumberFormatterSettings",
107       "android.icu.number.NumberRangeFormatter",
108       "android.icu.number.NumberRangeFormatter$RangeCollapse",
109       "android.icu.number.NumberRangeFormatter$RangeIdentityFallback",
110       "android.icu.number.NumberRangeFormatter$RangeIdentityResult",
111       "android.icu.number.NumberRangeFormatterSettings",
112       "android.icu.number.Precision",
113       "android.icu.number.Scale",
114       "android.icu.number.ScientificNotation",
115       "android.icu.number.SimpleNotation",
116       "android.icu.number.UnlocalizedNumberFormatter",
117       "android.icu.number.UnlocalizedNumberRangeFormatter",
118       "android.icu.text.AlphabeticIndex",
119       "android.icu.text.AlphabeticIndex$Bucket",
120       "android.icu.text.AlphabeticIndex$Bucket$LabelType",
121       "android.icu.text.AlphabeticIndex$ImmutableIndex",
122       "android.icu.text.AlphabeticIndex$Record",
123       "android.icu.text.Bidi",
124       "android.icu.text.BidiClassifier",
125       "android.icu.text.BidiRun",
126       "android.icu.text.BreakIterator",
127       "android.icu.text.CaseMap",
128       "android.icu.text.CaseMap$Fold",
129       "android.icu.text.CaseMap$Lower",
130       "android.icu.text.CaseMap$Title",
131       "android.icu.text.CaseMap$Upper",
132       "android.icu.text.CollationElementIterator",
133       "android.icu.text.CollationKey",
134       "android.icu.text.CollationKey$BoundMode",
135       "android.icu.text.Collator",
136       "android.icu.text.Collator$CollatorFactory",
137       "android.icu.text.Collator$ReorderCodes",
138       "android.icu.text.CompactDecimalFormat",
139       "android.icu.text.CompactDecimalFormat$CompactStyle",
140       "android.icu.text.ConstrainedFieldPosition",
141       "android.icu.text.CurrencyPluralInfo",
142       "android.icu.text.DateFormat",
143       "android.icu.text.DateFormat$BooleanAttribute",
144       "android.icu.text.DateFormat$Field",
145       "android.icu.text.DateFormat$HourCycle",
146       "android.icu.text.DateFormatSymbols",
147       "android.icu.text.DateIntervalFormat",
148       "android.icu.text.DateIntervalFormat$FormattedDateInterval",
149       "android.icu.text.DateIntervalInfo",
150       "android.icu.text.DateIntervalInfo$PatternInfo",
151       "android.icu.text.DateTimePatternGenerator",
152       "android.icu.text.DateTimePatternGenerator$DisplayWidth",
153       "android.icu.text.DateTimePatternGenerator$PatternInfo",
154       "android.icu.text.DecimalFormat",
155       "android.icu.text.DecimalFormatSymbols",
156       "android.icu.text.DisplayContext",
157       "android.icu.text.DisplayContext$Type",
158       "android.icu.text.Edits",
159       "android.icu.text.Edits$Iterator",
160       "android.icu.text.FormattedValue",
161       "android.icu.text.IDNA",
162       "android.icu.text.IDNA$Error",
163       "android.icu.text.IDNA$Info",
164       "android.icu.text.ListFormatter",
165       "android.icu.text.ListFormatter$FormattedList",
166       "android.icu.text.ListFormatter$Type",
167       "android.icu.text.ListFormatter$Width",
168       "android.icu.text.LocaleDisplayNames",
169       "android.icu.text.LocaleDisplayNames$DialectHandling",
170       "android.icu.text.LocaleDisplayNames$UiListItem",
171       "android.icu.text.MeasureFormat",
172       "android.icu.text.MeasureFormat$FormatWidth",
173       "android.icu.text.MessageFormat",
174       "android.icu.text.MessageFormat$Field",
175       "android.icu.text.MessagePattern",
176       "android.icu.text.MessagePattern$ApostropheMode",
177       "android.icu.text.MessagePattern$ArgType",
178       "android.icu.text.MessagePattern$Part",
179       "android.icu.text.MessagePattern$Part$Type",
180       "android.icu.text.Normalizer",
181       "android.icu.text.Normalizer$QuickCheckResult",
182       "android.icu.text.Normalizer2",
183       "android.icu.text.Normalizer2$Mode",
184       "android.icu.text.NumberFormat",
185       "android.icu.text.NumberFormat$Field",
186       "android.icu.text.NumberingSystem",
187       "android.icu.text.PluralFormat",
188       "android.icu.text.PluralRules",
189       "android.icu.text.PluralRules$PluralType",
190       "android.icu.text.RelativeDateTimeFormatter",
191       "android.icu.text.RelativeDateTimeFormatter$AbsoluteUnit",
192       "android.icu.text.RelativeDateTimeFormatter$Direction",
193       "android.icu.text.RelativeDateTimeFormatter$FormattedRelativeDateTime",
194       "android.icu.text.RelativeDateTimeFormatter$RelativeDateTimeUnit",
195       "android.icu.text.RelativeDateTimeFormatter$RelativeUnit",
196       "android.icu.text.RelativeDateTimeFormatter$Style",
197       "android.icu.text.Replaceable",
198       "android.icu.text.RuleBasedCollator",
199       "android.icu.text.ScientificNumberFormatter",
200       "android.icu.text.SearchIterator",
201       "android.icu.text.SearchIterator$ElementComparisonType",
202       "android.icu.text.SelectFormat",
203       "android.icu.text.SimpleDateFormat",
204       "android.icu.text.StringPrepParseException",
205       "android.icu.text.StringSearch",
206       "android.icu.text.SymbolTable",
207       "android.icu.text.TimeZoneFormat",
208       "android.icu.text.TimeZoneFormat$GMTOffsetPatternType",
209       "android.icu.text.TimeZoneFormat$ParseOption",
210       "android.icu.text.TimeZoneFormat$Style",
211       "android.icu.text.TimeZoneFormat$TimeType",
212       "android.icu.text.TimeZoneNames",
213       "android.icu.text.TimeZoneNames$NameType",
214       "android.icu.text.Transliterator",
215       "android.icu.text.Transliterator$Position",
216       "android.icu.text.UCharacterIterator",
217       "android.icu.text.UFormat",
218       "android.icu.text.UnicodeFilter",
219       "android.icu.text.UnicodeMatcher",
220       "android.icu.text.UnicodeSet",
221       "android.icu.text.UnicodeSet$ComparisonStyle",
222       "android.icu.text.UnicodeSet$EntryRange",
223       "android.icu.text.UnicodeSet$SpanCondition",
224       "android.icu.text.UnicodeSetIterator",
225       "android.icu.text.UnicodeSetSpanner",
226       "android.icu.text.UnicodeSetSpanner$CountMethod",
227       "android.icu.text.UnicodeSetSpanner$TrimOption",
228       "android.icu.util.BuddhistCalendar",
229       "android.icu.util.CECalendar",
230       "android.icu.util.Calendar",
231       "android.icu.util.Calendar$WeekData",
232       "android.icu.util.ChineseCalendar",
233       "android.icu.util.CopticCalendar",
234       "android.icu.util.Currency",
235       "android.icu.util.Currency$CurrencyUsage",
236       "android.icu.util.CurrencyAmount",
237       "android.icu.util.DateInterval",
238       "android.icu.util.EthiopicCalendar",
239       "android.icu.util.Freezable",
240       "android.icu.util.GregorianCalendar",
241       "android.icu.util.HebrewCalendar",
242       "android.icu.util.ICUUncheckedIOException",
243       "android.icu.util.IllformedLocaleException",
244       "android.icu.util.IndianCalendar",
245       "android.icu.util.IslamicCalendar",
246       "android.icu.util.IslamicCalendar$CalculationType",
247       "android.icu.util.JapaneseCalendar",
248       "android.icu.util.LocaleData",
249       "android.icu.util.LocaleData$MeasurementSystem",
250       "android.icu.util.LocaleData$PaperSize",
251       "android.icu.util.Measure",
252       "android.icu.util.MeasureUnit",
253       "android.icu.util.MeasureUnit$Complexity",
254       "android.icu.util.MeasureUnit$MeasurePrefix",
255       "android.icu.util.Output",
256       "android.icu.util.RangeValueIterator",
257       "android.icu.util.RangeValueIterator$Element",
258       "android.icu.util.TaiwanCalendar",
259       "android.icu.util.TimeUnit",
260       "android.icu.util.TimeZone",
261       "android.icu.util.TimeZone$SystemTimeZoneType",
262       "android.icu.util.ULocale",
263       "android.icu.util.ULocale$AvailableType",
264       "android.icu.util.ULocale$Builder",
265       "android.icu.util.ULocale$Category",
266       "android.icu.util.UniversalTimeScale",
267       "android.icu.util.ValueIterator",
268       "android.icu.util.ValueIterator$Element",
269       "android.icu.util.VersionInfo",
270 
271   };
272 
273   /**
274    * The set of deprecated ICU types/methods/fields that must not be part of the public API as they
275    * were deprecated when Android first exposed their classes as a public API. Methods deprecated by
276    * ICU after this will be visible and deprecated in Android.
277    */
278   // This list was originally generated by the CaptureDeprecatedElements tool when run against
279   // ICU56 with the original PUBLIC_API_CLASSES.
280   private static final String[] INITIAL_DEPRECATED_SET = new String[] {
281       /* ASCII order please. */
282       "field:android.icu.lang.UProperty#ISO_COMMENT",
283       "field:android.icu.lang.UProperty#UNDEFINED",
284       "field:android.icu.lang.UProperty#UNICODE_1_NAME",
285       "field:android.icu.lang.UScript#DUPLOYAN_SHORTAND",
286       "field:android.icu.text.Bidi#CLASS_DEFAULT",
287       "field:android.icu.text.CaseMap#internalOptions",
288       "field:android.icu.text.DateFormat#ABBR_STANDALONE_MONTH",
289       "field:android.icu.text.DateFormat#DATE_SKELETONS",
290       "field:android.icu.text.DateFormat#HOUR_GENERIC_TZ",
291       "field:android.icu.text.DateFormat#HOUR_MINUTE_GENERIC_TZ",
292       "field:android.icu.text.DateFormat#HOUR_MINUTE_TZ",
293       "field:android.icu.text.DateFormat#HOUR_TZ",
294       "field:android.icu.text.DateFormat#STANDALONE_MONTH",
295       "field:android.icu.text.DateFormat#TIME_SKELETONS",
296       "field:android.icu.text.DateFormat#ZONE_SKELETONS",
297       "field:android.icu.text.DateFormatSymbols#DT_CONTEXT_COUNT",
298       "field:android.icu.text.DateFormatSymbols#DT_WIDTH_COUNT",
299       "field:android.icu.text.DateFormatSymbols#NUMERIC",
300       "field:android.icu.text.DateTimePatternGenerator#MATCH_MINUTE_FIELD_LENGTH",
301       "field:android.icu.text.DateTimePatternGenerator#MATCH_SECOND_FIELD_LENGTH",
302       "field:android.icu.text.IDNA#ALLOW_UNASSIGNED",
303       "field:android.icu.text.Normalizer#COMPARE_NORM_OPTIONS_SHIFT",
304       "field:android.icu.text.Normalizer#COMPOSE",
305       "field:android.icu.text.Normalizer#COMPOSE_COMPAT",
306       "field:android.icu.text.Normalizer#DECOMP",
307       "field:android.icu.text.Normalizer#DECOMP_COMPAT",
308       "field:android.icu.text.Normalizer#DEFAULT",
309       "field:android.icu.text.Normalizer#DONE",
310       "field:android.icu.text.Normalizer#FCD",
311       "field:android.icu.text.Normalizer#IGNORE_HANGUL",
312       "field:android.icu.text.Normalizer#NFC",
313       "field:android.icu.text.Normalizer#NFD",
314       "field:android.icu.text.Normalizer#NFKC",
315       "field:android.icu.text.Normalizer#NFKD",
316       "field:android.icu.text.Normalizer#NONE",
317       "field:android.icu.text.Normalizer#NO_OP",
318       "field:android.icu.text.Normalizer#UNICODE_3_2",
319       "field:android.icu.text.PluralRules#CATEGORY_SEPARATOR",
320       "field:android.icu.text.PluralRules#KEYWORD_RULE_SEPARATOR",
321       "field:android.icu.text.PluralRules$FixedDecimal#decimalDigits",
322       "field:android.icu.text.PluralRules$FixedDecimal#decimalDigitsWithoutTrailingZeros",
323       "field:android.icu.text.PluralRules$FixedDecimal#hasIntegerValue",
324       "field:android.icu.text.PluralRules$FixedDecimal#integerValue",
325       "field:android.icu.text.PluralRules$FixedDecimal#isNegative",
326       "field:android.icu.text.PluralRules$FixedDecimal#source",
327       "field:android.icu.text.PluralRules$FixedDecimal#visibleDecimalDigitCount",
328       "field:android.icu.text.PluralRules$FixedDecimal#visibleDecimalDigitCountWithoutTrailingZeros",
329       "field:android.icu.text.PluralRules$FixedDecimalRange#end",
330       "field:android.icu.text.PluralRules$FixedDecimalRange#start",
331       "field:android.icu.text.PluralRules$FixedDecimalSamples#bounded",
332       "field:android.icu.text.PluralRules$FixedDecimalSamples#sampleType",
333       "field:android.icu.text.PluralRules$FixedDecimalSamples#samples",
334       "field:android.icu.text.PluralRules$StandardPluralCategories#COUNT",
335       "field:android.icu.text.PluralRules$StandardPluralCategories#VALUES",
336       "field:android.icu.text.UnicodeSetIterator#endElement",
337       "field:android.icu.text.UnicodeSetIterator#nextElement",
338       "field:android.icu.util.Calendar#WEEKDAY",
339       "field:android.icu.util.Calendar#WEEKEND",
340       "field:android.icu.util.Calendar#WEEKEND_CEASE",
341       "field:android.icu.util.Calendar#WEEKEND_ONSET",
342       "field:android.icu.util.LocaleData#DELIMITER_COUNT",
343       "field:android.icu.util.LocaleData#ES_COUNT",
344       "field:android.icu.util.LocaleData#ES_CURRENCY",
345       "field:android.icu.util.MeasureUnit#subType",
346       "field:android.icu.util.MeasureUnit#type",
347       "field:android.icu.util.VersionInfo#ICU_DATA_VERSION",
348       "field:android.icu.util.VersionInfo#ICU_DATA_VERSION_PATH",
349       "field:android.icu.util.VersionInfo#UCOL_TAILORINGS_VERSION",
350       "method:android.icu.lang.UCharacter#getCharFromName1_0(String)",
351       "method:android.icu.lang.UCharacter#getISOComment(int)",
352       "method:android.icu.lang.UCharacter#getName1_0(int)",
353       "method:android.icu.lang.UCharacter#getName1_0Iterator()",
354       "method:android.icu.lang.UCharacter#getPropertyValueEnumNoThrow(int,CharSequence)",
355       "method:android.icu.lang.UCharacter#getStringPropertyValue(int,int,int)",
356       "method:android.icu.lang.UCharacter#isJavaLetter(int)",
357       "method:android.icu.lang.UCharacter#isJavaLetterOrDigit(int)",
358       "method:android.icu.lang.UCharacter#isSpace(int)",
359       "method:android.icu.lang.UCharacter#toTitleFirst(ULocale,String)",
360       "method:android.icu.text.AlphabeticIndex#getFirstCharactersInScripts()",
361       "method:android.icu.text.BreakIterator#getBreakInstance(ULocale,int)",
362       "method:android.icu.text.CollationElementIterator#getRuleBasedCollator()",
363       "method:android.icu.text.CollationElementIterator#hashCode()",
364       "method:android.icu.text.Collator#doCompare(CharSequence,CharSequence)",
365       "method:android.icu.text.Collator#setStrength2(int)",
366       "method:android.icu.text.Collator#setVariableTop(String)",
367       "method:android.icu.text.Collator#setVariableTop(int)",
368       "method:android.icu.text.CompactDecimalFormat#CompactDecimalFormat(String,DecimalFormatSymbols,CompactStyle,PluralRules,long[],Map<String,String[][]>,Map<String,String[]>,Collection<String>)",
369       "method:android.icu.text.CurrencyPluralInfo#hashCode()",
370       "method:android.icu.text.DateFormatSymbols#getDateFormatBundle(Calendar,Locale)",
371       "method:android.icu.text.DateFormatSymbols#getDateFormatBundle(Calendar,ULocale)",
372       "method:android.icu.text.DateFormatSymbols#getDateFormatBundle(Class<? extends Calendar>,Locale)",
373       "method:android.icu.text.DateFormatSymbols#getDateFormatBundle(Class<? extends Calendar>,ULocale)",
374       "method:android.icu.text.DateFormatSymbols#getLeapMonthPattern(int,int)",
375       "method:android.icu.text.DateFormatSymbols#initializeData(ULocale,CalendarData)",
376       "method:android.icu.text.DateFormatSymbols#setLeapMonthPattern(String,int,int)",
377       "method:android.icu.text.DateIntervalFormat#DateIntervalFormat(String,DateIntervalInfo,SimpleDateFormat)",
378       "method:android.icu.text.DateIntervalFormat#getPatterns(Calendar,Calendar,Output<String>)",
379       "method:android.icu.text.DateIntervalFormat#getRawPatterns()",
380       "method:android.icu.text.DateIntervalFormat#parseObject(String,ParsePosition)",
381       "method:android.icu.text.DateIntervalInfo#DateIntervalInfo()",
382       "method:android.icu.text.DateIntervalInfo#genPatternInfo(String,boolean)",
383       "method:android.icu.text.DateIntervalInfo#getPatterns()",
384       "method:android.icu.text.DateIntervalInfo#getRawPatterns()",
385       "method:android.icu.text.DateTimePatternGenerator#addPatternWithSkeleton(String,String,boolean,PatternInfo)",
386       "method:android.icu.text.DateTimePatternGenerator#getAppendFormatNumber(String)",
387       "method:android.icu.text.DateTimePatternGenerator#getCanonicalSkeletonAllowingDuplicates(String)",
388       "method:android.icu.text.DateTimePatternGenerator#getDefaultHourFormatChar()",
389       "method:android.icu.text.DateTimePatternGenerator#getFields(String)",
390       "method:android.icu.text.DateTimePatternGenerator#getFrozenInstance(ULocale)",
391       "method:android.icu.text.DateTimePatternGenerator#getRedundants(Collection<String>)",
392       "method:android.icu.text.DateTimePatternGenerator#getSkeletonAllowingDuplicates(String)",
393       "method:android.icu.text.DateTimePatternGenerator#isSingleField(String)",
394       "method:android.icu.text.DateTimePatternGenerator#setDefaultHourFormatChar(char)",
395       "method:android.icu.text.DateTimePatternGenerator#skeletonsAreSimilar(String,String)",
396       "method:android.icu.text.DateTimePatternGenerator$FormatParser#FormatParser()",
397       "method:android.icu.text.DateTimePatternGenerator$FormatParser#getItems()",
398       "method:android.icu.text.DateTimePatternGenerator$FormatParser#hasDateAndTimeFields()",
399       "method:android.icu.text.DateTimePatternGenerator$FormatParser#quoteLiteral(String)",
400       "method:android.icu.text.DateTimePatternGenerator$FormatParser#set(String)",
401       "method:android.icu.text.DateTimePatternGenerator$FormatParser#set(String,boolean)",
402       "method:android.icu.text.DateTimePatternGenerator$FormatParser#toString()",
403       "method:android.icu.text.DateTimePatternGenerator$FormatParser#toString(int,int)",
404       "method:android.icu.text.DateTimePatternGenerator$VariableField#VariableField(String)",
405       "method:android.icu.text.DateTimePatternGenerator$VariableField#VariableField(String,boolean)",
406       "method:android.icu.text.DateTimePatternGenerator$VariableField#getCanonicalCode(int)",
407       "method:android.icu.text.DateTimePatternGenerator$VariableField#getType()",
408       "method:android.icu.text.DateTimePatternGenerator$VariableField#isNumeric()",
409       "method:android.icu.text.DateTimePatternGenerator$VariableField#toString()",
410       "method:android.icu.text.DecimalFormat#getEffectiveCurrency()",
411       "method:android.icu.text.DecimalFormatSymbols#getMinusString()",
412       "method:android.icu.text.DecimalFormatSymbols#getPlusString()",
413       "method:android.icu.text.IDNA#IDNA()",
414       "method:android.icu.text.IDNA#addError(Info,Error)",
415       "method:android.icu.text.IDNA#addLabelError(Info,Error)",
416       "method:android.icu.text.IDNA#compare(String,String,int)",
417       "method:android.icu.text.IDNA#compare(StringBuffer,StringBuffer,int)",
418       "method:android.icu.text.IDNA#compare(UCharacterIterator,UCharacterIterator,int)",
419       "method:android.icu.text.IDNA#convertIDNToASCII(String,int)",
420       "method:android.icu.text.IDNA#convertIDNToASCII(StringBuffer,int)",
421       "method:android.icu.text.IDNA#convertIDNToASCII(UCharacterIterator,int)",
422       "method:android.icu.text.IDNA#convertIDNToUnicode(String,int)",
423       "method:android.icu.text.IDNA#convertIDNToUnicode(StringBuffer,int)",
424       "method:android.icu.text.IDNA#convertIDNToUnicode(UCharacterIterator,int)",
425       "method:android.icu.text.IDNA#convertToASCII(String,int)",
426       "method:android.icu.text.IDNA#convertToASCII(StringBuffer,int)",
427       "method:android.icu.text.IDNA#convertToASCII(UCharacterIterator,int)",
428       "method:android.icu.text.IDNA#convertToUnicode(String,int)",
429       "method:android.icu.text.IDNA#convertToUnicode(StringBuffer,int)",
430       "method:android.icu.text.IDNA#convertToUnicode(UCharacterIterator,int)",
431       "method:android.icu.text.IDNA#hasCertainErrors(Info,EnumSet<Error>)",
432       "method:android.icu.text.IDNA#hasCertainLabelErrors(Info,EnumSet<Error>)",
433       "method:android.icu.text.IDNA#isBiDi(Info)",
434       "method:android.icu.text.IDNA#isOkBiDi(Info)",
435       "method:android.icu.text.IDNA#promoteAndResetLabelErrors(Info)",
436       "method:android.icu.text.IDNA#resetInfo(Info)",
437       "method:android.icu.text.IDNA#setBiDi(Info)",
438       "method:android.icu.text.IDNA#setNotOkBiDi(Info)",
439       "method:android.icu.text.IDNA#setTransitionalDifferent(Info)",
440       "method:android.icu.text.LocaleDisplayNames#LocaleDisplayNames()",
441       "method:android.icu.text.LocaleDisplayNames#scriptDisplayNameInContext(String)",
442       "method:android.icu.text.MeasureFormat#formatMeasureRange(Measure,Measure)",
443       "method:android.icu.text.MeasureFormat#getRangeFormat(ULocale,FormatWidth)",
444       "method:android.icu.text.MeasureFormat#getRangePattern(ULocale,FormatWidth)",
445       "method:android.icu.text.Normalizer#Normalizer(CharacterIterator,Mode,int)",
446       "method:android.icu.text.Normalizer#Normalizer(String,Mode,int)",
447       "method:android.icu.text.Normalizer#Normalizer(UCharacterIterator,Mode,int)",
448       "method:android.icu.text.Normalizer#clone()",
449       "method:android.icu.text.Normalizer#compose(String,boolean)",
450       "method:android.icu.text.Normalizer#compose(String,boolean,int)",
451       "method:android.icu.text.Normalizer#compose(char[],char[],boolean,int)",
452       "method:android.icu.text.Normalizer#compose(char[],int,int,char[],int,int,boolean,int)",
453       "method:android.icu.text.Normalizer#concatenate(String,String,Mode,int)",
454       "method:android.icu.text.Normalizer#concatenate(char[],char[],Mode,int)",
455       "method:android.icu.text.Normalizer#concatenate(char[],int,int,char[],int,int,char[],int,int,Normalizer.Mode,int)",
456       "method:android.icu.text.Normalizer#current()",
457       "method:android.icu.text.Normalizer#decompose(String,boolean)",
458       "method:android.icu.text.Normalizer#decompose(String,boolean,int)",
459       "method:android.icu.text.Normalizer#decompose(char[],char[],boolean,int)",
460       "method:android.icu.text.Normalizer#decompose(char[],int,int,char[],int,int,boolean,int)",
461       "method:android.icu.text.Normalizer#endIndex()",
462       "method:android.icu.text.Normalizer#first()",
463       "method:android.icu.text.Normalizer#getBeginIndex()",
464       "method:android.icu.text.Normalizer#getEndIndex()",
465       "method:android.icu.text.Normalizer#getFC_NFKC_Closure(int)",
466       "method:android.icu.text.Normalizer#getFC_NFKC_Closure(int,char[])",
467       "method:android.icu.text.Normalizer#getIndex()",
468       "method:android.icu.text.Normalizer#getLength()",
469       "method:android.icu.text.Normalizer#getMode()",
470       "method:android.icu.text.Normalizer#getOption(int)",
471       "method:android.icu.text.Normalizer#getText()",
472       "method:android.icu.text.Normalizer#getText(char[])",
473       "method:android.icu.text.Normalizer#isNormalized(String,Mode,int)",
474       "method:android.icu.text.Normalizer#isNormalized(char[],int,int,Mode,int)",
475       "method:android.icu.text.Normalizer#isNormalized(int,Mode,int)",
476       "method:android.icu.text.Normalizer#last()",
477       "method:android.icu.text.Normalizer#next()",
478       "method:android.icu.text.Normalizer#normalize(String,Mode)",
479       "method:android.icu.text.Normalizer#normalize(String,Mode,int)",
480       "method:android.icu.text.Normalizer#normalize(char[],char[],Mode,int)",
481       "method:android.icu.text.Normalizer#normalize(char[],int,int,char[],int,int,Mode,int)",
482       "method:android.icu.text.Normalizer#normalize(int,Mode)",
483       "method:android.icu.text.Normalizer#normalize(int,Mode,int)",
484       "method:android.icu.text.Normalizer#previous()",
485       "method:android.icu.text.Normalizer#quickCheck(String,Mode)",
486       "method:android.icu.text.Normalizer#quickCheck(String,Mode,int)",
487       "method:android.icu.text.Normalizer#quickCheck(char[],Mode,int)",
488       "method:android.icu.text.Normalizer#quickCheck(char[],int,int,Mode,int)",
489       "method:android.icu.text.Normalizer#reset()",
490       "method:android.icu.text.Normalizer#setIndex(int)",
491       "method:android.icu.text.Normalizer#setIndexOnly(int)",
492       "method:android.icu.text.Normalizer#setMode(Mode)",
493       "method:android.icu.text.Normalizer#setOption(int,boolean)",
494       "method:android.icu.text.Normalizer#setText(CharacterIterator)",
495       "method:android.icu.text.Normalizer#setText(String)",
496       "method:android.icu.text.Normalizer#setText(StringBuffer)",
497       "method:android.icu.text.Normalizer#setText(UCharacterIterator)",
498       "method:android.icu.text.Normalizer#setText(char[])",
499       "method:android.icu.text.Normalizer#startIndex()",
500       "method:android.icu.text.Normalizer$Mode#Mode()",
501       "method:android.icu.text.Normalizer$Mode#getNormalizer2(int)",
502       "method:android.icu.text.Normalizer2#Normalizer2()",
503       "method:android.icu.text.NumberFormat#getEffectiveCurrency()",
504       "method:android.icu.text.NumberFormat#getPattern(Locale,int)",
505       "method:android.icu.text.PluralFormat#setLocale(ULocale)",
506       "method:android.icu.text.PluralRules#addSample(String,Number,int,Set<Double>)",
507       "method:android.icu.text.PluralRules#compareTo(PluralRules)",
508       "method:android.icu.text.PluralRules#computeLimited(String,SampleType)",
509       "method:android.icu.text.PluralRules#getAllKeywordValues(String,SampleType)",
510       "method:android.icu.text.PluralRules#getDecimalSamples(String,SampleType)",
511       "method:android.icu.text.PluralRules#getKeywordStatus(String,int,Set<Double>,Output<Double>,SampleType)",
512       "method:android.icu.text.PluralRules#getRules(String)",
513       "method:android.icu.text.PluralRules#getSamples(String,SampleType)",
514       "method:android.icu.text.PluralRules#hashCode()",
515       "method:android.icu.text.PluralRules#isLimited(String)",
516       "method:android.icu.text.PluralRules#isLimited(String,SampleType)",
517       "method:android.icu.text.PluralRules#matches(FixedDecimal,String)",
518       "method:android.icu.text.PluralRules#select(FixedDecimal)",
519       "method:android.icu.text.PluralRules#select(double,int,long)",
520       "method:android.icu.text.PluralRules$Factory#Factory()",
521       "method:android.icu.text.PluralRules$Factory#forLocale(ULocale)",
522       "method:android.icu.text.PluralRules$Factory#forLocale(ULocale,PluralType)",
523       "method:android.icu.text.PluralRules$Factory#getAvailableULocales()",
524       "method:android.icu.text.PluralRules$Factory#getDefaultFactory()",
525       "method:android.icu.text.PluralRules$Factory#getFunctionalEquivalent(ULocale,boolean[])",
526       "method:android.icu.text.PluralRules$Factory#hasOverride(ULocale)",
527       "method:android.icu.text.PluralRules$FixedDecimal#FixedDecimal(String)",
528       "method:android.icu.text.PluralRules$FixedDecimal#FixedDecimal(double)",
529       "method:android.icu.text.PluralRules$FixedDecimal#FixedDecimal(double,int)",
530       "method:android.icu.text.PluralRules$FixedDecimal#FixedDecimal(double,int,long)",
531       "method:android.icu.text.PluralRules$FixedDecimal#FixedDecimal(long)",
532       "method:android.icu.text.PluralRules$FixedDecimal#compareTo(FixedDecimal)",
533       "method:android.icu.text.PluralRules$FixedDecimal#decimals(double)",
534       "method:android.icu.text.PluralRules$FixedDecimal#doubleValue()",
535       "method:android.icu.text.PluralRules$FixedDecimal#equals(Object)",
536       "method:android.icu.text.PluralRules$FixedDecimal#floatValue()",
537       "method:android.icu.text.PluralRules$FixedDecimal#get(Operand)",
538       "method:android.icu.text.PluralRules$FixedDecimal#getBaseFactor()",
539       "method:android.icu.text.PluralRules$FixedDecimal#getDecimalDigits()",
540       "method:android.icu.text.PluralRules$FixedDecimal#getDecimalDigitsWithoutTrailingZeros()",
541       "method:android.icu.text.PluralRules$FixedDecimal#getIntegerValue()",
542       "method:android.icu.text.PluralRules$FixedDecimal#getOperand(String)",
543       "method:android.icu.text.PluralRules$FixedDecimal#getShiftedValue()",
544       "method:android.icu.text.PluralRules$FixedDecimal#getSource()",
545       "method:android.icu.text.PluralRules$FixedDecimal#getVisibleDecimalDigitCount()",
546       "method:android.icu.text.PluralRules$FixedDecimal#getVisibleDecimalDigitCountWithoutTrailingZeros()",
547       "method:android.icu.text.PluralRules$FixedDecimal#hasIntegerValue()",
548       "method:android.icu.text.PluralRules$FixedDecimal#hashCode()",
549       "method:android.icu.text.PluralRules$FixedDecimal#intValue()",
550       "method:android.icu.text.PluralRules$FixedDecimal#isHasIntegerValue()",
551       "method:android.icu.text.PluralRules$FixedDecimal#isNegative()",
552       "method:android.icu.text.PluralRules$FixedDecimal#longValue()",
553       "method:android.icu.text.PluralRules$FixedDecimal#toString()",
554       "method:android.icu.text.PluralRules$FixedDecimalRange#FixedDecimalRange(FixedDecimal,FixedDecimal)",
555       "method:android.icu.text.PluralRules$FixedDecimalRange#toString()",
556       "method:android.icu.text.PluralRules$FixedDecimalSamples#addSamples(Set<Double>)",
557       "method:android.icu.text.PluralRules$FixedDecimalSamples#getSamples()",
558       "method:android.icu.text.PluralRules$FixedDecimalSamples#getStartEndSamples(Set<FixedDecimal>)",
559       "method:android.icu.text.PluralRules$FixedDecimalSamples#toString()",
560       "method:android.icu.text.RuleBasedCollator#doCompare(CharSequence,CharSequence)",
561       "method:android.icu.text.RuleBasedCollator#internalGetCEs(CharSequence)",
562       "method:android.icu.text.RuleBasedCollator#isHiraganaQuaternary()",
563       "method:android.icu.text.RuleBasedCollator#setHiraganaQuaternary(boolean)",
564       "method:android.icu.text.RuleBasedCollator#setHiraganaQuaternaryDefault()",
565       "method:android.icu.text.RuleBasedCollator#setVariableTop(String)",
566       "method:android.icu.text.RuleBasedCollator#setVariableTop(int)",
567       "method:android.icu.text.SearchIterator#setMatchNotFound()",
568       "method:android.icu.text.SimpleDateFormat#SimpleDateFormat(String,DateFormatSymbols,ULocale)",
569       "method:android.icu.text.SimpleDateFormat#getInstance(Calendar.FormatConfiguration)",
570       "method:android.icu.text.SimpleDateFormat#intervalFormatByAlgorithm(Calendar,Calendar,StringBuffer,FieldPosition)",
571       "method:android.icu.text.SimpleDateFormat#subFormat(StringBuffer,char,int,int,int,DisplayContext,FieldPosition,Calendar)",
572       "method:android.icu.text.SimpleDateFormat#subFormat(char,int,int,int,DisplayContext,FieldPosition,Calendar)",
573       "method:android.icu.text.SimpleDateFormat#zeroPaddingNumber(NumberFormat,StringBuffer,int,int,int)",
574       "method:android.icu.text.StringPrepParseException#hashCode()",
575       "method:android.icu.text.StringSearch#setMatchNotFound()",
576       "method:android.icu.text.TimeZoneNames#getDisplayNames(String,NameType[],long,String[],int)",
577       "method:android.icu.text.TimeZoneNames#loadAllDisplayNames()",
578       "method:android.icu.text.TimeZoneNames$Factory#Factory()",
579       "method:android.icu.text.TimeZoneNames$Factory#getTimeZoneNames(ULocale)",
580       "method:android.icu.text.UnicodeFilter#UnicodeFilter()",
581       "method:android.icu.text.UnicodeSet#addBridges(UnicodeSet)",
582       "method:android.icu.text.UnicodeSet#applyPattern(String,ParsePosition,SymbolTable,int)",
583       "method:android.icu.text.UnicodeSet#compare(Iterator<T>,Iterator<T>)",
584       "method:android.icu.text.UnicodeSet#findIn(CharSequence,int,boolean)",
585       "method:android.icu.text.UnicodeSet#findLastIn(CharSequence,int,boolean)",
586       "method:android.icu.text.UnicodeSet#getDefaultXSymbolTable()",
587       "method:android.icu.text.UnicodeSet#getRegexEquivalent()",
588       "method:android.icu.text.UnicodeSet#getSingleCodePoint(CharSequence)",
589       "method:android.icu.text.UnicodeSet#matchesAt(CharSequence,int)",
590       "method:android.icu.text.UnicodeSet#setDefaultXSymbolTable(XSymbolTable)",
591       "method:android.icu.text.UnicodeSet#spanAndCount(CharSequence,int,SpanCondition,OutputInt)",
592       "method:android.icu.text.UnicodeSet#stripFrom(CharSequence,boolean)",
593       "method:android.icu.text.UnicodeSetIterator#getSet()",
594       "method:android.icu.text.UnicodeSetIterator#loadRange(int)",
595       "method:android.icu.text.Transliterator#addSourceTargetSet(UnicodeSet,UnicodeSet,UnicodeSet)",
596       "method:android.icu.text.Transliterator#getFilterAsUnicodeSet(UnicodeSet)",
597       "method:android.icu.text.Transliterator#registerAny()",
598       "method:android.icu.util.Calendar#getDateTimePattern(Calendar,ULocale,int)",
599       "method:android.icu.util.Calendar#getDayOfWeekType(int)",
600       "method:android.icu.util.Calendar#getRelatedYear()",
601       "method:android.icu.util.Calendar#getWeekendTransition(int)",
602       "method:android.icu.util.Calendar#haveDefaultCentury()",
603       "method:android.icu.util.Calendar#setRelatedYear(int)",
604       "method:android.icu.util.Calendar$FormatConfiguration#getCalendar()",
605       "method:android.icu.util.Calendar$FormatConfiguration#getDateFormatSymbols()",
606       "method:android.icu.util.Calendar$FormatConfiguration#getLocale()",
607       "method:android.icu.util.Calendar$FormatConfiguration#getOverrideString()",
608       "method:android.icu.util.Calendar$FormatConfiguration#getPatternString()",
609       "method:android.icu.util.ChineseCalendar#ChineseCalendar(TimeZone,ULocale,int,TimeZone)",
610       "method:android.icu.util.ChineseCalendar#haveDefaultCentury()",
611       "method:android.icu.util.CopticCalendar#getJDEpochOffset()",
612       "method:android.icu.util.CopticCalendar#handleComputeFields(int)",
613       "method:android.icu.util.CopticCalendar#handleGetExtendedYear()",
614       "method:android.icu.util.Currency#parse(ULocale,String,int,ParsePosition)",
615       "method:android.icu.util.HebrewCalendar#isLeapYear(int)",
616       "method:android.icu.util.HebrewCalendar#validateField(int)",
617       "method:android.icu.util.JapaneseCalendar#haveDefaultCentury()",
618       "method:android.icu.util.MeasureUnit#MeasureUnit(String,String)",
619       "method:android.icu.util.MeasureUnit#addUnit(String,String,Factory)",
620       "method:android.icu.util.MeasureUnit#internalGetInstance(String,String)",
621       "method:android.icu.util.MeasureUnit#resolveUnitPerUnit(MeasureUnit,MeasureUnit)",
622       "method:android.icu.util.MeasureUnit$Factory#create(String,String)",
623       "method:android.icu.util.TimeZone#TimeZone(String)",
624       "method:android.icu.util.ULocale#getDisplayScriptInContext()",
625       "method:android.icu.util.ULocale#getDisplayScriptInContext(String,String)",
626       "method:android.icu.util.ULocale#getDisplayScriptInContext(String,ULocale)",
627       "method:android.icu.util.ULocale#getDisplayScriptInContext(ULocale)",
628       "method:android.icu.util.ULocale#minimizeSubtags(ULocale,Minimize)",
629       "method:android.icu.util.VersionInfo#getVersionString(int,int)",
630       "method:android.icu.util.VersionInfo#javaVersion()",
631       "type:android.icu.text.DateTimePatternGenerator$FormatParser",
632       "type:android.icu.text.DateTimePatternGenerator$VariableField",
633       "type:android.icu.text.Normalizer$Mode",
634       "type:android.icu.text.PluralRules$Factory",
635       "type:android.icu.text.PluralRules$FixedDecimal",
636       "type:android.icu.text.PluralRules$FixedDecimalRange",
637       "type:android.icu.text.PluralRules$FixedDecimalSamples",
638       "type:android.icu.text.PluralRules$SampleType",
639       "type:android.icu.text.PluralRules$StandardPluralCategories",
640       "type:android.icu.text.TimeZoneNames$Factory",
641       "type:android.icu.util.Calendar$FormatConfiguration",
642       "type:android.icu.util.MeasureUnit$Factory",
643       "type:android.icu.util.ULocale$Minimize",
644   };
645 
646   /**
647    * A set of declarations we don't want to expose in Android.
648    * We generally hide:
649    * Any API we find that relates to a final static primitive that a compiler could inline
650    * and could change between ICU releases.
651    * Methods that relate to registration of static defaults / factories, which cannot be
652    * configured on Android "before use", because a lot of initialization happens in the zygote.
653    */
654   private static final String[] DECLARATIONS_TO_HIDE = {
655       /* ASCII order please. */
656       "field:android.icu.lang.UCharacter$BidiPairedBracketType#COUNT",
657       "field:android.icu.lang.UCharacter$DecompositionType#COUNT",
658       "field:android.icu.lang.UCharacter$EastAsianWidth#COUNT",
659       "field:android.icu.lang.UCharacter$GraphemeClusterBreak#COUNT",
660       "field:android.icu.lang.UCharacter$HangulSyllableType#COUNT",
661       "field:android.icu.lang.UCharacter$JoiningGroup#COUNT",
662       "field:android.icu.lang.UCharacter$JoiningType#COUNT",
663       "field:android.icu.lang.UCharacter$LineBreak#COUNT",
664       "field:android.icu.lang.UCharacter$NumericType#COUNT",
665       "field:android.icu.lang.UCharacter$SentenceBreak#COUNT",
666       "field:android.icu.lang.UCharacter$UnicodeBlock#COUNT",
667       "field:android.icu.lang.UCharacter$WordBreak#COUNT",
668       "field:android.icu.lang.UCharacterEnums$ECharacterCategory#CHAR_CATEGORY_COUNT",
669       "field:android.icu.lang.UCharacterEnums$ECharacterDirection#CHAR_DIRECTION_COUNT",
670       "field:android.icu.lang.UProperty#BINARY_LIMIT",
671       "field:android.icu.lang.UProperty#DOUBLE_LIMIT",
672       "field:android.icu.lang.UProperty#INT_LIMIT",
673       "field:android.icu.lang.UProperty#MASK_LIMIT",
674       "field:android.icu.lang.UProperty#OTHER_PROPERTY_LIMIT",
675       "field:android.icu.lang.UProperty#STRING_LIMIT",
676       "field:android.icu.lang.UProperty$NameChoice#COUNT",
677       "field:android.icu.lang.UScript#CODE_LIMIT",
678       "field:android.icu.text.BidiClassifier#context",
679       "field:android.icu.text.CollationKey$BoundMode#COUNT",
680       "field:android.icu.text.Collator$ReorderCodes#LIMIT",
681       "field:android.icu.text.DateFormat#FIELD_COUNT",
682       "field:android.icu.text.DateTimePatternGenerator#TYPE_LIMIT",
683       "field:android.icu.util.LocaleData#ES_AUXILIARY",
684       "field:android.icu.util.LocaleData#ES_INDEX",
685       "field:android.icu.util.LocaleData#ES_PUNCTUATION",
686       "field:android.icu.util.LocaleData#ES_STANDARD",
687       // Hide new measure units until a clear use case on Android is found.
688       // The cost of these APIs is the storage due to the additional locale data embedded
689       // in the ICU data file.
690       "field:android.icu.util.MeasureUnit#DUNAM",
691       "field:android.icu.util.MeasureUnit#MOLE",
692       "field:android.icu.util.MeasureUnit#PERMYRIAD",
693       "field:android.icu.util.MeasureUnit#DAY_PERSON",
694       "field:android.icu.util.MeasureUnit#MONTH_PERSON",
695       "field:android.icu.util.MeasureUnit#WEEK_PERSON",
696       "field:android.icu.util.MeasureUnit#YEAR_PERSON",
697       "field:android.icu.util.MeasureUnit#BRITISH_THERMAL_UNIT",
698       "field:android.icu.util.MeasureUnit#ELECTRONVOLT",
699       "field:android.icu.util.MeasureUnit#NEWTON",
700       "field:android.icu.util.MeasureUnit#POUND_FORCE",
701       "field:android.icu.util.MeasureUnit#SOLAR_RADIUS",
702       "field:android.icu.util.MeasureUnit#SOLAR_LUMINOSITY",
703       "field:android.icu.util.MeasureUnit#DALTON",
704       "field:android.icu.util.MeasureUnit#EARTH_MASS",
705       "field:android.icu.util.MeasureUnit#SOLAR_MASS",
706       "field:android.icu.util.MeasureUnit#KILOPASCAL",
707       "field:android.icu.util.MeasureUnit#MEGAPASCAL",
708       "field:android.icu.util.MeasureUnit#NEWTON_METER",
709       "field:android.icu.util.MeasureUnit#POUND_FOOT",
710       "field:android.icu.util.MeasureUnit#BARREL",
711       "field:android.icu.util.MeasureUnit#FLUID_OUNCE_IMPERIAL",
712       "field:android.icu.util.MeasureUnit#BAR",
713       "field:android.icu.util.MeasureUnit#PASCAL",
714       "field:android.icu.util.MeasureUnit#THERM_US",
715       "field:android.icu.util.MeasureUnit#EARTH_RADIUS",
716       "field:android.icu.util.MeasureUnit#GRAIN",
717       "field:android.icu.util.MeasureUnit#DESSERT_SPOON",
718       "field:android.icu.util.MeasureUnit#DESSERT_SPOON_IMPERIAL",
719       "field:android.icu.util.MeasureUnit#DRAM",
720       "field:android.icu.util.MeasureUnit#DROP",
721       "field:android.icu.util.MeasureUnit#JIGGER",
722       "field:android.icu.util.MeasureUnit#PINCH",
723       "field:android.icu.util.MeasureUnit#QUART_IMPERIAL",
724       // Skeleton syntax can evolve over time. Currently, the skeleton APIs are not prioritized to
725       // be public. Android developers could easily miss the API version check for new syntax and
726       // cause app crashing on older devices.
727       // See the syntax details in https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md.
728       "method:android.icu.number.NumberFormatterSettings#toSkeleton()",
729       "method:android.icu.number.NumberFormatter#forSkeleton(String)",
730       "method:android.icu.text.BreakIterator#registerInstance(BreakIterator,Locale,int)",
731       "method:android.icu.text.BreakIterator#registerInstance(BreakIterator,ULocale,int)",
732       "method:android.icu.text.BreakIterator#unregister(Object)",
733       "method:android.icu.text.CollationKey#CollationKey(String,RawCollationKey)",
734       "method:android.icu.text.Collator#getRawCollationKey(String,RawCollationKey)",
735       "method:android.icu.text.Collator#registerFactory(CollatorFactory)",
736       "method:android.icu.text.Collator#registerInstance(Collator,ULocale)",
737       "method:android.icu.text.Collator#unregister(Object)",
738       "method:android.icu.text.DecimalFormat#toNumberFormatter()",
739       "method:android.icu.text.DecimalFormatSymbols#getCurrencyPattern()",
740       "method:android.icu.text.NumberFormat#registerFactory(NumberFormatFactory)",
741       "method:android.icu.text.NumberFormat#unregister(Object)",
742       "method:android.icu.text.RuleBasedCollator#getRawCollationKey(String,RawCollationKey)",
743       "method:android.icu.text.UnicodeSet#addAllTo(Iterable<T>,T[])",
744       "method:android.icu.text.UnicodeSet#addAllTo(Iterable<T>,U)",
745       "method:android.icu.text.UnicodeSet#addAllTo(String[])",
746       "method:android.icu.text.UnicodeSet#compare(CharSequence,int)",
747       "method:android.icu.text.UnicodeSet#compare(Collection<T>,Collection<T>,ComparisonStyle)",
748       "method:android.icu.text.UnicodeSet#compare(Iterable<T>,Iterable<T>)",
749       "method:android.icu.text.UnicodeSet#compare(int,CharSequence)",
750       "method:android.icu.text.UnicodeSet#resemblesPattern(String,int)",
751       "method:android.icu.text.UnicodeSet#toArray(UnicodeSet)",
752       "method:android.icu.text.Transliterator#Transliterator(String,UnicodeFilter)",
753       "method:android.icu.text.Transliterator#baseToRules(boolean)",
754       "method:android.icu.text.Transliterator#handleGetSourceSet()",
755       "method:android.icu.text.Transliterator#handleTransliterate(Replaceable,Position,boolean)",
756       "method:android.icu.text.Transliterator#registerAlias(String,String)",
757       "method:android.icu.text.Transliterator#registerClass(String,Class<? extends Transliterator>,String)",
758       "method:android.icu.text.Transliterator#registerFactory(String,Factory)",
759       "method:android.icu.text.Transliterator#registerInstance(Transliterator)",
760       "method:android.icu.text.Transliterator#transform(String)",
761       "method:android.icu.text.Transliterator#unregister(String)",
762       "method:android.icu.text.Transliterator#setID(String)",
763       "method:android.icu.text.Transliterator#setMaximumContextLength(int)",
764       "method:android.icu.util.CECalendar#ceToJD(long,int,int,int)",
765       "method:android.icu.util.CECalendar#getJDEpochOffset()",
766       "method:android.icu.util.CECalendar#jdToCE(int,int,int[])",
767       "method:android.icu.util.Currency#registerInstance(Currency,ULocale)",
768       "method:android.icu.util.Currency#unregister(Object)",
769       "method:android.icu.util.IslamicCalendar#isCivil()",
770       "method:android.icu.util.IslamicCalendar#setCivil(boolean)",
771       "method:android.icu.util.LocaleData#getExemplarSet(int,int)",
772       "method:android.icu.util.LocaleData#getExemplarSet(ULocale,int)",
773       "method:android.icu.util.LocaleData#getExemplarSet(ULocale,int,int)",
774       "method:android.icu.util.LocaleData#getLocaleDisplayPattern()",
775       "method:android.icu.util.LocaleData#getLocaleSeparator()",
776       "method:android.icu.util.TimeZone#clearCachedDefault()",
777       "method:android.icu.util.TimeZone#getDefaultTimeZoneType()",
778       "method:android.icu.util.TimeZone#setDefault(TimeZone)",
779       "method:android.icu.util.TimeZone#setDefaultTimeZoneType(int)",
780       "method:android.icu.util.ULocale#setDefault(Category,ULocale)",
781       "method:android.icu.util.ULocale#setDefault(ULocale)",
782       "method:android.icu.util.VersionInfo#main(String[])",
783       "type:android.icu.text.Collator$CollatorFactory",
784       "type:android.icu.text.NumberFormat$NumberFormatFactory",
785       "type:android.icu.text.NumberFormat$SimpleNumberFormatFactory",
786   };
787 
788   /**
789    * ICU APIs that are in the Android SDK API but are deprecated on Android and not deprecated in
790    * ICU. Entries can be removed if ICU also decide to deprecate.
791    * Entries are usually the result of Android mistakenly exposing an API, an ICU API problem,
792    * and/or ICU's stability guarantees differing from Android's requirements.
793    */
794   private static final Map<String, String> ANDROID_DEPRECATED_SET = Map.of(
795       /* ASCII order please. */
796 
797       // Unstable "constant" value - different values in different API levels. http://b/77850660.
798       "field:android.icu.util.JapaneseCalendar#CURRENT_ERA",
799           "Use era constants, e.g. {@link #REIWA}, instead.",
800       // The method reads unstable .nrm file format. http://b/173821060
801       "method:android.icu.text.Normalizer2#getInstance(InputStream,String,Mode)",
802           "Don't use because the binary {@code data} format is not stable across API levels."
803   );
804 
805   /**
806    * ICU APIs that are in the Android SDK API but are removed on Android and @stable in ICU.
807    * Entries can be removed if ICU also decide to remove the APIs.
808    * Entries are usually the result of Android mistakenly exposing an API, an ICU API problem,
809    * and/or ICU's stability guarantees differing from Android's requirements.
810    */
811   private static final String[] ANDROID_REMOVED_SET = {
812       /* ASCII order please. */
813       // Unstable "constant" value - different values in different API levels. http://b/77850660.
814       "field:android.icu.util.JapaneseCalendar#CURRENT_ERA",
815   };
816 
817   // The declarations with JavaDocs that have @.jcite tags that should be transformed to doclava
818   // @sample tags. Ones not on this list will just be escaped and could show up in the generated
819   // docs. It is assumed that the complete set of ones that should appear in the public API are
820   // listed below and it's ok to escape those that are not.
821   private static final String[] JCITE_TRANSFORM_SET = {
822       "method:android.icu.text.DateIntervalFormat#getInstance(String,Locale)",
823       "method:android.icu.text.DateIntervalFormat#getInstance(String,Locale,DateIntervalInfo)",
824       "method:android.icu.text.DateTimePatternGenerator#addPattern(String,boolean,PatternInfo)",
825       "method:android.icu.text.DateTimePatternGenerator#getBestPattern(String)",
826       "method:android.icu.text.DateTimePatternGenerator#replaceFieldTypes(String,String)",
827       "method:android.icu.text.PluralFormat#PluralFormat(ULocale,String)",
828   };
829 
830   private static final String[] DEFAULT_CONSTRUCTORS = {
831       "android.icu.text.DateTimePatternGenerator$DistanceInfo",
832       "android.icu.text.SpoofChecker$ScriptSet",
833       "android.icu.text.TimeZoneNames$DefaultTimeZoneNames$FactoryImpl",
834   };
835 
836   // Metalava disallows hidden abstract methods in public abstract classes because classes
837   // inheriting such class can cause runtime crashes instead of a compile error. Due to historic
838   // reason, we have such classes in the public SDK. This is the allowlist of hidden abstract
839   // methods, and @SuppressWarnings("HiddenAbstractMethod") annotation will be added into those
840   // methods. See http://b/147445486 for more details.
841   private static final String[] HIDDEN_ABSTRACT_METHODS = {
842       "method:android.icu.text.Collator#getRawCollationKey(String,RawCollationKey)",
843       "method:android.icu.text.Collator#setVariableTop(String)",
844       "method:android.icu.text.Collator#setVariableTop(int)",
845   };
846 
847   public static final String ANDROID_ICU4J_SAMPLE_DIR =
848       "external/icu/android_icu4j/src/samples/java";
849 
850   private static final boolean DEBUG = false;
851 
852   static final String ORIGINAL_ICU_PACKAGE = "com.ibm.icu";
853   static final String ANDROID_ICU_PACKAGE = "android.icu";
854 
Icu4jTransform()855   private Icu4jTransform() {
856   }
857 
858   /**
859    * Usage: See {@link Icu4jRules#COMMAND_USAGE}
860    *
861    * The option --hide-non-allowlisted-api can be used to explicitly describe the API surface to be
862    * exposed; anything not in the list will be hidden in additional to other rules. This is useful
863    * when upgrading ICU when we haven't yet added new classes/methods to various hard-coded lists
864    * described below.
865    *
866    * This tool hides the following in the knowledge that classes that are not explicitly
867    * hidden are exposed in the public API set:
868    *
869    * 1) Public classes that are not in the PUBLIC_API_CLASSES list.
870    * 2) Types / fields / methods that were deprecated when the class was first exposed in Android,
871    *    listed in INITIAL_DEPRECATED_SET
872    * 3) Types / fields / methods that we explicitly want to hide, listed in DECLARATIONS_TO_HIDE
873    * 4) Types / fields / methods that are flagged with ICU javadoc as draft / provisional or
874    *    internal.
875    * 5) If the --hide-non-allowlisted-api option is provided, types / fields / methods that are not
876    *    in the allowlisted-api-file.
877    */
main(String[] args)878   public static void main(String[] args) throws Exception {
879     Map<String, String> options = JavaCore.getOptions();
880     options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
881     options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
882     options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
883     options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
884     options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
885 
886     new Main(DEBUG)
887         .setJdtOptions(options)
888         .execute(new Icu4jRules(args));
889   }
890 
891   static class Icu4jRules implements RuleSet {
892 
893     private static final String SOURCE_CODE_HEADER = "/* GENERATED SOURCE. DO NOT MODIFY. */\n";
894     private static final String COMMAND_USAGE = "Usage: " + Icu4jTransform.class.getCanonicalName()
895             + " [--hide-non-allowlisted-api <allowlisted-api-file>]"
896             + " <source-dir>+ <target-dir> <core-platform-api-file> <intra-core-api-file>"
897             + " <unsupported-app-usage-file>";
898 
899     private final InputFileGenerator inputFileGenerator;
900     private final List<Rule> rules;
901     private final BasicOutputSourceFileGenerator outputSourceFileGenerator;
902 
Icu4jRules(String[] args)903     public Icu4jRules(String[] args) {
904       if (args.length < 3) {
905         throw new IllegalArgumentException(COMMAND_USAGE);
906       }
907       Path allowlistedApiPath = null;
908       if ("--hide-non-allowlisted-api".equals(args[0])) {
909         allowlistedApiPath = Paths.get(args[1]);
910         if (args.length < 6) {
911           throw new IllegalArgumentException(COMMAND_USAGE);
912         }
913         String[] newArgs = new String[args.length - 2];
914         System.arraycopy(args, 2, newArgs, 0, args.length - 2);
915         args = newArgs;
916       }
917 
918       // Extract the source directories.
919       String[] inputDirNames = new String[args.length - 4];
920       System.arraycopy(args, 0, inputDirNames, 0, args.length - 4);
921       inputFileGenerator = Icu4jTransformRules.createInputFileGenerator(inputDirNames);
922 
923       // Extract the additional arguments.
924       int argIndex = inputDirNames.length;
925       String targetDir = args[argIndex++];
926       Path corePlatformApiFile = Paths.get(args[argIndex++]);
927       Path intraCoreApiFile = Paths.get(args[argIndex++]);
928       Path unsupportedAppUsageFile = Paths.get(args[argIndex++]);
929 
930       // Ensure that all the arguments were used.
931       if (argIndex != args.length) {
932         throw new IllegalArgumentException(COMMAND_USAGE);
933       }
934 
935       rules = createTransformRules(corePlatformApiFile, intraCoreApiFile,
936           unsupportedAppUsageFile, allowlistedApiPath);
937       outputSourceFileGenerator = Icu4jTransformRules.createOutputFileGenerator(targetDir);
938     }
939 
940     @Override
getRuleList(File ignored)941     public List<Rule> getRuleList(File ignored) {
942       return rules;
943     }
944 
945     @Override
getInputFileGenerator()946     public InputFileGenerator getInputFileGenerator() {
947       return inputFileGenerator;
948     }
949 
950     @Override
getOutputSourceFileGenerator()951     public OutputSourceFileGenerator getOutputSourceFileGenerator() {
952       return outputSourceFileGenerator;
953     }
954 
955     // Rules for migrating com.ibm.icu source over to android.icu. Pulled out separately so they
956     // can be used for modifying ICU4J sample code as well.
getRepackagingRules()957     static Rule[] getRepackagingRules() {
958       return new Rule[] {
959           // Doc change: Insert a warning about the source code being generated.
960           createMandatoryRule(new InsertHeader(SOURCE_CODE_HEADER)),
961           // AST change: Change the package of each CompilationUnit from com.ibm.icu to android.icu.
962           createMandatoryRule(new RenamePackage(ORIGINAL_ICU_PACKAGE, ANDROID_ICU_PACKAGE)),
963           // AST change: Change all qualified names in code and javadoc.
964           createOptionalRule(new ModifyQualifiedNames(ORIGINAL_ICU_PACKAGE, ANDROID_ICU_PACKAGE)),
965           // AST change: Change all string literals containing package names in code.
966           createOptionalRule(new ModifyStringLiterals(ORIGINAL_ICU_PACKAGE, ANDROID_ICU_PACKAGE)),
967           // AST change: Change all string literals containing paths in code.
968           createOptionalRule(new ModifyStringLiterals("com/ibm/icu", "android/icu")),
969       };
970     }
971 
createTransformRules(Path corePlatformApiFile, Path intraCoreApiFile, Path unsupportedAppUsagePath, Path allowlistedApiPath)972     private static List<Rule> createTransformRules(Path corePlatformApiFile,
973             Path intraCoreApiFile,
974             Path unsupportedAppUsagePath,
975             Path allowlistedApiPath) {
976       // The rules needed to repackage source code that declares or references com.ibm.icu code
977       // so it references android.icu instead.
978       Rule[] repackageRules = getRepackagingRules();
979 
980       // The rules needed to fix up Android's documentation rules.
981       Rule[] apiDocsRules = new Rule[] {
982           // Below are the fixes that ensure the Android API documentation generation can be run
983           // over the source.
984 
985           // Doc change: Switch all documentation references from com.ibm.icu to android.icu.
986           // e.g. importantly in <code> blocks and unimportantly in non-Javadoc comments.
987           createOptionalRule(
988               new ReplaceTextCommentScanner(ORIGINAL_ICU_PACKAGE, ANDROID_ICU_PACKAGE)),
989 
990           // AST change: Hide all ICU public classes except those in the PUBLIC_API_CLASSES
991           // allowlist.
992           createHidePublicClassesRule(),
993 
994           // AST change: Hide ICU methods that are in INITIAL_DEPRECATED_SET and Android does not
995           // want to make public.
996           createHideOriginalDeprecatedClassesRule(),
997           // AST change: Explicitly hide blocklisted methods in DECLARATIONS_TO_HIDE such as those
998           // that get/set static default values that might lead to confusion or strange interactions
999           // between Android's ICU4J and java.text / java.util classes.
1000           createHideBlocklistedDeclarationsRule(),
1001           // AST change: Explicitly hide any elements that are marked as
1002           // @draft / @provisional / @internal
1003           createOptionalRule(new HideDraftProvisionalInternal()),
1004 
1005           // AST change: Hide new non-allowlisted API in Android temporarily
1006           // Usually used for avoiding the new API introduced by upstream to show up in Android.
1007           createHideNonAllowlistedRule(allowlistedApiPath),
1008 
1009           // AST change: Add @Deprecated annotation and @deprecated doc to deprecated API in Android
1010           createMarkElementsWithDeprecatedAnnotationRule(),
1011           createMarkElementsWithDeprecatedJavadocTagRule(),
1012 
1013           // AST change: Add @removed doc to removed API in Android
1014           createMarkElementsWithRemovedJavadocTagRule(),
1015 
1016 
1017           // AST change: Remove JavaDoc tags that Android has no need of:
1018           // @hide has been added in place of @draft, @provisional and @internal
1019           // @stable <ICU version> will not mean much on Android.
1020           createOptionalRule(new RemoveJavaDocTags(
1021               "@stable", "@draft", "@provisional", "@internal", "@since")),
1022           // AST change: Replace @icu and @icuenhanced with standard text.
1023           createOptionalRule(new ReplaceIcuTags()),
1024 
1025           // AST change: Translate some of the @.jcite tags used by ICU into @sample tags used by
1026           // doclava. Those that are not translated are escaped.
1027           createTranslateJciteInclusionRule(),
1028 
1029           // AST change: Add CorePlatformApi to specified classes and members
1030           createOptionalRule(AddAnnotation.markerAnnotationFromFlatFile(
1031               "libcore.api.CorePlatformApi", corePlatformApiFile)),
1032 
1033           // AST change: Add CorePlatformApi to specified classes and members
1034           createOptionalRule(AddAnnotation.markerAnnotationFromFlatFile(
1035               "libcore.api.IntraCoreApi", intraCoreApiFile)),
1036 
1037           // AST change: Add default constructors, must come before processor to add
1038           // UnsupportedAppUsage.
1039           createOptionalRule(new AddDefaultConstructor(
1040               TypeLocator.createLocatorsFromStrings(DEFAULT_CONSTRUCTORS))),
1041 
1042           // AST change: Add UnsupportedAppUsage to specified classes and members
1043           createOptionalRule(Annotations.addUnsupportedAppUsage(unsupportedAppUsagePath)),
1044 
1045           // AST change: Add @SuppressWarnings("HiddenAbstractMethod") to specified methods
1046           createHiddenAbstractMethodRule(),
1047       };
1048 
1049       List<Rule> rulesList = Lists.newArrayList(repackageRules);
1050       rulesList.addAll(Arrays.asList(apiDocsRules));
1051       return rulesList;
1052     }
1053 
createTranslateJciteInclusionRule()1054     private static Rule createTranslateJciteInclusionRule() {
1055       List<BodyDeclarationLocator> allowlist =
1056           BodyDeclarationLocators.createLocatorsFromStrings(JCITE_TRANSFORM_SET);
1057       TranslateJcite.InclusionHandler transformer =
1058           new TranslateJcite.InclusionHandler(ANDROID_ICU4J_SAMPLE_DIR, allowlist);
1059       return createOptionalRule(transformer);
1060     }
1061 
createHideOriginalDeprecatedClassesRule()1062     private static Rule createHideOriginalDeprecatedClassesRule() {
1063       List<BodyDeclarationLocator> blocklist =
1064           BodyDeclarationLocators.createLocatorsFromStrings(INITIAL_DEPRECATED_SET);
1065       return createOptionalRule(
1066           new TagMatchingDeclarations(blocklist, "@hide original deprecated declaration"));
1067     }
1068 
createMarkElementsWithDeprecatedAnnotationRule()1069     private static Rule createMarkElementsWithDeprecatedAnnotationRule() {
1070       List<BodyDeclarationLocator> locators =
1071           BodyDeclarationLocators.createLocatorsFromStrings(
1072                   ANDROID_DEPRECATED_SET.keySet().toArray(new String[0]));
1073       return createOptionalRule(AddAnnotation.markerAnnotationFromLocators(
1074           "Deprecated", locators));
1075     }
1076 
createMarkElementsWithDeprecatedJavadocTagRule()1077     private static Rule createMarkElementsWithDeprecatedJavadocTagRule() {
1078       Map<BodyDeclarationLocator, String> locatorTags = ANDROID_DEPRECATED_SET.entrySet().stream()
1079               .collect(Collectors.toMap(
1080                       (entry) -> BodyDeclarationLocators.fromStringForm(entry.getKey()),
1081                       (entry) -> "@deprecated " + entry.getValue())
1082               );
1083       return createOptionalRule(new TagMatchingDeclarations(locatorTags));
1084     }
1085 
createMarkElementsWithRemovedJavadocTagRule()1086     private static Rule createMarkElementsWithRemovedJavadocTagRule() {
1087       List<BodyDeclarationLocator> locators =
1088           BodyDeclarationLocators.createLocatorsFromStrings(ANDROID_REMOVED_SET);
1089       return createOptionalRule(new TagMatchingDeclarations(locators,
1090           "@removed on Android but @stable in ICU"));
1091     }
1092 
createHideBlocklistedDeclarationsRule()1093     private static Rule createHideBlocklistedDeclarationsRule() {
1094       List<BodyDeclarationLocator> blocklist =
1095           BodyDeclarationLocators.createLocatorsFromStrings(DECLARATIONS_TO_HIDE);
1096       return createOptionalRule(
1097           new TagMatchingDeclarations(blocklist, "@hide unsupported on Android"));
1098     }
1099 
createHidePublicClassesRule()1100     private static Rule createHidePublicClassesRule() {
1101       List<TypeLocator> allowlist = TypeLocator.createLocatorsFromStrings(PUBLIC_API_CLASSES);
1102       return createOptionalRule(
1103           new HidePublicClasses(allowlist, "Only a subset of ICU is exposed in Android"));
1104     }
1105 
createHiddenAbstractMethodRule()1106     private static Rule createHiddenAbstractMethodRule() {
1107       List<BodyDeclarationLocator> loactors =
1108               BodyDeclarationLocators.createLocatorsFromStrings(HIDDEN_ABSTRACT_METHODS);
1109       return createOptionalRule(
1110               AddAnnotation.markerAnnotationWithPropertyFromLocators("SuppressWarnings",
1111                       "value", String.class, "HiddenAbstractMethod", loactors));
1112     }
1113   }
1114 
createHideNonAllowlistedRule(Path allowlistedApiPath)1115   private static Rule createHideNonAllowlistedRule(Path allowlistedApiPath) {
1116     List<BodyDeclarationLocator> bodyDeclarationLocators = null;
1117     if (allowlistedApiPath != null) {
1118       bodyDeclarationLocators = BodyDeclarationLocators.readBodyDeclarationLocators(
1119               allowlistedApiPath);
1120     }
1121     return createOptionalRule(new HideNonAllowlistedDeclarations(bodyDeclarationLocators,
1122             "@hide Hide new API in Android temporarily"));
1123   }
1124 }
1125