Search in sources :

Example 76 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindColorTest method simpleColorStateListSdk23.

@Test
public void simpleColorStateListSdk23() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.content.res.ColorStateList;\n" + "import butterknife.BindColor;\n" + "public class Test {\n" + "  @BindColor(1) ColorStateList 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.getColorStateList(1);\n" + "  }\n" + "  @Override\n" + "  @CallSuper\n" + "  public void unbind() {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing", "-Abutterknife.minSdk=23").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 77 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindColorTest method typeMustBeIntOrColorStateList.

@Test
public void typeMustBeIntOrColorStateList() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindColor;\n" + "public class Test {\n" + "  @BindColor(1) String one;\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindColor field type must be 'int' or 'ColorStateList'. (test.Test.one)").in(source).onLine(4);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 78 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindColorTest method simpleIntSdk23.

@Test
public void simpleIntSdk23() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindColor;\n" + "public class Test {\n" + "  @BindColor(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.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.getColor(1);\n" + "  }\n" + "  @Override\n" + "  @CallSuper\n" + "  public void unbind() {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing", "-Abutterknife.minSdk=23").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 79 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class OnTextChangedTest method textChangedWithParameter.

@Test
public void textChangedWithParameter() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnTextChanged;\n" + "public class Test {\n" + "  @OnTextChanged(1) void doStuff(CharSequence p0) {}\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.text.Editable;\n" + "import android.text.TextWatcher;\n" + "import android.view.View;\n" + "import android.widget.TextView;\n" + "import butterknife.Unbinder;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.CharSequence;\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 TextWatcher view1TextWatcher;\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" + "    view1TextWatcher = new TextWatcher() {\n" + "      @Override\n" + "      public void onTextChanged(CharSequence p0, int p1, int p2, int p3) {\n" + "        target.doStuff(p0);\n" + "      }\n" + "      @Override\n" + "      public void beforeTextChanged(CharSequence p0, int p1, int p2, int p3) {\n" + "      }\n" + "      @Override\n" + "      public void afterTextChanged(Editable p0) {\n" + "      }\n" + "    };\n" + "    ((TextView) view).addTextChangedListener(view1TextWatcher);\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).removeTextChangedListener(view1TextWatcher);\n" + "    view1TextWatcher = null;\n" + "    view1 = null;\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 80 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class OnTouchTest method touch.

@Test
public void touch() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnTouch;\n" + "public class Test {\n" + "  @OnTouch(1) boolean doStuff() { return false; }\n" + "}");
    JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "package test;\n" + "import android.annotation.SuppressLint;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.MotionEvent;\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" + "  @SuppressLint(\"ClickableViewAccessibility\")\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.setOnTouchListener(new View.OnTouchListener() {\n" + "      @Override\n" + "      public boolean onTouch(View p0, MotionEvent p1) {\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" + "    view1.setOnTouchListener(null);\n" + "    view1 = null;\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Aggregations

ButterKnifeProcessor (butterknife.compiler.ButterKnifeProcessor)121 JavaFileObject (javax.tools.JavaFileObject)121 Test (org.junit.Test)121