当前位置: 首页>>代码示例>>Java>>正文


Java JavaFileObjects.forSourceString方法代码示例

本文整理汇总了Java中com.google.testing.compile.JavaFileObjects.forSourceString方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileObjects.forSourceString方法的具体用法?Java JavaFileObjects.forSourceString怎么用?Java JavaFileObjects.forSourceString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.testing.compile.JavaFileObjects的用法示例。


在下文中一共展示了JavaFileObjects.forSourceString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFinal

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testFinal() {
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName("TestFinal"), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestFinal {\n"
            + "    @State\n"
            + "    public final int test = 5;\n"
            + "}\n");

    Compilation compilation = Compiler.javac().withProcessors(new StateProcessor()).compile(javaFileObject);
    assertThat(compilation).failed();
    assertThat(compilation)
            .hadErrorContaining("Field must not be final")
            .inFile(javaFileObject)
            .onLine(7)
            .atColumn(22);
}
 
开发者ID:evernote,项目名称:android-state,代码行数:21,代码来源:TestProcessor.java

示例2: compilationShoulNotFailIfDuplicateFoundAndSupressed

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void compilationShoulNotFailIfDuplicateFoundAndSupressed() {
  final JavaFileObject source =
          JavaFileObjects.forSourceString(
                  "com.groupon.android.dichecks.dummy.A",
                  Joiner.on('\n')
                          .join(
                                  "package com.groupon.android.dichecks.dummy;",
                                  "import javax.inject.Inject;",
                                  "import javax.inject.Named;",
                                  "public class A {",
                                  "    @Inject @Named(\"someNamedString\") String something;",
                                  "    @Inject InjectedClass aClass;",
                                  "}",
                                  "class B extends A {",
                                  "    @SuppressWarnings(\"" + CompilerOptions.OPTIONS_PREFIX + CompilerOptions.DUPLICATE_CHECK + "\")",
                                  "    @Inject InjectedClass aClass;",
                                  "}",
                                  "class D extends B {}",
                                  "class C extends A {}",
                                  "class InjectedClass {}"));

  assertAbout(javaSource()).that(source).processedWith(new DiChecksProcessor()).compilesWithoutError();
}
 
开发者ID:groupon,项目名称:dependency-injection-checks,代码行数:25,代码来源:ProcessorTest.java

示例3: testTypeNotSupported

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testTypeNotSupported() {
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName("TestTypeNotSupported"), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestTypeNotSupported {\n"
            + "    @State\n"
            + "    public Other test;\n"
            + "\n"
            + "    public static final class Other {}\n"
            + "}\n");

    Compilation compilation = Compiler.javac().withProcessors(new StateProcessor()).compile(javaFileObject);
    assertThat(compilation).failed();
    assertThat(compilation)
            .hadErrorContaining("Don't know how to put com.evernote.android.state.test.TestTypeNotSupported.Other into a bundle")
            .inFile(javaFileObject)
            .onLine(7)
            .atColumn(18);
}
 
开发者ID:evernote,项目名称:android-state,代码行数:23,代码来源:TestProcessor.java

示例4: failsIfPrivate

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:BindViewTest.java

示例5: typeMustBeDrawable

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void typeMustBeDrawable() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import butterknife.BindDrawable;\n"
      + "public class Test {\n"
      + "  @BindDrawable(1) String one;\n"
      + "}"
  );

  assertAbout(javaSource()).that(source)
      .processedWith(new ButterKnifeProcessor())
      .failsToCompile()
      .withErrorContaining("@BindDrawable field type must be 'Drawable'. (test.Test.one)")
      .in(source).onLine(4);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:BindDrawableTest.java

