Skip to content

Commit e9fb7c5

Browse files
eugen-shulimovibbem
authored andcommitted
feat: store endif lines when parsing variation diffs
1 parent 02f7340 commit e9fb7c5

7 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/main/java/org/variantsync/diffdetective/variation/VariationUnparser.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.variantsync.diffdetective.variation;
22

3-
import java.util.ArrayList;
43
import java.util.Stack;
54
import org.variantsync.diffdetective.variation.tree.VariationTree;
65
import org.variantsync.diffdetective.variation.tree.VariationTreeNode;
@@ -19,10 +18,8 @@ public static String variationTreeUnparser(VariationTree<? extends Label> tree)
1918
result.append("\n");
2019
}
2120
if (node.isIf()) {
22-
ArrayList<String> list = new ArrayList<>();
23-
list.add(node.getEndIf());
2421
stack.push(new VariationTreeNode<>(NodeType.ARTIFACT, null, null,
25-
DiffLinesLabel.withInvalidLineNumbers(list)));
22+
DiffLinesLabel.withInvalidLineNumbers(node.getEndIf())));
2623
}
2724
for (int i = node.getChildren().size() - 1; i >= 0; i--) {
2825
stack.push(node.getChildren().get(i));

src/main/java/org/variantsync/diffdetective/variation/diff/DiffNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class DiffNode<L extends Label> implements HasNodeType {
5151

5252
private Node featureMapping;
5353

54-
private String endIf = null;
54+
private List<String> endIf = null;
5555

5656
/**
5757
* The parents {@link DiffNode} before and after the edit.
@@ -152,15 +152,15 @@ public void setLabel(L newLabel) {
152152
* Returns the line with the endif of the corresponding if, if the node is an if node, otherwise null
153153
* @return String, the Line with endif
154154
*/
155-
public String getEndIf() {
155+
public List<String> getEndIf() {
156156
return endIf;
157157
}
158158

159159
/**
160160
* Sets the line with the endif of the corresponding if, if the node is an if node
161161
* @param endIf String, the Line with endif
162162
*/
163-
public void setEndIf(String endIf) {
163+
public void setEndIf(List<String> endIf) {
164164
this.endIf = endIf;
165165
}
166166

src/main/java/org/variantsync/diffdetective/variation/diff/Projection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public int getID() {
123123
}
124124

125125
@Override
126-
public String getEndIf() {
126+
public List<String> getEndIf() {
127127
return getBackingNode().getEndIf();
128128
}
129129
};

src/main/java/org/variantsync/diffdetective/variation/diff/parse/VariationDiffParser.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.variantsync.diffdetective.variation.diff.parse;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import org.apache.commons.lang3.function.FailableSupplier;
46
import org.eclipse.jgit.api.Git;
57
import org.eclipse.jgit.lib.ObjectId;
@@ -327,7 +329,7 @@ private void parseLine(
327329
// Do not create a node for ENDIF, but update the line numbers of the closed if-chain
328330
// and remove that if-chain from the relevant stacks.
329331
diffType.forAllTimesOfExistence(beforeStack, afterStack, stack ->
330-
popIfChain(stack, fromLine)
332+
popIfChain(stack, fromLine, line)
331333
);
332334
} else if (options.collapseMultipleCodeLines()
333335
&& annotation.type() == AnnotationType.None
@@ -361,15 +363,24 @@ private void parseLine(
361363
*
362364
* @param stack the stack which should be popped
363365
* @param elseLineNumber the first line of the else which causes this IF to be popped
366+
* @param line the line containing the endif
364367
* @throws DiffParseException if {@code stack} doesn't contain an IF node
365368
*/
366369
private void popIfChain(
367370
Stack<DiffNode<DiffLinesLabel>> stack,
368-
DiffLineNumber elseLineNumber
371+
DiffLineNumber elseLineNumber,
372+
LogicalLine line
369373
) throws DiffParseException {
370374
DiffLineNumber previousLineNumber = elseLineNumber;
371375
do {
372376
DiffNode<DiffLinesLabel> annotation = stack.peek();
377+
if (annotation.isIf()) {
378+
List<String> list = new ArrayList<>();
379+
for (int i = 0; i < line.getLines().size(); i++) {
380+
list.add(line.getLines().get(i).content());
381+
}
382+
annotation.setEndIf(list);
383+
}
373384

374385
// Set the line number of now closed annotations to the beginning of the
375386
// following annotation.

src/main/java/org/variantsync/diffdetective/variation/tree/VariationNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public VariationNode<T, L> downCast() {
117117
* Returns the line with the endif of the corresponding if, if the node is an if node, otherwise null
118118
* @return String, the Line with endif
119119
*/
120-
public abstract String getEndIf();
120+
public abstract List<String> getEndIf();
121121

122122
/**
123123
* Returns {@code true} iff this node has no parent.

src/main/java/org/variantsync/diffdetective/variation/tree/VariationTreeNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class VariationTreeNode<L extends Label> extends VariationNode<VariationT
8585
/**
8686
* The line with the endif of the corresponding if, if the node is an if node, otherwise null
8787
*/
88-
private String endIf = null;
88+
private List<String> endIf = null;
8989

9090
/**
9191
* Creates a new node of a variation tree.
@@ -235,15 +235,15 @@ public void removeAllChildren() {
235235
* Returns the line with the endif of the corresponding if, if the node is an if node, otherwise null
236236
* @return String, the Line with endif
237237
*/
238-
public String getEndIf() {
238+
public List<String> getEndIf() {
239239
return endIf;
240240
}
241241

242242
/**
243243
* Sets the line with the endif of the corresponding if, if the node is an if node
244244
* @param endIf String, the Line with endif
245245
*/
246-
public void setEndIf(String endIf) {
246+
public void setEndIf(List<String> endIf) {
247247
this.endIf = endIf;
248248
}
249249

src/test/java/VariationUnparserTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public void tests() {
3333
findTestCases(testDir).forEach(this::test);
3434
}
3535

36-
@Disabled
3736
@Test
3837
public void teststest() {
3938
Path path = testDir.resolve("test2.txt");

0 commit comments

Comments
 (0)