use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnClickTest method methodCastsArgument.
@Test
public void methodCastsArgument() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import android.widget.Button;\n" + "import android.widget.TextView;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + " interface TestInterface {}\n" + " @OnClick(0) void click0() {}\n" + " @OnClick(1) void click1(View view) {}\n" + " @OnClick(2) void click2(TextView view) {}\n" + " @OnClick(3) void click3(Button button) {}\n" + " @OnClick(4) void click4(TestInterface thing) {}\n" + "}");
JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "package test;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import android.widget.Button;\n" + "import android.widget.TextView;\n" + "import butterknife.Unbinder;\n" + "import butterknife.internal.DebouncingOnClickListener;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public class Test_ViewBinding implements Unbinder {\n" + " private Test target;\n" + " private View view0;\n" + " private View view1;\n" + " private View view2;\n" + " private View view3;\n" + " private View view4;\n" + " @UiThread\n" + " public Test_ViewBinding(final Test target, View source) {\n" + " this.target = target;\n" + " View view;\n" + " view = Utils.findRequiredView(source, 0, \"method 'click0'\");\n" + " view0 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click0();\n" + " }\n" + " });\n" + " view = Utils.findRequiredView(source, 1, \"method 'click1'\");\n" + " view1 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click1(p0);\n" + " }\n" + " });\n" + " view = Utils.findRequiredView(source, 2, \"method 'click2'\");\n" + " view2 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click2(Utils.<TextView>castParam(p0, \"doClick\", 0, \"click2\", 0));\n" + " }\n" + " });\n" + " view = Utils.findRequiredView(source, 3, \"method 'click3'\");\n" + " view3 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click3(Utils.<Button>castParam(p0, \"doClick\", 0, \"click3\", 0));\n" + " }\n" + " });\n" + " view = Utils.findRequiredView(source, 4, \"method 'click4'\");\n" + " view4 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click4(Utils.<Test.TestInterface>castParam(p0, \"doClick\", 0, \"click4\", 0));\n" + " }\n" + " });\n" + " }\n" + " @Override\n" + " @CallSuper\n" + " public void unbind() {\n" + " if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + " target = null;\n" + " view0.setOnClickListener(null);\n" + " view0 = null;\n" + " view1.setOnClickListener(null);\n" + " view1 = null;\n" + " view2.setOnClickListener(null);\n" + " view2 = null;\n" + " view3.setOnClickListener(null);\n" + " view3 = null;\n" + " view4.setOnClickListener(null);\n" + " view4 = null;\n" + " }\n" + "}");
assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnClickTest method failsIfStatic.
@Test
public void failsIfStatic() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + " @OnClick(1)\n" + " public static void doStuff() {\n" + " }\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick methods must not be private or static. (test.Test.doStuff)").in(source).onLine(5);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnClickTest method onClickBindingFinalType.
@Test
public void onClickBindingFinalType() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public final class Test {\n" + " @OnClick(1) void doStuff() {}\n" + "}");
JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "package test;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import butterknife.internal.DebouncingOnClickListener;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public final class Test_ViewBinding implements Unbinder {\n" + " private Test target;\n" + " private View view1;\n" + " @UiThread\n" + " public Test_ViewBinding(final Test target, View source) {\n" + " this.target = target;\n" + " View view;\n" + " view = Utils.findRequiredView(source, 1, \"method 'doStuff'\");\n" + " view1 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.doStuff();\n" + " }\n" + " });\n" + " }\n" + " @Override\n" + " public void unbind() {\n" + " if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + " target = null;\n" + " view1.setOnClickListener(null);\n" + " view1 = null;\n" + " }\n" + "}");
assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewTest method superclass.
@Test
public void superclass() {
JavaFileObject source1 = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + " @BindView(1) View view;\n" + "}");
JavaFileObject source2 = JavaFileObjects.forSourceString("test.TestOne", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class TestOne extends Test {\n" + " @BindView(1) View thing;\n" + "}");
JavaFileObject source3 = JavaFileObjects.forSourceString("test.TestTwo", "" + "package test;\n" + "public class TestTwo extends Test {\n" + "}");
JavaFileObject binding1Source = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "package test;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public class Test_ViewBinding implements Unbinder {\n" + " private Test target;\n" + " @UiThread\n" + " public Test_ViewBinding(Test target, View source) {\n" + " this.target = target;\n" + " target.view = Utils.findRequiredView(source, 1, \"field 'view'\");\n" + " }\n" + " @Override\n" + " @CallSuper\n" + " public void unbind() {\n" + " Test target = this.target;\n" + " if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + " this.target = null;\n" + " target.view = null;\n" + " }\n" + "}");
JavaFileObject binding2Source = JavaFileObjects.forSourceString("test/TestOne_ViewBinding", "" + "package test;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public class TestOne_ViewBinding extends Test_ViewBinding {\n" + " private TestOne target;\n" + " @UiThread\n" + " public TestOne_ViewBinding(TestOne target, View source) {\n" + " super(target, source);\n" + " this.target = target;\n" + " target.thing = Utils.findRequiredView(source, 1, \"field 'thing'\");\n" + " }\n" + " @Override\n" + " public void unbind() {\n" + " TestOne target = this.target;\n" + " if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + " this.target = null;\n" + " target.thing = null;\n" + " super.unbind();\n" + " }\n" + "}");
assertAbout(javaSources()).that(asList(source1, source2, source3)).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(binding1Source, binding2Source);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewTest method genericSuperclass.
@Test
public void genericSuperclass() {
JavaFileObject source1 = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test<T> {\n" + " @BindView(1) View view;\n" + "}");
JavaFileObject source2 = JavaFileObjects.forSourceString("test.TestOne", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class TestOne extends Test<String> {\n" + " @BindView(1) View thing;\n" + "}");
JavaFileObject source3 = JavaFileObjects.forSourceString("test.TestTwo", "" + "package test;\n" + "public class TestTwo extends Test<Object> {\n" + "}");
JavaFileObject binding1Source = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "package test;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public class Test_ViewBinding implements Unbinder {\n" + " private Test target;\n" + " @UiThread\n" + " public Test_ViewBinding(Test target, View source) {\n" + " this.target = target;\n" + " target.view = Utils.findRequiredView(source, 1, \"field 'view'\");\n" + " }\n" + " @Override\n" + " @CallSuper\n" + " public void unbind() {\n" + " Test target = this.target;\n" + " if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + " this.target = null;\n" + " target.view = null;\n" + " }\n" + "}");
JavaFileObject binding2Source = JavaFileObjects.forSourceString("test/TestOne_ViewBinding", "" + "package test;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public class TestOne_ViewBinding extends Test_ViewBinding {\n" + " private TestOne target;\n" + " @UiThread\n" + " public TestOne_ViewBinding(TestOne target, View source) {\n" + " super(target, source);\n" + " this.target = target;\n" + " target.thing = Utils.findRequiredView(source, 1, \"field 'thing'\");\n" + " }\n" + " @Override\n" + " public void unbind() {\n" + " TestOne target = this.target;\n" + " if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + " this.target = null\n" + " target.thing = null;\n" + " super.unbind();\n" + " }\n" + "}");
assertAbout(javaSources()).that(asList(source1, source2, source3)).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutError().and().generatesSources(binding1Source, binding2Source);
}
Aggregations