示例6: compilationShouldNotFailIfToothpickTypeDuplicateLazyInSuperClassAndProviderInjectionInSubclass

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void compilationShouldNotFailIfToothpickTypeDuplicateLazyInSuperClassAndProviderInjectionInSubclass() {
    final JavaFileObject lazySource =
        JavaFileObjects.forSourceString(
        "toothpick.Lazy",
            Joiner.on('\n')
                .join(
                    "package toothpick;",
                    "import javax.inject.Provider;",
                    "public interface Lazy<T> extends Provider<T> {}"
            ));
    final JavaFileObject source =
        JavaFileObjects.forSourceString(
            "com.groupon.android.dichecks.dummy.A",
            Joiner.on('\n')
                .join(
                    "package com.groupon.android.dichecks.dummy;",
                    "import javax.inject.Inject;",
                    "import javax.inject.Named;",
                    "import javax.inject.Provider;",
                    "import toothpick.Lazy;",
                    "public class A {",
                        "@Inject Lazy<Foo> foo0;",
                    "}",
                    "class B extends A {",
                    "    @Inject Provider<Foo> foo1;",
                    "}",
                    "class Foo {}"));

    assertAbout(javaSources())
        .that(ImmutableList.of(source, lazySource))
        .processedWith(new DiChecksProcessor())
        .compilesWithoutError();
}
 
开发者ID:groupon,项目名称:dependency-injection-checks,代码行数:35,代码来源:ProcessorTest.java

示例7: findOnlyCalledOnce

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void findOnlyCalledOnce() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import android.view.View;\n"
      + "import butterknife.BindView;\n"
      + "import butterknife.OnClick;\n"
      + "public class Test {\n"
      + "  @BindView(1) View view;\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, \"field 'view' and method 'doStuff'\");\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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:60,代码来源:OnClickTest.java

示例8: app

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void app() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import butterknife.BindBool;\n"
      + "public class Test {\n"
      + "  @BindBool(R.bool.res) boolean bool;\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"
      + "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"
      + "  public Test_ViewBinding(Test target, Context context) {\n"
      + "    Resources res = context.getResources();\n"
      + "    target.bool = res.getBoolean(R.bool.res);\n"
      + "  }\n"
      + "  @Override\n"
      + "  @CallSuper\n"
      + "  public void unbind() {\n"
      + "  }\n"
      + "}"
  );

  assertAbout(javaSources()).that(asList(source, FINAL_R))
      .withCompilerOptions("-Xlint:-processing")
      .processedWith(new ButterKnifeProcessor())
      .compilesWithoutWarnings()
      .and()
      .generatesSources(bindingSource);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:50,代码来源:RClassTest.java

示例9: compiledRClass

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void compiledRClass() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import butterknife.BindColor;\n"
      + "public class Test {\n"
      + "  @BindColor(android.R.color.black) int black;\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"
      + "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"
      + "  public Test_ViewBinding(Test target, Context context) {\n"
      + "    target.black = ContextCompat.getColor(context, android.R.color.black);\n"
      + "  }\n"
      + "  @Override\n"
      + "  @CallSuper\n"
      + "  public void unbind() {\n"
      + "  }\n"
      + "}"
  );

  assertAbout(javaSources()).that(asList(source, NON_FINAL_R))
      .withCompilerOptions("-Xlint:-processing")
      .processedWith(new ButterKnifeProcessor())
      .compilesWithoutWarnings()
      .and()
      .generatesSources(bindingSource);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:49,代码来源:RClassTest.java

示例10: simple

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void simple() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;"
      + "import butterknife.BindFloat;"
      + "public class Test {"
      + "  @BindFloat(1) float one;"
      + "}"
  );

  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 butterknife.internal.Utils;\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 = Utils.getFloat(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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:51,代码来源:BindFloatTest.java

示例11: onItemClickBinding

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void onItemClickBinding() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;"
      + "import butterknife.OnItemClick;"
      + "public class Test {"
      + "  @OnItemClick(1) void doStuff() {}"
      + "}"
  );

  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.AdapterView;\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"
      + "    ((AdapterView<?>) view).setOnItemClickListener(new AdapterView.OnItemClickListener() {\n"
      + "      @Override\n"
      + "      public void onItemClick(AdapterView<?> p0, View p1, int p2, long p3) {\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"
      + "    ((AdapterView<?>) view1).setOnItemClickListener(null);\n"
      + "    view1 = null;\n"
      + "  }\n"
      + "}"
  );

  assertAbout(javaSource()).that(source)
      .withCompilerOptions("-Xlint:-processing")
      .processedWith(new ButterKnifeProcessor())
      .compilesWithoutWarnings()
      .and()
      .generatesSources(bindingSource);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:54,代码来源:OnItemClickTest.java

