protected void compile(
     SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) {
   if (compilingFirstGroup && additionalUnits != null) {
     // add any source file from additionalUnits to units if it defines secondary types
     // otherwise its possible during testing with MAX_AT_ONCE == 1 that a secondary type
     // can cause an infinite loop as it alternates between not found and defined, see bug 146324
     ArrayList extras = null;
     for (int i = 0, l = additionalUnits.length; i < l; i++) {
       SourceFile unit = additionalUnits[i];
       if (unit != null && this.newState.getDefinedTypeNamesFor(unit.typeLocator()) != null) {
         if (JavaBuilder.DEBUG)
           System.out.println(
               "About to compile file with secondary types " + unit.typeLocator()); // $NON-NLS-1$
         if (extras == null) extras = new ArrayList(3);
         extras.add(unit);
       }
     }
     if (extras != null) {
       int oldLength = units.length;
       int toAdd = extras.size();
       System.arraycopy(units, 0, units = new SourceFile[oldLength + toAdd], 0, oldLength);
       for (int i = 0; i < toAdd; i++) units[oldLength++] = (SourceFile) extras.get(i);
     }
   }
   super.compile(units, additionalUnits, compilingFirstGroup);
 }
  protected void buildAfterBatchBuild() {
    // called from a batch builder once all source files have been compiled AND some changes
    // need to be propagated incrementally (annotations, missing secondary types)

    if (JavaBuilder.DEBUG)
      System.out.println(
          "INCREMENTAL build after batch build @ "
              + new Date(System.currentTimeMillis())); // $NON-NLS-1$

    // this is a copy of the incremental build loop
    try {
      addAffectedSourceFiles();
      while (this.sourceFiles.size() > 0) {
        this.notifier.checkCancel();
        SourceFile[] allSourceFiles = new SourceFile[this.sourceFiles.size()];
        this.sourceFiles.toArray(allSourceFiles);
        resetCollections();
        this.notifier.setProgressPerCompilationUnit(0.08f / allSourceFiles.length);
        this.workQueue.addAll(allSourceFiles);
        compile(allSourceFiles);
        removeSecondaryTypes();
        addAffectedSourceFiles();
      }
    } catch (CoreException e) {
      throw internalException(e);
    } finally {
      cleanUp();
    }
  }