Make jetifier process @links in xml doc.
Also fixes leanback links as it would now break partial migration.
Bug: b/145673347
Test: Added
Change-Id: Id546f52866212601b87f20362a86061042b8cf1f
diff --git a/jetifier/jetifier/processor/src/main/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformer.kt b/jetifier/jetifier/processor/src/main/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformer.kt
index f8b633d..d72312a 100644
--- a/jetifier/jetifier/processor/src/main/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformer.kt
+++ b/jetifier/jetifier/processor/src/main/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformer.kt
@@ -59,6 +59,8 @@
* Matches xml tags in form of:
* 1. '<(/)prefix(SOMETHING)'.
* 2. <view ... class="prefix(SOMETHING)" ...>
+ * 3. >SOMETHING<
+ * 4. {@link SOMETHING#method()}
*
* Note that this can also rewrite commented blocks of XML. But on a library level we don't care
* much about comments.
@@ -66,7 +68,8 @@
private val patterns = listOf(
Pattern.compile("</?([a-zA-Z0-9.]+)"), // </{candidate} or <{candidate}
Pattern.compile("[a-zA-Z0-9:]+=\"([^\"]+)\""), // any="{candidate}"
- Pattern.compile(">\\s*([a-zA-Z0-9.\$_]+)<") // >{candidate}<
+ Pattern.compile(">\\s*([a-zA-Z0-9.\$_]+)<"), // >{candidate}<
+ Pattern.compile("\\{@link\\s*([a-zA-Z0-9.\$_]+)(#[^}]*)?}") // @{link {candidate}#*}
)
override fun canTransform(file: ArchiveFile) = file.isXmlFile() && !file.isPomFile()
diff --git a/jetifier/jetifier/processor/src/test/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformerTest.kt b/jetifier/jetifier/processor/src/test/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformerTest.kt
index 5e54923..5f9bb29 100644
--- a/jetifier/jetifier/processor/src/test/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformerTest.kt
+++ b/jetifier/jetifier/processor/src/test/kotlin/com/android/tools/build/jetifier/processor/transform/resource/XmlResourcesTransformerTest.kt
@@ -221,6 +221,90 @@
)
}
+ @Test fun link_withoutSuffix_shouldRewrite() {
+ testRewrite(
+ givenXml =
+ "<!-- Comment {@link android.support.Test} -->\n" +
+ "<attr name=\"someAttribute\">",
+ expectedXml =
+ "<!-- Comment {@link androidx.Test} -->\n" +
+ "<attr name=\"someAttribute\">",
+ prefixes = setOf("android/support/"),
+ typesMap = mapOf(
+ "android/support/Test"
+ to "androidx/Test"
+ )
+ )
+ }
+
+ @Test fun link_withInnerClass_shouldRewrite() {
+ testRewrite(
+ givenXml =
+ "<!-- Comment {@link android.support.Test\$R#get(Context, int)} -->\n" +
+ "<attr name=\"someAttribute\">",
+ expectedXml =
+ "<!-- Comment {@link androidx.Test\$R#get(Context, int)} -->\n" +
+ "<attr name=\"someAttribute\">",
+ prefixes = setOf("android/support/"),
+ typesMap = mapOf(
+ "android/support/Test"
+ to "androidx/Test"
+ )
+ )
+ }
+
+ @Test fun link_shouldRewrite() {
+ testRewrite(
+ givenXml =
+ "<!-- Comment {@link android.support.Test#get(Context, int)} -->\n" +
+ "<attr name=\"someAttribute\">",
+ expectedXml =
+ "<!-- Comment {@link androidx.Test#get(Context, int)} -->\n" +
+ "<attr name=\"someAttribute\">",
+ prefixes = setOf("android/support/"),
+ typesMap = mapOf(
+ "android/support/Test"
+ to "androidx/Test"
+ )
+ )
+ }
+
+ @Test fun link_lineBreak_shouldRewrite() {
+ testRewrite(
+ givenXml =
+ "<!-- Comment {@link \n" +
+ "android.support.Test#get(Context, int)} -->\n" +
+ "<attr name=\"someAttribute\">",
+ expectedXml =
+ "<!-- Comment {@link \n" +
+ "androidx.Test#get(Context, int)} -->\n" +
+ "<attr name=\"someAttribute\">",
+ prefixes = setOf("android/support/"),
+ typesMap = mapOf(
+ "android/support/Test"
+ to "androidx/Test"
+ )
+ )
+ }
+
+ @Test fun link_lineBreak2_shouldRewrite() {
+ testRewrite(
+ givenXml =
+ "<!-- Comment {@link android.support.Test#get(Context, int)" +
+ "} -->\n" +
+ "<attr name=\"someAttribute\">",
+ expectedXml =
+ "<!-- Comment {@link androidx.Test#get(Context, int)" +
+ "} -->\n" +
+ "<attr name=\"someAttribute\">",
+ prefixes = setOf("android/support/"),
+ typesMap = mapOf(
+ "android/support/Test"
+ to "androidx/Test"
+ )
+ )
+ }
+
@Test fun manifestFile_packageRewrite() {
testRewrite(
givenXml =
diff --git a/leanback/src/main/res/values/attrs.xml b/leanback/src/main/res/values/attrs.xml
index 79c71a1..92d92bb 100644
--- a/leanback/src/main/res/values/attrs.xml
+++ b/leanback/src/main/res/values/attrs.xml
@@ -386,27 +386,27 @@
<!-- Theme attribute for the animation used when a guided step element is animated in
response to the IME appearing. Default is {@link
- androidx.leanbackback.R.animator#lb_guidedstep_slide_up}. -->
+ androidx.leanback.R.animator#lb_guidedstep_slide_up}. -->
<attr name="guidedStepImeAppearingAnimation" format="reference" />
<!-- Theme attribute for the animation used when a guided step element is animated in
response to the IME disappearing. Default is {@link
- androidx.leanbackback.R.animator#lb_guidedstep_slide_down}. -->
+ androidx.leanback.R.animator#lb_guidedstep_slide_down}. -->
<attr name="guidedStepImeDisappearingAnimation" format="reference" />
<!-- Theme attribute for the style of the main container in a GuidanceStylist. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidanceContainerStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidanceContainerStyle}.-->
<attr name="guidanceContainerStyle" format="reference" />
<!-- Theme attribute for the style of the title in a GuidanceStylist. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidanceTitleStyle}. -->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidanceTitleStyle}. -->
<attr name="guidanceTitleStyle" format="reference" />
<!-- Theme attribute for the style of the description in a GuidanceStylist. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidanceDescriptionStyle}. -->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidanceDescriptionStyle}. -->
<attr name="guidanceDescriptionStyle" format="reference" />
<!-- Theme attribute for the style of the breadcrumb in a GuidanceStylist. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidanceBreadcrumbStyle}. -->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidanceBreadcrumbStyle}. -->
<attr name="guidanceBreadcrumbStyle" format="reference" />
<!-- Theme attribute for the style of the icon in a GuidanceStylist. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidanceIconStyle}. -->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidanceIconStyle}. -->
<attr name="guidanceIconStyle" format="reference" />
<!-- Theme attribute for the style of the item selector in a GuidedActionsPresenter. Default is
@@ -414,97 +414,97 @@
<attr name="guidedActionsSelectorDrawable" format="reference" />
<!-- Theme attribute for the shadow elevation of GuidedActions. Default is
- {@landroidx.leanbackback.R.dimen#lb_guidedactions_elevation}.-->
+ {@landroidx.leanback.R.dimen#lb_guidedactions_elevation}.-->
<attr name="guidedActionsElevation" format="dimension|reference" />
<!-- Theme attribute for the background of GuidedActions. Default is
- {@landroidx.leanbackback.R.color#lb_guidedactions_background}.-->
+ {@landroidx.leanback.R.color#lb_guidedactions_background}.-->
<attr name="guidedActionsBackground" format="reference" />
<!-- Theme attribute for the dark version background of GuidedActions. Default is
- {@landroidx.leanbackback.R.color#lb_guidedactions_background_dark}.-->
+ {@landroidx.leanback.R.color#lb_guidedactions_background_dark}.-->
<attr name="guidedActionsBackgroundDark" format="reference" />
<!-- Theme attribute for the style of the list in a GuidedActionsPresenter. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidedActionsListStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidedActionsListStyle}.-->
<attr name="guidedActionsListStyle" format="reference" />
<!-- Theme attribute for the style of the sub actions list in a GuidedActionsPresenter. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidedSubActionsListStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidedSubActionsListStyle}.-->
<attr name="guidedSubActionsListStyle" format="reference" />
<!-- Theme attribute for the style of the list in a GuidedActionsPresenter. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_GuidedButtonActionsListStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_GuidedButtonActionsListStyle}.-->
<attr name="guidedButtonActionsListStyle" format="reference" />
<!-- Theme attribute for the style of the container of a single action in a
GuidedActionsPresenter. Default is {@link
- androidx.leanbackback.R.style#Widget_Leanback_GuidedActionItemContainerStyle}. -->
+ androidx.leanback.R.style#Widget_Leanback_GuidedActionItemContainerStyle}. -->
<attr name="guidedActionItemContainerStyle" format="reference" />
<!-- Theme attribute for the style of an action's checkmark in a GuidedActionsPresenter.
Default is {@link
- androidx.leanbackback.R.style#Widget_Leanback_GuidedActionItemCheckmarkStyle}. -->
+ androidx.leanback.R.style#Widget_Leanback_GuidedActionItemCheckmarkStyle}. -->
<attr name="guidedActionItemCheckmarkStyle" format="reference" />
<!-- Theme attribute for the style of an action's icon in a GuidedActionsPresenter. Default
is {@link
- androidx.leanbackback.R.style#Widget_Leanback_GuidedActionItemIconStyle}. -->
+ androidx.leanback.R.style#Widget_Leanback_GuidedActionItemIconStyle}. -->
<attr name="guidedActionItemIconStyle" format="reference" />
<!-- Theme attribute for the style of an action's content in a GuidedActionsPresenter.
Default is {@link
- androidx.leanbackback.R.style#Widget_Leanback_GuidedActionItemContentStyle}. -->
+ androidx.leanback.R.style#Widget_Leanback_GuidedActionItemContentStyle}. -->
<attr name="guidedActionItemContentStyle" format="reference" />
<!-- Theme attribute for the style of an action's title in a GuidedActionsPresenter. Default
is {@link
- androidx.leanbackback.R.style#Widget_Leanback_GuidedActionItemTitleStyle}. -->
+ androidx.leanback.R.style#Widget_Leanback_GuidedActionItemTitleStyle}. -->
<attr name="guidedActionItemTitleStyle" format="reference" />
<!-- Theme attribute for the style of an action's description in a GuidedActionsPresenter.
Default is {@link
- androidx.leanbackback.R.style#Widget_Leanback_GuidedActionItemDescriptionStyle}. -->
+ androidx.leanback.R.style#Widget_Leanback_GuidedActionItemDescriptionStyle}. -->
<attr name="guidedActionItemDescriptionStyle" format="reference" />
<!-- Theme attribute for the style of an action's chevron decoration in a
GuidedActionsPresenter. Default is {@link
- androidx.leanbackback.R.style#Widget_Leanback_GuidedActionItemChevronStyle}. -->
+ androidx.leanback.R.style#Widget_Leanback_GuidedActionItemChevronStyle}. -->
<attr name="guidedActionItemChevronStyle" format="reference" />
<!-- Theme attribute for the animation used in a GuidedActionsPresenter when an action
is pressed. Default is {@link
- androidx.leanbackback.R.animator#lb_guidedactions_item_pressed}. -->
+ androidx.leanback.R.animator#lb_guidedactions_item_pressed}. -->
<attr name="guidedActionPressedAnimation" format="reference" />
<!-- Theme attribute for the animation used in a GuidedActionsPresenter when an action
is unpressed. Default is {@link
- androidx.leanbackback.R.animator#lb_guidedactions_item_unpressed}. -->
+ androidx.leanback.R.animator#lb_guidedactions_item_unpressed}. -->
<attr name="guidedActionUnpressedAnimation" format="reference" />
<!-- Theme attribute used in a GuidedActionsPresenter for the alpha value of the chevron
decoration when its action is enabled. Default is {@link
- androidx.leanbackback.R.dimen#lb_guidedactions_item_enabled_chevron_alpha}. -->
+ androidx.leanback.R.dimen#lb_guidedactions_item_enabled_chevron_alpha}. -->
<attr name="guidedActionEnabledChevronAlpha" format="reference" />
<!-- Theme attribute used in a GuidedActionsPresenter for the alpha value of the chevron
decoration when its action is disabled. Default is {@link
- androidx.leanbackback.R.string#lb_guidedactions_item_disabled_chevron_alpha}. -->
+ androidx.leanback.R.string#lb_guidedactions_item_disabled_chevron_alpha}. -->
<attr name="guidedActionDisabledChevronAlpha" format="reference" />
<!-- Theme attribute used for the width weight of actions in comparison to guidance area. Default is {@link
- androidx.leanbackback.R.string#lb_guidedactions_width_weight}. -->
+ androidx.leanback.R.string#lb_guidedactions_width_weight}. -->
<attr name="guidedActionContentWidthWeight" format="reference" />
<!-- Theme attribute used for the width weight of actions and button actions in comparison to guidance area. Default is {@link
- androidx.leanbackback.R.string#lb_guidedactions_width_weight_two_panels}. -->
+ androidx.leanback.R.string#lb_guidedactions_width_weight_two_panels}. -->
<attr name="guidedActionContentWidthWeightTwoPanels" format="reference" />
<!-- Theme attribute used for the width weight of button actions in compare to actions -->
<attr name="guidedButtonActionsWidthWeight" format="reference" />
<!-- Theme attribute used in a GuidedActionsPresenter for the max lines of the title text
view when the action's isMultilineDescription is set to false. Default is {@link
- androidx.leanbackback.R.integer#lb_guidedactions_item_title_min_lines}. -->
+ androidx.leanback.R.integer#lb_guidedactions_item_title_min_lines}. -->
<attr name="guidedActionTitleMinLines" format="reference" />
<!-- Theme attribute used in a GuidedActionsPresenter for the max lines of the title text
view when the action's isMultilineDescription is set to true. Default is {@link
- androidx.leanbackback.R.integer#lb_guidedactions_item_title_max_lines}. -->
+ androidx.leanback.R.integer#lb_guidedactions_item_title_max_lines}. -->
<attr name="guidedActionTitleMaxLines" format="reference" />
<!-- Theme attribute used in a GuidedActionsPresenter for the max lines of the title text
view when the action's isMultilineDescription is set to false. Default is {@link
- androidx.leanbackback.R.integer#lb_guidedactions_item_description_min_lines}. -->
+ androidx.leanback.R.integer#lb_guidedactions_item_description_min_lines}. -->
<attr name="guidedActionDescriptionMinLines" format="reference" />
<!-- Theme attribute used in a GuidedActionsPresenter for the vertical padding between
action views in the list. Default is {@link
- androidx.leanbackback.R.dimen#lb_guidedactions_vertical_padding}. -->
+ androidx.leanback.R.dimen#lb_guidedactions_vertical_padding}. -->
<attr name="guidedActionVerticalPadding" format="reference" />
<!-- Deprecated theme attribute, do not use -->
@@ -584,31 +584,31 @@
<attr name="onboardingTheme" format="reference" />
<!-- Theme attribute for the style of the header in onboarding screen. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingHeaderStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingHeaderStyle}.-->
<attr name="onboardingHeaderStyle" format="reference" />
<!-- Theme attribute for the style of the title text in onboarding screen. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingTitleStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingTitleStyle}.-->
<attr name="onboardingTitleStyle" format="reference" />
<!-- Theme attribute for the style of the description text in onboarding screen. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingDescriptionStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingDescriptionStyle}.-->
<attr name="onboardingDescriptionStyle" format="reference" />
<!-- Theme attribute for the style of the navigator container in onboarding screen. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingNavigatorContainerStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingNavigatorContainerStyle}.-->
<attr name="onboardingNavigatorContainerStyle" format="reference" />
<!-- Theme attribute for the style of the page indicator in onboarding screen. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingPageIndicatorStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingPageIndicatorStyle}.-->
<attr name="onboardingPageIndicatorStyle" format="reference" />
<!-- Theme attribute for the style of the start button in onboarding screen. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingStartButtonStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingStartButtonStyle}.-->
<attr name="onboardingStartButtonStyle" format="reference" />
<!-- Theme attribute for the style of the logo in onboarding screen. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingLogoStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingLogoStyle}.-->
<attr name="onboardingLogoStyle" format="reference" />
<!-- Theme attribute for the style of the main icon in onboarding fragment. Default is
- {@landroidx.leanbackback.R.style#Widget_Leanback_OnboardingMainIconStyle}.-->
+ {@landroidx.leanback.R.style#Widget_Leanback_OnboardingMainIconStyle}.-->
<attr name="onboardingMainIconStyle" format="reference" />
</declare-styleable>