Skip to content

Commit e0be9d3

Browse files
committed
default DiffTreeSource from parsed linegraph for easier debugging
1 parent ba8d513 commit e0be9d3

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/main/java/org/variantsync/diffdetective/diff/difftree/serialize/LineGraphImport.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.variantsync.diffdetective.diff.difftree.serialize;
22

33
import org.variantsync.diffdetective.diff.difftree.*;
4+
import org.variantsync.diffdetective.diff.difftree.source.LineGraphFileSource;
45
import org.variantsync.diffdetective.util.Assert;
56
import org.variantsync.diffdetective.util.FileUtils;
67
import org.variantsync.functjonal.Pair;
@@ -23,15 +24,15 @@ public class LineGraphImport {
2324
public static List<DiffTree> fromFile(final Path path, final DiffTreeLineGraphImportOptions options) {
2425
Assert.assertTrue(Files.isRegularFile(path));
2526
Assert.assertTrue(FileUtils.isLineGraph(path));
26-
return fromLineGraph(FileUtils.readUTF8(path), options);
27+
return fromLineGraph(FileUtils.readUTF8(path), path, options);
2728
}
2829

2930
/**
3031
* Transforms a line graph into a list of {@link DiffTree DiffTrees}.
3132
*
3233
* @return All {@link DiffTree DiffTrees} contained in the line graph
3334
*/
34-
public static List<DiffTree> fromLineGraph(final String lineGraph, final DiffTreeLineGraphImportOptions options) {
35+
public static List<DiffTree> fromLineGraph(final String lineGraph, final Path originalFile, final DiffTreeLineGraphImportOptions options) {
3536
java.util.Scanner input = new java.util.Scanner(lineGraph);
3637

3738
// All DiffTrees read from the line graph
@@ -57,7 +58,7 @@ public static List<DiffTree> fromLineGraph(final String lineGraph, final DiffTre
5758
// the line represents a DiffTree
5859

5960
if (!diffNodeList.isEmpty()) {
60-
curDiffTree = parseDiffTree(previousDiffTreeLine, diffNodeList, options); // parse to DiffTree
61+
curDiffTree = parseDiffTree(previousDiffTreeLine, originalFile, diffNodeList, options); // parse to DiffTree
6162
diffTreeList.add(curDiffTree); // add newly computed DiffTree to the list of all DiffTrees
6263

6364
// Remove all DiffNodes from list
@@ -100,7 +101,7 @@ public static List<DiffTree> fromLineGraph(final String lineGraph, final DiffTre
100101
input.close();
101102

102103
if (!diffNodeList.isEmpty()) {
103-
curDiffTree = parseDiffTree(previousDiffTreeLine, diffNodeList, options); // parse to DiffTree
104+
curDiffTree = parseDiffTree(previousDiffTreeLine, originalFile, diffNodeList, options); // parse to DiffTree
104105
diffTreeList.add(curDiffTree); // add newly computed DiffTree to the list of all DiffTrees
105106
}
106107

@@ -116,8 +117,16 @@ public static List<DiffTree> fromLineGraph(final String lineGraph, final DiffTre
116117
* @param options {@link DiffTreeLineGraphImportOptions}
117118
* @return {@link DiffTree}
118119
*/
119-
private static DiffTree parseDiffTree(final String lineGraph, final List<DiffNode> diffNodeList, final DiffTreeLineGraphImportOptions options) {
120-
final DiffTreeSource diffTreeSource = options.treeFormat().fromLineGraphLine(lineGraph);
120+
private static DiffTree parseDiffTree(final String lineGraph, final Path inFile, final List<DiffNode> diffNodeList, final DiffTreeLineGraphImportOptions options) {
121+
DiffTreeSource diffTreeSource = options.treeFormat().fromLineGraphLine(lineGraph);
122+
123+
if (diffTreeSource == null || DiffTreeSource.Unknown.equals(diffTreeSource)) {
124+
diffTreeSource = new LineGraphFileSource(
125+
lineGraph,
126+
inFile
127+
);
128+
}
129+
121130
// Handle trees and graphs differently
122131
if (options.graphFormat() == GraphFormat.DIFFGRAPH) {
123132
// If you should interpret the input data as DiffTrees, always expect a root to be present. Parse all nodes (v) to a list of nodes. Search for the root. Assert that there is exactly one root.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.variantsync.diffdetective.diff.difftree.source;
2+
3+
import org.variantsync.diffdetective.diff.difftree.DiffTreeSource;
4+
5+
import java.nio.file.Path;
6+
7+
public record LineGraphFileSource(
8+
String graphHeader,
9+
Path file
10+
) implements DiffTreeSource {
11+
}

0 commit comments

Comments
 (0)