本文整理汇总了Java中com.google.errorprone.apply.DescriptionBasedDiff.onDescribed方法的典型用法代码示例。如果您正苦于以下问题:Java DescriptionBasedDiff.onDescribed方法的具体用法?Java DescriptionBasedDiff.onDescribed怎么用?Java DescriptionBasedDiff.onDescribed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.errorprone.apply.DescriptionBasedDiff
的用法示例。
在下文中一共展示了DescriptionBasedDiff.onDescribed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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\");",
" }",
"}");
}
示例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\");",
" }",
"}");
}
示例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\");",
" }",
"}");
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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\");",
" }",
"}");
}
示例12: 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();
}
示例13: overlappingDiffs_throws
import com.google.errorprone.apply.DescriptionBasedDiff; //导入方法依赖的package包/类
@Test
public void overlappingDiffs_throws() {
DescriptionBasedDiff diff = createDescriptionBasedDiff();
assertThrows(
IllegalArgumentException.class,
() ->
diff.onDescribed(
new Description(
null,
"message",
SuggestedFix.builder()
.replace(137, 140, "baz")
.replace(137, 140, "bar")
.build(),
SeverityLevel.SUGGESTION)));
DescriptionBasedDiff diff2 = createDescriptionBasedDiff();
diff2.onDescribed(
new Description(
null,
"bah",
SuggestedFix.builder().replace(137, 140, "baz").build(),
SeverityLevel.SUGGESTION));
assertThrows(
IllegalArgumentException.class,
() ->
diff2.onDescribed(
new Description(
null,
"message",
SuggestedFix.builder().replace(137, 140, "bar").build(),
SeverityLevel.SUGGESTION)));
DescriptionBasedDiff diff3 =
DescriptionBasedDiff.createIgnoringOverlaps(
compilationUnit, ImportOrganizer.STATIC_FIRST_ORGANIZER);
diff3.onDescribed(
new Description(
null,
"bah",
SuggestedFix.builder().replace(137, 140, "baz").build(),
SeverityLevel.SUGGESTION));
// No throw, since it's lenient. Refactors to the first "baz" replacement and ignores this.
diff3.onDescribed(
new Description(
null,
"message",
SuggestedFix.builder().replace(137, 140, "bar").build(),
SeverityLevel.SUGGESTION));
diff3.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(\"baz\");",
" }",
"}")
.inOrder();
}