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
diff --git a/compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateSource.kt b/compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateJava.kt
similarity index 98%
rename from compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateSource.kt
rename to compilerCommon/src/main/kotlin/android/databinding/tool/writer/ViewBinderGenerateJava.kt
index 00c604b..ca54513 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 @@
             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
similarity index 94%
rename from compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateSourceTest.kt
rename to compilerCommon/src/test/kotlin/android/databinding/tool/writer/ViewBinderGenerateJavaTest.kt
index 55ba9f4..dcc2bdf 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.Rule
 import org.junit.Test
 
-class ViewBinderGenerateSourceTest {
+class ViewBinderGenerateJavaTest {
     @get:Rule val layouts = LayoutResourceRule()
 
     @Test fun nullableFieldsJavadocTheirConfigurations() {
@@ -214,9 +214,7 @@
             <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 @@
                 |  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 @@
                 |        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 @@
                 |      }
                 |
                 |      return new ExampleBinding((LinearLayout) rootView, id_, missingId,
-                |          otherBinding, otherBinding_, rootView_);
+                |          rootView_);
                 |    }
                 |
                 |    String missingId_ = rootView.getResources().getResourceName(id);
@@ -579,7 +555,7 @@
         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())
diff --git a/integration-tests/ViewBindingTestApp/app/src/androidTest/java/com/example/viewbinding/IncludeNamingCollisionTest.java b/integration-tests/ViewBindingTestApp/app/src/androidTest/java/com/example/viewbinding/IncludeNamingCollisionTest.java
new file mode 100644
index 0000000..f255cc0
--- /dev/null
+++ b/integration-tests/ViewBindingTestApp/app/src/androidTest/java/com/example/viewbinding/IncludeNamingCollisionTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.viewbinding;
+
+import static org.junit.Assert.assertNotNull;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.view.LayoutInflater;
+import com.example.viewbinding.databinding.IncludeNamingCollisionBinding;
+import org.junit.Test;
+
+public final class IncludeNamingCollisionTest {
+    private final Context context = InstrumentationRegistry.getContext();
+    private final LayoutInflater inflater = LayoutInflater.from(context);
+
+    @Test public void check() {
+        IncludeNamingCollisionBinding binding =
+                IncludeNamingCollisionBinding.inflate(inflater);
+        // Compilation is the real test here.
+        assertNotNull(binding);
+    }
+}
diff --git a/integration-tests/ViewBindingTestApp/app/src/main/res/layout/include_naming_collision.xml b/integration-tests/ViewBindingTestApp/app/src/main/res/layout/include_naming_collision.xml
new file mode 100644
index 0000000..c74c934
--- /dev/null
+++ b/integration-tests/ViewBindingTestApp/app/src/main/res/layout/include_naming_collision.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+ -->
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    >
+  <include
+    layout="@layout/simple"
+    android:id="@+id/_simple"
+    />
+</FrameLayout>