use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnClickTest method onClickBinding.
@Test
public void onClickBinding() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + " @OnClick(1) void doStuff() {}\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 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 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" + " @CallSuper\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 OnClickTest method optionalAndRequiredSkipsNullCheck.
@Test
public void optionalAndRequiredSkipsNullCheck() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "import butterknife.OnClick;\n" + "import butterknife.Optional;\n" + "public class Test {\n" + " @BindView(1) View view;\n" + " @Optional @OnClick(1) void doStuff() {}\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 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 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, \"field 'view'\");\n" + " target.view = view;\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" + " @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" + " 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 OnClickTest method nullable.
@Test
public void nullable() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "import butterknife.Optional;\n" + "public class Test {\n" + " @Optional @OnClick(1) void doStuff() {}\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 butterknife.Unbinder;\n" + "import butterknife.internal.DebouncingOnClickListener;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public 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 = source.findViewById(1);\n" + " if (view != null) {\n" + " view1 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.doStuff();\n" + " }\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" + " if (view1 != null) {\n" + " view1.setOnClickListener(null);\n" + " view1 = null;\n" + " }\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 failsInJavaPackage.
@Test
public void failsInJavaPackage() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package java.test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + " @OnClick(1) void doStuff() {}\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick-annotated class incorrectly in Java framework package. (java.test.Test)").in(source).onLine(4);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnClickTest method failsIfInInterface.
@Test
public void failsIfInInterface() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public interface Test {\n" + " @OnClick(1)\n" + " void doStuff();\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick methods may only be contained in classes. (test.Test.doStuff)").in(source).onLine(3);
}
Aggregations