@@ -328,8 +328,8 @@ private void parseLine(
328328
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.
331- diffType .forAllTimesOfExistence (beforeStack , afterStack , stack ->
332- popIfChain (stack , fromLine , line )
331+ diffType .forAllTimesOfExistence (time ->
332+ popIfChain (time , fromLine , line )
333333 );
334334 } else if (options .collapseMultipleCodeLines ()
335335 && annotation .type () == AnnotationType .None
@@ -357,20 +357,22 @@ private void parseLine(
357357 }
358358
359359 /**
360- * Pop {@code stack} until an IF node is popped.
360+ * Pop the stack until an IF node is popped.
361361 * If there were ELSEs or ELIFs between an IF and an ENDIF, they were placed on the stack and
362362 * have to be popped now. The {@link DiffNode#getToLine() end line numbers} are adjusted
363363 *
364- * @param stack the stack which should be popped
364+ * @param time which stack to pop the if chain (i.e., {@link beforeStack} or {@link afterStack})
365365 * @param elseLineNumber the first line of the else which causes this IF to be popped
366366 * @param line the line containing the endif
367367 * @throws DiffParseException if {@code stack} doesn't contain an IF node
368368 */
369369 private void popIfChain (
370- Stack < DiffNode < DiffLinesLabel >> stack ,
370+ Time time ,
371371 DiffLineNumber elseLineNumber ,
372372 LogicalLine line
373373 ) throws DiffParseException {
374+ Stack <DiffNode <DiffLinesLabel >> stack = time .match (beforeStack , afterStack );
375+
374376 DiffLineNumber previousLineNumber = elseLineNumber ;
375377 do {
376378 DiffNode <DiffLinesLabel > annotation = stack .peek ();
@@ -381,19 +383,19 @@ private void popIfChain(
381383 for (int i = 0 ; i < line .getLines ().size (); i ++) {
382384 list .add (line .getLines ().get (i ).content ());
383385 }
384- annotation .setEndIf (list , stack == beforeStack ? Time . BEFORE : Time . AFTER );
386+ annotation .setEndIf (list , time );
385387 }
386388
387389 // Set the line number of now closed annotations to the beginning of the
388390 // following annotation.
389391 annotation .setToLine (new DiffLineNumber (
390392 Math .max (previousLineNumber .inDiff (), annotation .getToLine ().inDiff ()),
391- stack == beforeStack
392- ? previousLineNumber .beforeEdit ()
393- : annotation .getToLine ().beforeEdit (),
394- stack == afterStack
395- ? previousLineNumber . afterEdit ()
396- : annotation . getToLine (). afterEdit ()
393+ time . match (
394+ previousLineNumber .beforeEdit (),
395+ annotation .getToLine ().beforeEdit () ),
396+ time . match (
397+ annotation . getToLine (). afterEdit (),
398+ previousLineNumber . afterEdit () )
397399 ));
398400
399401 previousLineNumber = annotation .getFromLine ();
0 commit comments