private void removeLastResults(int numberOfResults, @NotNull MatchContext context) {
    if (numberOfResults == 0) return;
    final MatchResultImpl substitution = context.getResult().getChild(name);

    if (substitution != null) {
      if (substitution.hasChildren()) {
        while (numberOfResults > 0) {
          --numberOfResults;
          final MatchResult matchResult = substitution.removeLastChild();
          context.removeMatchedNode(matchResult.getMatch());
        }
        if (!substitution.hasChildren()) {
          context.getResult().removeChild(name);
        }
      } else {
        final MatchResult matchResult = context.getResult().removeChild(name);
        assert matchResult != null;
        context.removeMatchedNode(matchResult.getMatch());
      }
    }
  }
private void removeLastResults(int numberOfResults, @NotNull MatchContext context)