當前位置: 首頁>>代碼示例>>Java>>正文


Java DescriptionBasedDiff類代碼示例

本文整理匯總了Java中com.google.errorprone.apply.DescriptionBasedDiff的典型用法代碼示例。如果您正苦於以下問題:Java DescriptionBasedDiff類的具體用法?Java DescriptionBasedDiff怎麽用?Java DescriptionBasedDiff使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DescriptionBasedDiff類屬於com.google.errorprone.apply包,在下文中一共展示了DescriptionBasedDiff類的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: getDescriptionListener

import com.google.errorprone.apply.DescriptionBasedDiff; //導入依賴的package包/類
@Override
public DescriptionListener getDescriptionListener(Log log, JCCompilationUnit compilation) {
  URI sourceFile = compilation.getSourceFile().toUri();

  DelegatingDescriptionListener delegate =
      new DelegatingDescriptionListener(
          descriptionsFactory.getDescriptionListener(log, compilation),
          DescriptionBasedDiff.createIgnoringOverlaps(compilation, importOrganizer));
  foundSources.put(sourceFile, delegate);
  return delegate;
}
 
開發者ID:google,項目名稱:error-prone,代碼行數:12,代碼來源:RefactoringCollection.java

示例15: 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


注:本文中的com.google.errorprone.apply.DescriptionBasedDiff類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。