11package org .variantsync .diffdetective .diff .difftree .serialize ;
22
33import org .variantsync .diffdetective .diff .difftree .*;
4+ import org .variantsync .diffdetective .diff .difftree .source .LineGraphFileSource ;
45import org .variantsync .diffdetective .util .Assert ;
56import org .variantsync .diffdetective .util .FileUtils ;
67import 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.
0 commit comments