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


Java DescriptionBasedDiff.applyDifferences方法代码示例

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


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

示例1: twoDiffs

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void twoDiffs() {
  DescriptionBasedDiff diff = DescriptionBasedDiff.create(compilationUnit);
  diff.onDescribed(new Description(null, "message", 
      SuggestedFix.builder()
          .replace(83, 86, "longer")
          .replace(96, 99, "bar")
          .build(),
      SeverityLevel.NOT_A_PROBLEM));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines()).iteratesAs(
      "package foo.bar;",
      "class Foo {",
      "  public static void main(String[] args) {",
      "    System.longer.println(\"bar\");",
      "  }", 
      "}");
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:19,代码来源:DescriptionBasedDiffTest.java

示例2: addImport

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void addImport() {
  DescriptionBasedDiff diff = DescriptionBasedDiff.create(compilationUnit);
  diff.onDescribed(new Description(null, "message", 
      SuggestedFix.builder().addImport("com.google.foo.Bar").build(),
      SeverityLevel.NOT_A_PROBLEM));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines()).iteratesAs(
      "package foo.bar;",
      "",
      "import com.google.foo.Bar;",
      "class Foo {",
      "  public static void main(String[] args) {",
      "    System.out.println(\"foo\");",
      "  }", 
      "}");
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:18,代码来源:DescriptionBasedDiffTest.java

示例3: twoDiffsWithImport

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void twoDiffsWithImport() {
  DescriptionBasedDiff diff = DescriptionBasedDiff.create(compilationUnit);
  diff.onDescribed(new Description(null, "message", 
      SuggestedFix.builder()
          .replace(83, 86, "longer")
          .replace(96, 99, "bar")
          .addImport("com.google.foo.Bar")
          .build(),
      SeverityLevel.NOT_A_PROBLEM));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines()).iteratesAs(
      "package foo.bar;",
      "",
      "import com.google.foo.Bar;",
      "class Foo {",
      "  public static void main(String[] args) {",
      "    System.longer.println(\"bar\");",
      "  }", 
      "}");
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:22,代码来源:DescriptionBasedDiffTest.java

