package ch.unibe.scg.regex;

interface CaptureGroup {
  /**
   * Returns increasing capture groups, including their tags. The first returned capture group is 1.
   */
  static class CaptureGroupMaker {
    /**
     * Don't instantiate directly. Use {@link CaptureGroupMaker} instead.
     */
    static class RealCaptureGroup implements CaptureGroup {
      static RealCaptureGroup make(final int number) {
        final RealCaptureGroup cg = new RealCaptureGroup(number);
        cg.startTag = Tag.RealTag.makeStartTag(cg);
        cg.endTag = Tag.RealTag.makeEndTag(cg);
        return cg;
      }

      Tag endTag;
      final int number;

      Tag startTag;

      private RealCaptureGroup(final int number) {
        this.number = number;
      }

      public Tag getEndTag() {
        assert endTag != null;
        return endTag;
      }

      public int getNumber() {
        return number;
      }

      public Tag getStartTag() {
        assert startTag != null;
        return startTag;
      }

      @Override
      public String toString() {
        return "g" + number;
      }
    }

    CaptureGroup last = new RealCaptureGroup(0);

    synchronized CaptureGroup next() {
      last = RealCaptureGroup.make(last.getNumber() + 1);
      return last;
    }
  }

  public Tag getEndTag();

  public int getNumber();

  public Tag getStartTag();
}

@@ -195,16 +195,50 @@
 Maker %7B%0A
+    CaptureGroup last = make(0);%0A%0A
     /**%0A
@@ -389,37 +389,36 @@
     
-static RealCaptureGroup make(
+Tag startTag, endTag;%0A      
 fina
@@ -433,269 +433,71 @@
 mber
-) %7B
+;%0A
 %0A      
-  final RealCaptureGroup cg = new RealCaptureGroup(number);%0A        cg.startTag = Tag.RealTag.makeStartTag(cg);%0A        cg.endTag = Tag.RealTag.makeEndTag(cg);%0A        return cg;%0A      %7D%0A%0A      Tag endTag;%0A      final int number;%0A%0A      Tag startTag;%0A
+/** Call %7B@link RealCaptureGroup#make(int)%7D instead */
 %0A   
@@ -933,24 +933,28 @@
 %0A    %7D%0A%0A    
+Real
 CaptureGroup
@@ -958,44 +958,227 @@
 oup 
-last = new RealCaptureGroup(0);%0A%0A   
+make(final int number) %7B%0A      final RealCaptureGroup cg = new RealCaptureGroup(number);%0A      cg.startTag = Tag.RealTag.makeStartTag(cg);%0A      cg.endTag = Tag.RealTag.makeEndTag(cg);%0A      return cg;%0A    %7D%0A%0A    public
  syn
@@ -1226,25 +1226,8 @@
 t = 
-RealCaptureGroup.
 make

Move make into the CaptureGroupMaker