use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewTest method bindingViewFinalClassWithBaseClass.
@Test
public void bindingViewFinalClassWithBaseClass() {
JavaFileObject baseSource = JavaFileObjects.forSourceString("test.Base", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Base {\n" + " @BindView(1) View thing;\n" + "}");
JavaFileObject testSource = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public final class Test extends Base {\n" + " @BindView(1) View thing;\n" + "}");
JavaFileObject bindingBaseSource = JavaFileObjects.forSourceString("test/Base_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 Base_ViewBinding implements Unbinder {\n" + " private Base target;\n" + " @UiThread\n" + " public Base_ViewBinding(Base target, View source) {\n" + " this.target = target;\n" + " target.thing = Utils.findRequiredView(source, 1, \"field 'thing'\");\n" + " }\n" + " @Override\n" + " @CallSuper\n" + " public void unbind() {\n" + " Base target = this.target;\n" + " if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + " this.target = null;\n" + " target.thing = null;\n" + " }\n" + "}");
JavaFileObject bindingTestSource = JavaFileObjects.forSourceString("test/Test_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 final class Test_ViewBinding extends Base_ViewBinding {\n" + " private Test target;\n" + " @UiThread\n" + " public Test_ViewBinding(Test 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" + " Test 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(baseSource, testSource)).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingBaseSource, bindingTestSource);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewTest method failsInAndroidPackage.
@Test
public void failsInAndroidPackage() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package android.test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + " @BindView(1) View thing;\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindView-annotated class incorrectly in Android framework package. (android.test.Test)").in(source).onLine(5);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewTest method failsIfPrivate.
@Test
public void failsIfPrivate() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + " @BindView(1) private View thing;\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindView fields must not be private or static. (test.Test.thing)").in(source).onLine(5);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewTest method bindingView.
@Test
public void bindingView() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + " @BindView(1) View 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 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.thing = Utils.findRequiredView(source, 1, \"field 'thing'\");\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.thing = 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 BindArrayTest method intArray.
@Test
public void intArray() throws Exception {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindArray;\n" + "public class Test {\n" + " @BindArray(1) int[] 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.content.res.Resources;\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" + " Resources res = context.getResources();\n" + " target.one = res.getIntArray(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);
}
Aggregations