package com.greghaskins.spectrum;

import com.greghaskins.spectrum.Spectrum.Block;

import java.util.ArrayList;
import java.util.List;

class AfterEachBlock implements Block {

  private final List<Block> blocks;

  public AfterEachBlock() {
    this.blocks = new ArrayList<>();
  }

  @Override
  public void run() throws Throwable {
    runAllBlocksInReverseOrder(this.blocks.size() - 1);
  }

  private void runAllBlocksInReverseOrder(final int index) throws Throwable {
    if (index < 0) {
      return;
    }
    try {
      this.blocks.get(index).run();
    } finally {
      runAllBlocksInReverseOrder(index - 1);
    }
  }

  public void addBlock(final Block block) {
    this.blocks.add(block);
  }

}

@@ -331,27 +331,33 @@
 le %7B%0A    run
-All
+Remaining
 BlocksInReve
@@ -409,27 +409,33 @@
 ate void run
-All
+Remaining
 BlocksInReve
@@ -453,17 +453,24 @@
 nal int 
-i
+currentI
 ndex) th
@@ -494,17 +494,24 @@
     if (
-i
+currentI
 ndex %3C 0
@@ -566,17 +566,24 @@
 cks.get(
-i
+currentI
 ndex).ru
@@ -616,11 +616,17 @@
  run
-All
+Remaining
 Bloc
@@ -642,17 +642,24 @@
 seOrder(
-i
+currentI
 ndex - 1

Clarify AfterEach execution flow (naming)