Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25ac81d8 authored by George Mount's avatar George Mount
Browse files

Added support for imports in type checking.

findType did not support user-defined imports, so casting,
for example, of Foo<String> didn't recognize Foo or String.
This also will import java.lang.* by default.
parent 980449bc
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.databinding.testapp;
import com.android.databinding.testapp.generated.FindMethodTestBinder;
import com.android.databinding.testapp.vo.FindMethodBindingObject;

import android.test.UiThreadTest;
import android.widget.TextView;

public class FindMethodTest
@@ -91,4 +92,12 @@ public class FindMethodTest
        TextView textView = mBinder.getTextView12();
        assertEquals("hello world", textView.getText().toString());
    }

    @UiThreadTest
    public void testImports() throws Throwable {
        mBinder.setObj2(new FindMethodBindingObject.Bar<String>());
        mBinder.rebindDirty();
        TextView textView = mBinder.getTextView15();
        assertEquals("hello", textView.getText().toString());
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -28,8 +28,13 @@ public class FindMethodBindingObject extends FindMethodBindingObjectBase {

    public static Foo foo = new Foo();

    public static Bar<String> bar = new Bar<>();

    public static class Foo {
        public final String bar = "hello world";
    }

    public static class Bar<T> {
        public T method(T value) { return value; }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <variable name="a" type="java.lang.String"/>
    <variable name="b" type="java.lang.String"/>
    <variable name="a" type="String"/>
    <variable name="b" type="String"/>
    <TextView
            android:id="@+id/textView"
            android:text="@{a + b}"
+7 −4
Original line number Diff line number Diff line
@@ -3,15 +3,18 @@
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <variable name="list" type="java.util.Collection&lt;java.lang.String&gt;"/>
    <variable name="map" type="java.lang.Object"/>
    <import type="java.util.Collection"/>
    <import type="java.util.ArrayList"/>
    <import type="java.util.Map"/>
    <variable name="list" type="Collection&lt;String&gt;"/>
    <variable name="map" type="Object"/>

    <TextView
            android:id="@+id/textView0"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="@{((java.util.ArrayList&lt;java.lang.String&gt;)list)[0]}"/>
            android:text="@{((ArrayList&lt;String&gt;)list)[0]}"/>
    <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="@{((java.util.Map&lt;java.lang.String,java.lang.String&gt;)map)[`hello`]}"/>
            android:text="@{((Map&lt;String, String&gt;)map)[`hello`]}"/>
</LinearLayout>
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <variable name="obj" type="com.android.databinding.testapp.vo.FindMethodBindingObject"/>
    <import type="com.android.databinding.testapp.vo.FindMethodBindingObject.Bar"/>
    <variable name="obj2" type="Bar&lt;String&gt;"/>
    <import type="com.android.databinding.testapp.vo.FindMethodBindingObject"/>
    <import type="com.android.databinding.testapp.vo.FindMethodBindingObject" alias="FMBO"/>
    <TextView
@@ -67,4 +69,9 @@
            android:id="@+id/textView14"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="@{FMBO.foo.bar}"/>
    <!-- Imported classes -->
    <TextView
            android:id="@+id/textView15"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="@{obj2.method(`hello`)}"/>
</LinearLayout>
 No newline at end of file
Loading