示例12: bindingInterface

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void bindingInterface() throws Exception {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import android.view.View;\n"
      + "import butterknife.BindView;\n"
      + "public class Test {\n"
      + "    interface TestInterface {}\n"
      + "    @BindView(1) 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 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.findRequiredViewAsType(source, 1, \"field 'thing'\", Test.TestInterface.class);\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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:46,代码来源:BindViewTest.java

示例13: multipleBindings

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void multipleBindings() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import android.view.View;\n"
      + "import butterknife.BindView;\n"
      + "import butterknife.OnClick;\n"
      + "import butterknife.OnLongClick;\n"
      + "public class Test {\n"
      + "  @BindView(1) View view;\n"
      + "  @BindView(2) View view2;\n"
      + "  @OnClick(1) void doStuff() {}\n"
      + "  @OnLongClick(1) boolean doMoreStuff() { 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.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', method 'doStuff', and method 'doMoreStuff'\");\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"
      + "    view.setOnLongClickListener(new View.OnLongClickListener() {\n"
      + "      @Override\n"
      + "      public boolean onLongClick(View p0) {\n"
      + "        return target.doMoreStuff();\n"
      + "      }\n"
      + "    });\n"
      + "    target.view2 = Utils.findRequiredView(source, 2, \"field 'view2'\");\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"
      + "    target.view2 = null;\n"
      + "    view1.setOnClickListener(null);\n"
      + "    view1.setOnLongClickListener(null);\n"
      + "    view1 = null;\n"
      + "  }\n"
      + "}"
  );

  assertAbout(javaSource()).that(source)
      .withCompilerOptions("-Xlint:-processing")
      .processedWith(new ButterKnifeProcessor())
      .compilesWithoutWarnings()
      .and()
      .generatesSources(bindingSource);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:72,代码来源:UnbinderTest.java

示例14: bindingArrayWithCast

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void bindingArrayWithCast() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import android.widget.TextView;\n"
      + "import butterknife.BindViews;\n"
      + "public class Test {\n"
      + "    @BindViews({1, 2, 3}) TextView[] 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.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"
      + "  @UiThread\n"
      + "  public Test_ViewBinding(Test target, View source) {\n"
      + "    this.target = target;\n"
      + "    target.thing = Utils.arrayOf(\n"
      + "        Utils.findRequiredViewAsType(source, 1, \"field 'thing'\", TextView.class), \n"
      + "        Utils.findRequiredViewAsType(source, 2, \"field 'thing'\", TextView.class), \n"
      + "        Utils.findRequiredViewAsType(source, 3, \"field 'thing'\", TextView.class));\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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:49,代码来源:BindViewsTest.java

示例15: onLongClickBinding

import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test public void onLongClickBinding() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import butterknife.OnLongClick;\n"
      + "public class Test {\n"
      + "  @OnLongClick(1) boolean doStuff() {\n"
      + "    return true;\n"
      + "  }\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.setOnLongClickListener(new View.OnLongClickListener() {\n"
      + "      @Override\n"
      + "      public boolean onLongClick(View p0) {\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.setOnLongClickListener(null);\n"
      + "    view1 = null;\n"
      + "  }\n"
      + "}"
  );

  assertAbout(javaSource()).that(source)
      .withCompilerOptions("-Xlint:-processing")
      .processedWith(new ButterKnifeProcessor())
      .compilesWithoutWarnings()
      .and()
      .generatesSources(bindingSource);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:55,代码来源:OnLongClickTest.java


注:本文中的com.google.testing.compile.JavaFileObjects.forSourceString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。