use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnClickTest method methodWithMultipleIds.
@Test
public void methodWithMultipleIds() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + " @OnClick({1, 2, 3}) void click() {}\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" + " private View view2;\n" + " private View view3;\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 'click'\");\n" + " view1 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click();\n" + " }\n" + " });\n" + " view = Utils.findRequiredView(source, 2, \"method 'click'\");\n" + " view2 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click();\n" + " }\n" + " });\n" + " view = Utils.findRequiredView(source, 3, \"method 'click'\");\n" + " view3 = view;\n" + " view.setOnClickListener(new DebouncingOnClickListener() {\n" + " @Override\n" + " public void doClick(View p0) {\n" + " target.click();\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" + " view2.setOnClickListener(null);\n" + " view2 = null;\n" + " view3.setOnClickListener(null);\n" + " view3 = 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 OnEditorActionTest method editorAction.
@Test
public void editorAction() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnEditorAction;\n" + "public class Test {\n" + " @OnEditorAction(1) boolean doStuff() { return false; }\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.KeyEvent;\n" + "import android.view.View;\n" + "import android.widget.TextView;\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" + " 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" + " ((TextView) view).setOnEditorActionListener(new TextView.OnEditorActionListener() {\n" + " @Override\n" + " public boolean onEditorAction(TextView p0, int p1, KeyEvent p2) {\n" + " return 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" + " ((TextView) view1).setOnEditorActionListener(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 OnFocusChangeTest method focusChange.
@Test
public void focusChange() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnFocusChange;\n" + "public class Test {\n" + " @OnFocusChange(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.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.setOnFocusChangeListener(new View.OnFocusChangeListener() {\n" + " @Override\n" + " public void onFocusChange(View p0, boolean p1) {\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.setOnFocusChangeListener(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 BindDrawableTest method simple.
@Test
public void simple() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.graphics.drawable.Drawable;\n" + "import butterknife.BindDrawable;\n" + "public class Test {\n" + " @BindDrawable(1) Drawable one;\n" + "}");
JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "// Generated code from Butter Knife. Do not modify!\n" + "package test;\n" + "import android.content.Context;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.support.v4.content.ContextCompat;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import java.lang.Deprecated;\n" + "import java.lang.Override;\n" + "import java.lang.SuppressWarnings;\n" + "public class Test_ViewBinding implements Unbinder {\n" + " /**\n" + " * @deprecated Use {@link #Test_ViewBinding(Test, Context)} for direct creation.\n" + " * Only present for runtime invocation through {@code ButterKnife.bind()}.\n" + " */\n" + " @Deprecated\n" + " @UiThread\n" + " public Test_ViewBinding(Test target, View source) {\n" + " this(target, source.getContext());\n" + " }\n" + " @UiThread\n" + " @SuppressWarnings(\"ResourceType\")\n" + " public Test_ViewBinding(Test target, Context context) {\n" + " target.one = ContextCompat.getDrawable(context, 1);\n" + " }\n" + " @Override\n" + " @CallSuper\n" + " public void unbind() {\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 BindDrawableTest method simpleSdk21.
@Test
public void simpleSdk21() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.graphics.drawable.Drawable;\n" + "import butterknife.BindDrawable;\n" + "public class Test {\n" + " @BindDrawable(1) Drawable one;\n" + "}");
JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "// Generated code from Butter Knife. Do not modify!\n" + "package test;\n" + "import android.content.Context;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import java.lang.Deprecated;\n" + "import java.lang.Override;\n" + "import java.lang.SuppressWarnings;\n" + "public class Test_ViewBinding implements Unbinder {\n" + " /**\n" + " * @deprecated Use {@link #Test_ViewBinding(Test, Context)} for direct creation.\n" + " * Only present for runtime invocation through {@code ButterKnife.bind()}.\n" + " */\n" + " @Deprecated\n" + " @UiThread\n" + " public Test_ViewBinding(Test target, View source) {\n" + " this(target, source.getContext());\n" + " }\n" + " @UiThread\n" + " @SuppressWarnings(\"ResourceType\")\n" + " public Test_ViewBinding(Test target, Context context) {\n" + " target.one = context.getDrawable(1);\n" + " }\n" + " @Override\n" + " @CallSuper\n" + " public void unbind() {\n" + " }\n" + "}");
assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing", "-Abutterknife.minSdk=21").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Aggregations