示例4: applyDiff

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
private JavaFileObject applyDiff(
    JavaFileObject sourceFileObject, Context context, JCCompilationUnit tree) throws IOException {
  ImportOrganizer importOrganizer = ImportOrderParser.getImportOrganizer(importOrder);
  final DescriptionBasedDiff diff = DescriptionBasedDiff.create(tree, importOrganizer);
  transformer(refactoringBugChecker)
      .apply(
          new TreePath(tree),
          context,
          new DescriptionListener() {
            @Override
            public void onDescribed(Description description) {
              if (!description.fixes.isEmpty()) {
                diff.handleFix(fixChooser.choose(description.fixes));
              }
            }
          });
  SourceFile sourceFile = SourceFile.create(sourceFileObject);
  diff.applyDifferences(sourceFile);

  JavaFileObject transformed =
      JavaFileObjects.forSourceString(getFullyQualifiedName(tree), sourceFile.getSourceText());
  return transformed;
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:BugCheckerRefactoringTestHelper.java

示例5: oneDiff

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void oneDiff() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null, "message", SuggestedFix.replace(137, 140, "bar"), SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "import org.bar.Baz;",
          "import com.foo.Bar;",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.out.println(\"bar\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:DescriptionBasedDiffTest.java

示例6: prefixDiff

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void prefixDiff() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null, "message", SuggestedFix.replace(140, 140, "bar"), SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "import org.bar.Baz;",
          "import com.foo.Bar;",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.out.println(\"foobar\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:DescriptionBasedDiffTest.java

示例7: twoDiffs

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void twoDiffs() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null,
          "message",
          SuggestedFix.builder().replace(124, 127, "longer").replace(137, 140, "bar").build(),
          SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "import org.bar.Baz;",
          "import com.foo.Bar;",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.longer.println(\"bar\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:DescriptionBasedDiffTest.java

示例8: applyDifferences_addsImportAndSorts_whenAddingNewImport

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void applyDifferences_addsImportAndSorts_whenAddingNewImport() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null,
          "message",
          SuggestedFix.builder().addImport("com.google.foo.Bar").build(),
          SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "import com.foo.Bar;",
          "import com.google.foo.Bar;",
          "import org.bar.Baz;",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.out.println(\"foo\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:25,代码来源:DescriptionBasedDiffTest.java

示例9: applyDifferences_preservesImportOrder_whenAddingExistingImport

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void applyDifferences_preservesImportOrder_whenAddingExistingImport() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null,
          "message",
          SuggestedFix.builder().addImport("com.foo.Bar").build(),
          SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "import org.bar.Baz;",
          "import com.foo.Bar;",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.out.println(\"foo\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:DescriptionBasedDiffTest.java

示例10: removeImport

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void removeImport() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null,
          "message",
          SuggestedFix.builder().removeImport("com.foo.Bar").removeImport("org.bar.Baz").build(),
          SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.out.println(\"foo\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:DescriptionBasedDiffTest.java

示例11: applyDifferences_preservesOrder_whenRemovingNonExistentImport

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void applyDifferences_preservesOrder_whenRemovingNonExistentImport() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null,
          "message",
          SuggestedFix.builder().removeImport("com.google.foo.Bar").build(),
          SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "import org.bar.Baz;",
          "import com.foo.Bar;",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.out.println(\"foo\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:DescriptionBasedDiffTest.java

示例12: oneDiff

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void oneDiff() {
  DescriptionBasedDiff diff = DescriptionBasedDiff.create(compilationUnit);
  diff.onDescribed(new Description(null, "message", SuggestedFix.replace(96, 99, "bar"),
      SeverityLevel.NOT_A_PROBLEM));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines()).iteratesAs(
      "package foo.bar;",
      "class Foo {",
      "  public static void main(String[] args) {",
      "    System.out.println(\"bar\");",
      "  }", 
      "}");
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:15,代码来源:DescriptionBasedDiffTest.java

示例13: transform

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
public JavaFileObject transform(JavaFileObject original) {
  JavaCompiler compiler = JavacTool.create();
  DiagnosticCollector<JavaFileObject> diagnosticsCollector =
      new DiagnosticCollector<JavaFileObject>();
  StandardJavaFileManager fileManager =
      compiler.getStandardFileManager(diagnosticsCollector, Locale.ENGLISH, UTF_8);
  JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(CharStreams.nullWriter(),
      fileManager,
      diagnosticsCollector,
      ImmutableList.<String>of(),
      null,
      ImmutableList.of(original));

  try {
    SourceFile sourceFile = SourceFile.create(original);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    task.analyze();
    JCCompilationUnit tree =
        FluentIterable.from(trees).filter(JCCompilationUnit.class).getOnlyElement();
    DescriptionBasedDiff diff = DescriptionBasedDiff.create(tree);
    transformer().apply(tree, task.getContext(), diff);
    diff.applyDifferences(sourceFile);

    return JavaFileObjects.forSourceString(
        FluentIterable.from(tree.getTypeDecls())
            .filter(JCClassDecl.class)
            .getOnlyElement()
            .sym.getQualifiedName().toString(),
        sourceFile.getSourceText());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:34,代码来源:CodeTransformerTestHelper.java

示例14: twoDiffsWithImport

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void twoDiffsWithImport() {
  DescriptionBasedDiff diff = createDescriptionBasedDiff();
  diff.onDescribed(
      new Description(
          null,
          "message",
          SuggestedFix.builder()
              .replace(124, 127, "longer")
              .replace(137, 140, "bar")
              .addImport("com.google.foo.Bar")
              .build(),
          SeverityLevel.SUGGESTION));
  diff.applyDifferences(sourceFile);
  assertThat(sourceFile.getLines())
      .containsExactly(
          "package foo.bar;",
          "import com.foo.Bar;",
          "import com.google.foo.Bar;",
          "import org.bar.Baz;",
          "",
          "class Foo {",
          "  public static void main(String[] args) {",
          "    System.longer.println(\"bar\");",
          "  }",
          "}")
      .inOrder();
}
 
开发者ID:google,项目名称:error-prone,代码行数:29,代码来源:DescriptionBasedDiffTest.java

示例15: transform

import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
public JavaFileObject transform(JavaFileObject original) {
  JavaCompiler compiler = JavacTool.create();
  DiagnosticCollector<JavaFileObject> diagnosticsCollector =
      new DiagnosticCollector<JavaFileObject>();
  StandardJavaFileManager fileManager =
      compiler.getStandardFileManager(diagnosticsCollector, Locale.ENGLISH, UTF_8);
  JavacTaskImpl task =
      (JavacTaskImpl)
          compiler.getTask(
              CharStreams.nullWriter(),
              fileManager,
              diagnosticsCollector,
              ImmutableList.<String>of(),
              null,
              ImmutableList.of(original));

  try {
    SourceFile sourceFile = SourceFile.create(original);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    task.analyze();
    JCCompilationUnit tree =
        Iterables.getOnlyElement(Iterables.filter(trees, JCCompilationUnit.class));
    DescriptionBasedDiff diff =
        DescriptionBasedDiff.create(tree, ImportOrganizer.STATIC_FIRST_ORGANIZER);
    transformer().apply(new TreePath(tree), task.getContext(), diff);
    diff.applyDifferences(sourceFile);

    return JavaFileObjects.forSourceString(
        Iterables.getOnlyElement(Iterables.filter(tree.getTypeDecls(), JCClassDecl.class))
            .sym
            .getQualifiedName()
            .toString(),
        sourceFile.getSourceText());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:38,代码来源:CodeTransformerTestHelper.java


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