/*
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

package cx2x.xcodeml.transformation;

import cx2x.xcodeml.xelement.XcodeProgram;
import cx2x.xcodeml.exception.*;

import java.util.List;

/**
 * An dependent transformation group check wether it can be transformed with
 * another pending transformation in the pipeline. Each transformation are
 * applied only once.
 *
 * @author clementval
 */

public class DependentTransformationGroup extends TransformationGroup {

  /**
   * DependentTransformationGroup ctor.
   * @param name A friendly name to describe the transformation group.
   */
  public DependentTransformationGroup(String name) {
    super(name);
  }

  /**
   * @see TransformationGroup#applyTranslations(XcodeProgram, Transformer)
   */
  public void applyTranslations(XcodeProgram xcodeml, Transformer transformer)
    throws Exception
  {
    List<Transformation> transformations = getTransformations();
    for(int i = 0; i < transformations.size(); ++i){
      Transformation base = transformations.get(i);
      for(int j = i + 1; j < transformations.size(); ++j){
        Transformation candidate = transformations.get(j);
        if(candidate.isTransformed()){
          continue;
        }
        if(base.canBeTransformedWith(candidate)){
          try {
            base.transform(xcodeml, transformer, candidate);
          } catch (IllegalTransformationException itex) {
            // Catch the exception to add line information and rethrow it
            if(itex.getStartLine() == 0){
              itex.setStartLine(base.getStartLine());
            }
            throw itex;
          }
        }
      }
    }
  }

  /**
   * Add a new transformation in the group. As transformation are dependent
   * between each other, the position in the list is determined by the
   * transformation's start line.
   * @see TransformationGroup#add(Transformation)
   */
  public void add(Transformation transformation){
    int linePosition = transformation.getStartLine();
    int insertIndex = 0;
    for(Transformation t : getTransformations()){
      if(t.getStartLine() > linePosition){
        break;
      }
      ++insertIndex;
    }
    getTransformations().add(insertIndex, transformation);
  }
}

@@ -1929,32 +1929,44 @@
 ormation)%0A   */%0A
+  @Override%0A
   public void ad

Add override annotation