/**
   * Tries to find a {@link DelayedReference#getQueryElement() foreach property init} on the delayed
   * reference <code>ref</code>. Assuming that <code>ref</code> is a {@link
   * DelayedReference.ReferenceType#TYPE_FOREACH_PREDICATE} reference, its {@link
   * DelayedReference#getPredicateActionList() predicate list} (the list of when/as/mode clauses} is
   * used to find the position/index of <code>activePredicateSemantic</code>. At this position, the
   * {@link com.sap.furcas.metamodel.FURCAS.TCS.PredicateSemantic#getAs() template} to be used for
   * production is looked up.
   *
   * <p>If either the reference doesn't have the property init set in its {@link
   * DelayedReference#getQueryElement()}, <code>null</code> is returned. This will in particular be
   * the case if the parser is not configured to produce text blocks.
   */
  private Template getTemplateFromPredicateSemantic(
      PredicateSemantic activePredicateSemantic, DelayedReference ref) {
    int index = ref.getPredicateActionList().indexOf(activePredicateSemantic);
    if (index >= 0 && ((ForeachPredicatePropertyInit) ref.getQueryElement()) != null) {
      int i = 0;

      for (com.sap.furcas.metamodel.FURCAS.TCS.PredicateSemantic predSem :
          ((ForeachPredicatePropertyInit) ref.getQueryElement()).getPredicateSemantic()) {
        if (i++ == index) {
          return predSem.getAs();
        }
      }
      return null;
    } else {
      return null;
    }
  }
 /**
  * Finds the next {@link ForEachExecution} in the collection iterated by <code>
  * foreachContextIterator</code> that is for the same {@link DelayedReference#getQueryElement()
  * property init} as the <code>reference</code> and that is for the same {@link
  * ForEachExecution#getSourceModelElement() source element} as the <code>reference</code>. If no
  * such element is found, <code>null</code> is returned
  *
  * <p>Postcondition: if a non-<code>null</code> result is returned, the <code>
  * foreachContextIterator</code> is at that element so that calling {@link Iterator#remove()}
  * removes the element just returned
  *
  * @param foreachContextIterator must not be <code>null</code>
  */
 private ForEachExecution getNextForeachContext(
     Iterator<ForEachExecution> foreachContextIterator, DelayedReference reference) {
   ForEachExecution result = null;
   while (foreachContextIterator.hasNext() && result == null) {
     ForEachExecution fec = foreachContextIterator.next();
     if (fec.getForeachPedicatePropertyInit().equals(reference.getQueryElement())
         && reference.getModelElement().equals(fec.getSourceModelElement())) {
       result = fec;
     }
   }
   return result;
 }
 private ForEachExecution produceNewForEachContext(
     DelayedReference reference, ForeachProductionResult producedResult) {
   ForEachExecution newContext = TextblocksFactory.eINSTANCE.createForEachExecution();
   newContext.setForeachPedicatePropertyInit(
       (ForeachPredicatePropertyInit) reference.getQueryElement());
   newContext.setSourceModelElement((EObject) reference.getModelElement());
   newContext.setContextElement(
       (EObject) producedResult.getForeachExpressionResultForWhichProduced());
   newContext.setTemplateUsedForProduction(producedResult.getTemplateUsedForProduction());
   newContext.setResultModelElement((EObject) reference.getRealValue());
   return newContext;
 }