Skip to content

Commit

Permalink
Provide alternate diffing mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Aug 18, 2016
1 parent f428a59 commit 96924fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/com/netflix/java/refactor/JavaSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.netflix.java.refactor.find.*
import com.sun.tools.javac.code.Symbol
import com.sun.tools.javac.tree.JCTree
import java.nio.file.Files
import java.util.function.Consumer
import kotlin.concurrent.thread

class JavaSource(internal val cu: CompilationUnit) {
var changedFile = false
Expand Down Expand Up @@ -51,4 +53,6 @@ class JavaSource(internal val cu: CompilationUnit) {
val after = text()
return InMemoryDiffEntry(file().toString(), before, after).diff
}

fun beginDiff() = JavaSourceDiff(this)
}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/netflix/java/refactor/JavaSourceDiff.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.netflix.java.refactor

class JavaSourceDiff(private val source: JavaSource) {
val before = source.text()

fun gitStylePatch(): String {
val after = source.text()
return InMemoryDiffEntry(source.file().toString(), before, after).diff
}
}
13 changes: 9 additions & 4 deletions src/test/kotlin/com/netflix/java/refactor/JavaSourceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ class JavaSourceTest : AbstractRefactorTest() {
""")

val source = parseJava(a, b, c)
val diff = source.diff {
val diff1 = source.beginDiff()

val diff2 = source.diff {
refactor().changeType("B", "C").fix()
}
assertEquals("""

val expectedDiff = """
|diff --git a/${a.absolutePath} b/${a.absolutePath}
|index 70f03ee..b82f543 100644
|--- a/${a.absolutePath}
Expand All @@ -105,6 +107,9 @@ class JavaSourceTest : AbstractRefactorTest() {
| }
| }
|
""".trimMargin(), diff)
""".trimMargin()

assertEquals(expectedDiff, diff1.gitStylePatch())
assertEquals(expectedDiff, diff2)
}
}

0 comments on commit 96924fd

Please sign in to comment.