Search in sources :

Example 11 with DescriptionBasedDiff

use of com.google.errorprone.apply.DescriptionBasedDiff in project error-prone by google.

the class DescriptionBasedDiffTest method twoDiffsWithImport.

@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();
}
Also used : DescriptionBasedDiff(com.google.errorprone.apply.DescriptionBasedDiff) Description(com.google.errorprone.matchers.Description) Test(org.junit.Test)

Example 12 with DescriptionBasedDiff

use of com.google.errorprone.apply.DescriptionBasedDiff in project error-prone by google.

the class DescriptionBasedDiffTest method noDiffs.

@Test
public void noDiffs() {
    DescriptionBasedDiff diff = createDescriptionBasedDiff();
    diff.applyDifferences(sourceFile);
    assertThat(sourceFile.getLines()).containsExactly((Object[]) lines).inOrder();
}
Also used : DescriptionBasedDiff(com.google.errorprone.apply.DescriptionBasedDiff) Test(org.junit.Test)

Example 13 with DescriptionBasedDiff

use of com.google.errorprone.apply.DescriptionBasedDiff in project error-prone by google.

the class DescriptionBasedDiffTest method removeImport.

@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();
}
Also used : DescriptionBasedDiff(com.google.errorprone.apply.DescriptionBasedDiff) Description(com.google.errorprone.matchers.Description) Test(org.junit.Test)

Example 14 with DescriptionBasedDiff

use of com.google.errorprone.apply.DescriptionBasedDiff in project error-prone by google.

the class DescriptionBasedDiffTest method prefixDiff.

@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();
}
Also used : DescriptionBasedDiff(com.google.errorprone.apply.DescriptionBasedDiff) Description(com.google.errorprone.matchers.Description) Test(org.junit.Test)

Aggregations

DescriptionBasedDiff (com.google.errorprone.apply.DescriptionBasedDiff)14 Description (com.google.errorprone.matchers.Description)11 Test (org.junit.Test)11 SourceFile (com.google.errorprone.apply.SourceFile)3 JavaFileObject (javax.tools.JavaFileObject)3 TreePath (com.sun.source.util.TreePath)2 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)2 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)2 IOException (java.io.IOException)2 DiagnosticCollector (javax.tools.DiagnosticCollector)2 ImportOrganizer (com.google.errorprone.apply.ImportOrganizer)1 JavacTask (com.sun.source.util.JavacTask)1 Arguments (com.sun.tools.javac.main.Arguments)1 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)1 Context (com.sun.tools.javac.util.Context)1 ArrayList (java.util.ArrayList)1 JavaCompiler (javax.tools.JavaCompiler)1 JavaFileManager (javax.tools.JavaFileManager)1 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1