Skip to content

Commit dee62f8

Browse files
eugen-shulimovibbem
authored andcommitted
fix: store endifs depending on the time
1 parent efb4b2c commit dee62f8

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

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

Lines changed: 7 additions & 5 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 List<String> endIf = null;
54+
private List<String>[] endIf = new List[2];
5555

5656
/**
5757
* The parents {@link DiffNode} before and after the edit.
@@ -150,18 +150,20 @@ public void setLabel(L newLabel) {
150150

151151
/**
152152
* Returns the line with the endif of the corresponding if, if the node is an if node, otherwise null
153+
* @param time when the returned endif exists
153154
* @return String, the Line with endif
154155
*/
155-
public List<String> getEndIf() {
156-
return endIf;
156+
public List<String> getEndIf(Time time) {
157+
return endIf[time.ordinal()];
157158
}
158159

159160
/**
160161
* Sets the line with the endif of the corresponding if, if the node is an if node
161162
* @param endIf String, the Line with endif
163+
* @param time when {@code endIf} exists
162164
*/
163-
public void setEndIf(List<String> endIf) {
164-
this.endIf = endIf;
165+
public void setEndIf(List<String> endIf, Time time) {
166+
this.endIf[time.ordinal()] = endIf;
165167
}
166168

167169
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ public int getID() {
124124

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

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private void parseLine(
329329
// Do not create a node for ENDIF, but update the line numbers of the closed if-chain
330330
// and remove that if-chain from the relevant stacks.
331331
diffType.forAllTimesOfExistence(beforeStack, afterStack, stack ->
332-
popIfChain(stack, fromLine, line)
332+
popIfChain(stack, fromLine, line, diffType)
333333
);
334334
} else if (options.collapseMultipleCodeLines()
335335
&& annotation.type() == AnnotationType.None
@@ -369,17 +369,27 @@ private void parseLine(
369369
private void popIfChain(
370370
Stack<DiffNode<DiffLinesLabel>> stack,
371371
DiffLineNumber elseLineNumber,
372-
LogicalLine line
372+
LogicalLine line,
373+
DiffType diffType
373374
) throws DiffParseException {
374375
DiffLineNumber previousLineNumber = elseLineNumber;
375376
do {
376377
DiffNode<DiffLinesLabel> annotation = stack.peek();
378+
379+
// Save endif
377380
if (annotation.isIf()) {
378381
List<String> list = new ArrayList<>();
379382
for (int i = 0; i < line.getLines().size(); i++) {
380383
list.add(line.getLines().get(i).content());
381384
}
382-
annotation.setEndIf(list);
385+
if (diffType.existsBefore() && diffType.existsAfter()) {
386+
annotation.setEndIf(list, Time.BEFORE);
387+
annotation.setEndIf(list, Time.AFTER);
388+
} else if (diffType.existsBefore()) {
389+
annotation.setEndIf(list, Time.BEFORE);
390+
} else {
391+
annotation.setEndIf(list, Time.AFTER);
392+
}
383393
}
384394

385395
// Set the line number of now closed annotations to the beginning of the

0 commit comments

Comments
 (0)