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


Java Compiler类代码示例

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


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

示例1: testPrivateField

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

    Compilation compilation = Compiler.javac().withProcessors(new StateProcessor()).compile(javaFileObject);
    assertThat(compilation).failed();
    assertThat(compilation)
            .hadErrorContaining("Field test must be either non-private or provide a getter and setter method")
            .inFile(javaFileObject)
            .onLine(7)
            .atColumn(17);
}
 
开发者ID:evernote,项目名称:android-state,代码行数:21,代码来源:TestProcessor.java

示例2: testPrivateClass

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void testPrivateClass() {
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName("TestPrivateClass"), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestPrivateClass {\n"
            + "    private static class Inner {\n"
            + "        @State\n"
            + "        public int test;\n"
            + "    }\n"
            + "}\n");

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

示例3: testStatic

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

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

示例4: testFinal

import com.google.testing.compile.Compiler; //导入依赖的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

示例5: testTypeNotSupported

import com.google.testing.compile.Compiler; //导入依赖的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

示例6: test

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void test() throws URISyntaxException, MalformedURLException {
    Compilation compilation = Compiler.javac()
        .withProcessors(new SyndesisExtensionActionProcessor())
        .compile(JavaFileObjects.forSourceString(
            "test.AnnotatedClassTest",
            "package test;\n" +
            "\n" +
            "@io.syndesis.integration.runtime.api.SyndesisExtensionAction(\n" +
            "    id = \"action-id\",\n" +
            "    name = \"action-name\",\n" +
            "    description = \"action-description\"\n" +
            ")\n" +
            "public class AnnotatedClassTest {\n" +
            "}"
        )
    );

    assertTrue(compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "test/AnnotatedClassTest-action-id.properties").isPresent());
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:21,代码来源:SyndesisExtensionActionProcessorTest.java

示例7: testPrivateProperty

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void testPrivateProperty() {
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName("TestPrivateProperty"), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestPrivateProperty {\n"
            + "    @State\n"
            + "    private int test;\n"
            + "\n"
            + "    private int getTest() {\n"
            + "        return test;\n"
            + "    }\n"
            + "\n"
            + "    public void setTest(int test) {\n"
            + "        this.test = test;\n"
            + "    }\n"
            + "}\n");

    Compilation compilation = Compiler.javac().withProcessors(new StateProcessor()).compile(javaFileObject);
    assertThat(compilation).failed();
    assertThat(compilation)
            .hadErrorContaining("Field test must be either non-private or provide a getter and setter method")
            .inFile(javaFileObject)
            .onLine(7)
            .atColumn(17);
}
 
开发者ID:evernote,项目名称:android-state,代码行数:29,代码来源:TestProcessor.java

示例8: captureDescriptionTest

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void captureDescriptionTest() {
    final String expectedMethodSignatureHash = "-tDqkuCipddkDhc3utZvVw==";

    JavaFileObject source = JavaFileObjects.forSourceLines(
            "io.qameta.allure.descriptions.test.DescriptionSample",
            "package io.qameta.allure.descriptions.test;",
            "import io.qameta.allure.Description;",
            "import org.testng.annotations.Test;",
            "",
            "public class DescriptionSample {",
            "",
            "/**",
            "* Captured javadoc description",
            "*/",
            "@Test",
            "@Description(useJavaDoc = true)",
            "public void sampleTest() {",
            "}",
            "}"
    );

    Compiler compiler = javac().withProcessors(new DescriptionsProcessor());
    Compilation compilation = compiler.compile(source);
    assertThat(compilation).generatedFile(StandardLocation.CLASS_OUTPUT,
            ALLURE_PACKAGE_NAME, expectedMethodSignatureHash);
}
 
开发者ID:allure-framework,项目名称:allure-java,代码行数:28,代码来源:ProcessDescriptionsTest.java

示例9: assertSuccessfulCompile

import com.google.testing.compile.Compiler; //导入依赖的package包/类
void assertSuccessfulCompile( @Nonnull final List<JavaFileObject> inputs,
                              @Nonnull final List<String> outputs )
  throws Exception
{
  if ( outputFiles() )
  {
    final ImmutableList<JavaFileObject> fileObjects =
      Compiler.javac().withProcessors( new ArezProcessor() ).compile( inputs ).generatedSourceFiles();
    for ( final JavaFileObject fileObject : fileObjects )
    {
      final Path target = fixtureDir().resolve( "expected/" + fileObject.getName().replace( "/SOURCE_OUTPUT/", "" ) );
      if ( Files.exists( target ) )
      {
        Files.delete( target );
      }

      final File dir = target.getParent().toFile();
      if ( !dir.exists() )
      {
        assertTrue( dir.mkdirs() );
      }
      Files.copy( fileObject.openInputStream(), target );
    }
  }
  final JavaFileObject firstExpected = fixture( outputs.get( 0 ) );
  final JavaFileObject[] restExpected =
    outputs.stream().skip( 1 ).map( this::fixture ).
      collect( Collectors.toList() ).
      toArray( new JavaFileObject[ 0 ] );
  assert_().about( JavaSourcesSubjectFactory.javaSources() ).
    that( inputs ).
    processedWith( new ArezProcessor() ).
    compilesWithoutError().
    and().
    generatesSources( firstExpected, restExpected );
}
 
开发者ID:arez,项目名称:arez,代码行数:37,代码来源:AbstractArezProcessorTest.java

示例10: GenerationPathHandler

import com.google.testing.compile.Compiler; //导入依赖的package包/类
public GenerationPathHandler(final Class<?> owningClass, Path resourcesDir) {
  super(DEFAULT_GENERATION_ROOT.toFile());

  //noinspection ResultOfMethodCallIgnored
  DEFAULT_GENERATION_ROOT.toFile().mkdirs();

  this.resourcesDir = resourcesDir;

  final String currentClasspath = getClasspathFromClassloader(ClassLoader.getSystemClassLoader());
  compiler = Compiler.javac()
                     .withOptions("-classpath", currentClasspath);
}
 
开发者ID:joel-costigliola,项目名称:assertj-assertions-generator,代码行数:13,代码来源:GenerationPathHandler.java

示例11: testSimple

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void testSimple() {
    String className = "TestSimple";
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName(className), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestSimple {\n"
            + "    @State\n"
            + "    int field;\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString(getName(className, true), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import android.os.Bundle;\n"
            + "import com.evernote.android.state.Bundler;\n"
            + "import com.evernote.android.state.InjectionHelper;\n"
            + "import com.evernote.android.state.Injector;\n"
            + "import java.lang.Override;\n"
            + "import java.lang.String;\n"
            + "import java.lang.SuppressWarnings;\n"
            + "import java.util.HashMap;\n"
            + "\n"
            + "public class TestSimple$$StateSaver<T extends TestSimple> extends Injector.Object<T> {\n"
            + "  private static final HashMap<String, Bundler<?>> BUNDLERS = new HashMap<String, Bundler<?>>();\n"
            + "\n"
            + "  private static final InjectionHelper HELPER = new InjectionHelper(\"com.evernote.android.state.test.TestSimple$$StateSaver\", BUNDLERS);\n"
            + "\n"
            + "  static {\n"
            + "  }\n"
            + "\n"
            + "  @Override\n"
            + "  @SuppressWarnings(\"unchecked\")\n"
            + "  public void save(T target, Bundle state) {\n"
            + "    HELPER.putInt(state, \"field\", target.field);\n"
            + "  }\n"
            + "\n"
            + "  @Override\n"
            + "  @SuppressWarnings(\"unchecked\")\n"
            + "  public void restore(T target, Bundle state) {\n"
            + "    target.field = HELPER.getInt(state, \"field\");\n"
            + "  }\n"
            + "}\n");

    Compilation compilation = Compiler.javac().withProcessors(new StateProcessor()).compile(javaFileObject);
    assertThat(compilation).succeeded();
    assertThat(compilation).generatedSourceFile(getName(className, true)).hasSourceEquivalentTo(expected);
}
 
开发者ID:evernote,项目名称:android-state,代码行数:51,代码来源:TestProcessor.java

示例12: testProperty

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void testProperty() {
    String className = "TestProperty";
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName(className), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestProperty {\n"
            + "    @State\n"
            + "    private int test;\n"
            + "\n"
            + "    public int getTest() {\n"
            + "        return test;\n"
            + "    }\n"
            + "\n"
            + "    public void setTest(int test) {\n"
            + "        this.test = test;\n"
            + "    }\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString(getName(className, true), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import android.os.Bundle;\n"
            + "import com.evernote.android.state.Bundler;\n"
            + "import com.evernote.android.state.InjectionHelper;\n"
            + "import com.evernote.android.state.Injector;\n"
            + "import java.lang.Override;\n"
            + "import java.lang.String;\n"
            + "import java.lang.SuppressWarnings;\n"
            + "import java.util.HashMap;\n"
            + "\n"
            + "public class TestProperty$$StateSaver<T extends TestProperty> extends Injector.Object<T> {\n"
            + "  private static final HashMap<String, Bundler<?>> BUNDLERS = new HashMap<String, Bundler<?>>();\n"
            + "\n"
            + "  private static final InjectionHelper HELPER = new InjectionHelper(\"com.evernote.android.state.test.TestProperty$$StateSaver\", BUNDLERS);\n"
            + "\n"
            + "  static {\n"
            + "  }\n"
            + "\n"
            + "  @Override\n"
            + "  @SuppressWarnings(\"unchecked\")\n"
            + "  public void save(T target, Bundle state) {\n"
            + "    HELPER.putInt(state, \"Test\", target.getTest());\n"
            + "  }\n"
            + "\n"
            + "  @Override\n"
            + "  @SuppressWarnings(\"unchecked\")\n"
            + "  public void restore(T target, Bundle state) {\n"
            + "    target.setTest(HELPER.getInt(state, \"Test\"));\n"
            + "  }\n"
            + "}\n");

    Compilation compilation = Compiler.javac().withProcessors(new StateProcessor()).compile(javaFileObject);
    assertThat(compilation).succeeded();
    assertThat(compilation).generatedSourceFile(getName(className, true)).hasSourceEquivalentTo(expected);
}
 
开发者ID:evernote,项目名称:android-state,代码行数:59,代码来源:TestProcessor.java

示例13: testPrivateClassBundler

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void testPrivateClassBundler() {
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName("TestPrivateClassBundler"), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import android.os.Bundle;\n"
            + "\n"
            + "import com.evernote.android.state.Bundler;\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestPrivateClassBundler {\n"
            + "    @State(MyBundler.class)\n"
            + "    private Data mData2;\n"
            + "\n"
            + "    public Data getData2() {\n"
            + "        return mData2;\n"
            + "    }\n"
            + "\n"
            + "    public void setData2(Data data2) {\n"
            + "        mData2 = data2;\n"
            + "    }\n"
            + "\n"
            + "    public static final class Data {\n"
            + "        private int int1;\n"
            + "        private int int2;\n"
            + "    }\n"
            + "\n"
            + "    private static final class MyBundler implements Bundler<Data> {\n"
            + "        @Override\n"
            + "        public void put(String key, Data value, Bundle bundle) {\n"
            + "            bundle.putInt(key + \"1\", value.int1);\n"
            + "            bundle.putInt(key + \"2\", value.int2);\n"
            + "        }\n"
            + "\n"
            + "        @Override\n"
            + "        public Data get(String key, Bundle bundle) {\n"
            + "            Data data = new Data();\n"
            + "            data.int1 = bundle.getInt(key + \"1\");\n"
            + "            data.int2 = bundle.getInt(key + \"2\");\n"
            + "            return data;\n"
            + "        }\n"
            + "    }\n"
            + "}\n");

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

示例14: testPrivateClassBundlerData

import com.google.testing.compile.Compiler; //导入依赖的package包/类
@Test
public void testPrivateClassBundlerData() {
    JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName("TestPrivateClassBundlerData"), ""
            + "package com.evernote.android.state.test;\n"
            + "\n"
            + "import android.os.Bundle;\n"
            + "\n"
            + "import com.evernote.android.state.Bundler;\n"
            + "import com.evernote.android.state.State;\n"
            + "\n"
            + "public class TestPrivateClassBundlerData {\n"
            + "    @State(MyBundler.class)\n"
            + "    private Data mData2;\n"
            + "\n"
            + "    public Data getData2() {\n"
            + "        return mData2;\n"
            + "    }\n"
            + "\n"
            + "    public void setData2(Data data2) {\n"
            + "        mData2 = data2;\n"
            + "    }\n"
            + "\n"
            + "    private static final class Data {\n"
            + "        private int int1;\n"
            + "        private int int2;\n"
            + "    }\n"
            + "\n"
            + "    public static final class MyBundler implements Bundler<Data> {\n"
            + "        @Override\n"
            + "        public void put(String key, Data value, Bundle bundle) {\n"
            + "            bundle.putInt(key + \"1\", value.int1);\n"
            + "            bundle.putInt(key + \"2\", value.int2);\n"
            + "        }\n"
            + "\n"
            + "        @Override\n"
            + "        public Data get(String key, Bundle bundle) {\n"
            + "            Data data = new Data();\n"
            + "            data.int1 = bundle.getInt(key + \"1\");\n"
            + "            data.int2 = bundle.getInt(key + \"2\");\n"
            + "            return data;\n"
            + "        }\n"
            + "    }\n"
            + "}\n");

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

示例15: assertSuccessfulCompile

import com.google.testing.compile.Compiler; //导入依赖的package包/类
void assertSuccessfulCompile( @Nonnull final List<JavaFileObject> inputs, @Nonnull final List<String> outputs )
  throws Exception
{
  // Arez processor required so that our tests emit all the right outputs
  // when outputFiles() is true
  if ( outputFiles() )
  {
    final ImmutableList<JavaFileObject> fileObjects =
      Compiler.javac().withProcessors( new ReactProcessor(), new ArezProcessor() ).
        compile( inputs ).generatedSourceFiles();
    for ( final JavaFileObject fileObject : fileObjects )
    {
      final Path target = fixtureDir().resolve( "expected/" + fileObject.getName().replace( "/SOURCE_OUTPUT/", "" ) );
      if ( target.toFile().getName().startsWith( "Arez_" ) )
      {
        continue;
      }
      if ( Files.exists( target ) )
      {
        Files.delete( target );
      }

      final File dir = target.getParent().toFile();
      if ( !dir.exists() )
      {
        assertTrue( dir.mkdirs() );
      }
      Files.copy( fileObject.openInputStream(), target );
    }
  }
  final JavaFileObject firstExpected = fixture( outputs.get( 0 ) );
  final JavaFileObject[] restExpected =
    outputs.stream().skip( 1 ).map( this::fixture ).
      collect( Collectors.toList() ).
      toArray( new JavaFileObject[ 0 ] );
  assert_().about( JavaSourcesSubjectFactory.javaSources() ).
    that( inputs ).
    processedWith( new ReactProcessor(), new ArezProcessor() ).
    compilesWithoutError().
    and().
    generatesSources( firstExpected, restExpected );
}
 
开发者ID:react4j,项目名称:react4j,代码行数:43,代码来源:AbstractReactProcessorTest.java


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