summaryrefslogtreecommitdiff
path: root/compilerCommon
diff options
context:
space:
mode:
authorJake Wharton <jakew@google.com>2020-03-30 11:35:10 -0400
committerJake Wharton <jakew@google.com>2020-04-03 01:49:20 +0000
commit2089889fbbd824f13b488ee9a645b86e13ee59cf (patch)
tree4fbdae0a0c02eb56ce233554951793715c4c3c03 /compilerCommon
parent5951d2675e9118474e9fc9d6c713243132ff9d9e (diff)
downloaddata-binding-2089889fbbd824f13b488ee9a645b86e13ee59cf.tar.gz
Change binding local naming to avoid type collision
Preciously the suffixing could cause the local to be named the same as a type which would cause javac to fail. Bug: 152413696 Test: ../base/bazel/bazel test --test_output=all //tools/base/build-system/integration-test/databinding:tests //tools/data-binding/... Change-Id: I7adfcbbb618bab271cc901fedef15f23645fdcc0
Diffstat (limited to 'compilerCommon')
-rw-r--r--compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateJava.kt (renamed from compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateSource.kt)2
-rw-r--r--compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateJavaTest.kt (renamed from compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateSourceTest.kt)32
2 files changed, 5 insertions, 29 deletions
diff --git a/compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateSource.kt b/compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateJava.kt
index 00c604b6..ca545132 100644
--- a/compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateSource.kt
+++ b/compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateJava.kt
@@ -292,7 +292,7 @@ private class JavaFileGenerator(
val constructorParam = when (binding.form) {
ViewBinding.Form.View -> viewName
ViewBinding.Form.Binder -> {
- val binderName = localNames.newName("${binding.name}Binding")
+ val binderName = localNames.newName("binding_${binding.name}")
if (binding.isRequired) {
addStatement("$1T $binderName = $1T.bind($viewName)", binding.type)
} else {
diff --git a/compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateSourceTest.kt b/compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateJavaTest.kt
index 55ba9f4b..dcc2bdf3 100644
--- a/compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateSourceTest.kt
+++ b/compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateJavaTest.kt
@@ -23,7 +23,7 @@ import org.junit.Assert.fail
import org.junit.Rule
import org.junit.Test
-class ViewBinderGenerateSourceTest {
+class ViewBinderGenerateJavaTest {
@get:Rule val layouts = LayoutResourceRule()
@Test fun nullableFieldsJavadocTheirConfigurations() {
@@ -214,9 +214,7 @@ class ViewBinderGenerateSourceTest {
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/root_view" />
<TextView android:id="@+id/missing_id" />
- <View android:id="@+id/other_binding" />
<View android:id="@+id/id" />
- <include layout="@layout/other" android:id="@+id/other"/>
</LinearLayout>
""".trimIndent())
@@ -249,22 +247,13 @@ class ViewBinderGenerateSourceTest {
| public final TextView missingId;
|
| @NonNull
- | public final OtherBinding other;
- |
- | @NonNull
- | public final View otherBinding;
- |
- | @NonNull
| public final TextView rootView;
|
| private ExampleBinding(@NonNull LinearLayout rootView_, @NonNull View id,
- | @NonNull TextView missingId, @NonNull OtherBinding other,
- | @NonNull View otherBinding, @NonNull TextView rootView) {
+ | @NonNull TextView missingId, @NonNull TextView rootView) {
| this.rootView_ = rootView_;
| this.id = id;
| this.missingId = missingId;
- | this.other = other;
- | this.otherBinding = otherBinding;
| this.rootView = rootView;
| }
|
@@ -305,19 +294,6 @@ class ViewBinderGenerateSourceTest {
| break missingId;
| }
|
- | id = R.id.other;
- | View other = rootView.findViewById(id);
- | if (other == null) {
- | break missingId;
- | }
- | OtherBinding otherBinding = OtherBinding.bind(other);
- |
- | id = R.id.other_binding;
- | View otherBinding_ = rootView.findViewById(id);
- | if (otherBinding_ == null) {
- | break missingId;
- | }
- |
| id = R.id.root_view;
| TextView rootView_ = rootView.findViewById(id);
| if (rootView_ == null) {
@@ -325,7 +301,7 @@ class ViewBinderGenerateSourceTest {
| }
|
| return new ExampleBinding((LinearLayout) rootView, id_, missingId,
- | otherBinding, otherBinding_, rootView_);
+ | rootView_);
| }
|
| String missingId_ = rootView.getResources().getResourceName(id);
@@ -579,7 +555,7 @@ class ViewBinderGenerateSourceTest {
model.toViewBinder().toJavaFile().assert {
contains("""
| View other = rootView.findViewById(R.id.other);
- | OtherBinding otherBinding = other != null
+ | OtherBinding binding_other = other != null
| ? OtherBinding.bind(other)
| : null;
""".trimMargin())