Program: 74480
Project: 74480
Buggy source:
/** 
 * This is the main function which tries to generate the system  description with the type StringBuffer where its content is  acceptable by the tool RED (Regional Encoding Diagram). 
 * @param PreModel The original model in Ptolemy II
 * @param pattern The temporal formula in TCTL
 * @param choice  Specify the type of formula: buffer overflow detectionor general TCTL formula
 * @param span The size of the span used for domain analysis.
 * @param bufferSizeFSM Specify for each of the input port, the size ofthe buffer used for buffer overflow detection.
 * @return A Communicating Timed Automata system description of the original system
 * @throws IllegalActionException
 */
public static StringBuffer generateREDDescription(CompositeActor PreModel,String pattern,String choice,String span,String bufferSizeFSM) throws IllegalActionException {
  StringBuffer returnREDFormat=new StringBuffer("String_Node_Str");
  CompositeActor model=generateEquivalentSystemWithoutHierachy(PreModel);
  StringBuffer constantDefinition=new StringBuffer("String_Node_Str");
  StringBuffer variableDefinition=new StringBuffer("String_Node_Str");
  ArrayList<String> globalClockSet=new ArrayList<String>();
  StringBuffer moduleDefinition=new StringBuffer("String_Node_Str");
  HashSet<String> globalSynchronizerSet=new HashSet<String>();
  HashSet<String> variableAndItsInitialCondition=new HashSet<String>();
  ArrayList<REDModuleNameInitialBean> processModuleNameList=new ArrayList<REDModuleNameInitialBean>();
  ArrayList<REDModuleNameInitialBean> processModulePortList=new ArrayList<REDModuleNameInitialBean>();
  for (Iterator actors=(((CompositeActor)model).entityList()).iterator(); actors.hasNext(); ) {
    Entity innerEntity=(Entity)actors.next();
    HashSet<String> setOfSynchronizes=_decideSynchronizerVariableSet(innerEntity);
    Iterator<String> it=setOfSynchronizes.iterator();
    while (it.hasNext()) {
      globalSynchronizerSet.add(it.next());
    }
  }
  for (Iterator actors=(((CompositeActor)model).entityList()).iterator(); actors.hasNext(); ) {
    Entity innerEntity=(Entity)actors.next();
    if (innerEntity instanceof FSMActor) {
      REDSingleEntityBean bean=_translateFSMActor((FSMActor)innerEntity,span,bufferSizeFSM,globalSynchronizerSet);
      variableDefinition.append(bean._declaredVariables);
      constantDefinition.append(bean._defineConstants);
      Iterator<String> it=bean._clockSet.iterator();
      while (it.hasNext()) {
        globalClockSet.add(it.next());
      }
      Iterator<REDModuleNameInitialBean> portlists=bean._portSet.iterator();
      while (portlists.hasNext()) {
        processModulePortList.add(portlists.next());
      }
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
      moduleDefinition.append(bean._moduleDescription);
      processModuleNameList.add(bean._nameInitialState);
    }
 else     if (innerEntity instanceof BoundedBufferNondeterministicDelay) {
      String outputSignalName=null;
      Iterator outputConnectedPortList=((BoundedBufferNondeterministicDelay)innerEntity).output.connectedPortList().iterator();
      while (outputConnectedPortList.hasNext()) {
        String portName=((Port)outputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferNondeterministicDelay)innerEntity).output.getName().trim())) {
          continue;
        }
 else {
          outputSignalName=portName;
        }
      }
      String inputSignalName=null;
      Iterator inputConnectedPortList=((BoundedBufferNondeterministicDelay)innerEntity).input.connectedPortList().iterator();
      while (inputConnectedPortList.hasNext()) {
        String portName=((Port)inputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferNondeterministicDelay)innerEntity).input.getName().trim())) {
          continue;
        }
 else {
          inputSignalName=portName;
        }
      }
      REDSingleEntityBean bean=_translateNondeterministicDelayedActor((BoundedBufferNondeterministicDelay)innerEntity,inputSignalName,outputSignalName);
      variableDefinition.append(bean._declaredVariables);
      constantDefinition.append(bean._defineConstants);
      processModuleNameList.add(bean._nameInitialState);
      Iterator<String> it=bean._clockSet.iterator();
      while (it.hasNext()) {
        globalClockSet.add(it.next());
      }
      Iterator<REDModuleNameInitialBean> ports=bean._portSet.iterator();
      while (ports.hasNext()) {
        processModulePortList.add(ports.next());
      }
      moduleDefinition.append(bean._moduleDescription);
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
    }
 else     if (innerEntity instanceof BoundedBufferTimedDelay) {
      String outputSignalName=null;
      Iterator outputConnectedPortList=((BoundedBufferTimedDelay)innerEntity).output.connectedPortList().iterator();
      while (outputConnectedPortList.hasNext()) {
        String portName=((Port)outputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferTimedDelay)innerEntity).output.getName().trim())) {
          continue;
        }
 else {
          outputSignalName=portName;
        }
      }
      String inputSignalName=null;
      Iterator inputConnectedPortList=((BoundedBufferTimedDelay)innerEntity).input.connectedPortList().iterator();
      while (inputConnectedPortList.hasNext()) {
        String portName=((Port)inputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferTimedDelay)innerEntity).input.getName().trim())) {
          continue;
        }
 else {
          inputSignalName=portName;
        }
      }
      REDSingleEntityBean bean=_translateTimedDelayedActor((BoundedBufferTimedDelay)innerEntity,inputSignalName,outputSignalName);
      constantDefinition.append(bean._defineConstants);
      variableDefinition.append(bean._declaredVariables);
      processModuleNameList.add(bean._nameInitialState);
      Iterator<String> clocks=bean._clockSet.iterator();
      while (clocks.hasNext()) {
        globalClockSet.add(clocks.next());
      }
      moduleDefinition.append(bean._moduleDescription);
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
    }
 else     if (innerEntity instanceof Clock) {
      String outputSignalName=null;
      Iterator outputConnectedPortList=((Clock)innerEntity).output.connectedPortList().iterator();
      while (outputConnectedPortList.hasNext()) {
        String portName=((Port)outputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((Clock)innerEntity).output.getName().trim())) {
          continue;
        }
 else {
          outputSignalName=portName;
        }
      }
      REDSingleEntityBean bean=_translateClockActor((Clock)innerEntity,outputSignalName);
      variableDefinition.append(bean._declaredVariables);
      constantDefinition.append(bean._defineConstants);
      moduleDefinition.append(bean._moduleDescription);
      processModuleNameList.add(bean._nameInitialState);
      Iterator<String> clocks=bean._clockSet.iterator();
      while (clocks.hasNext()) {
        globalClockSet.add(clocks.next());
      }
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
    }
  }
  returnREDFormat.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  for (int i=0; i < processModuleNameList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + String.valueOf(i + 1) + "String_Node_Str"+ processModuleNameList.get(i)._name+ "String_Node_Str");
  }
  for (int i=0; i < processModulePortList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + String.valueOf(processModuleNameList.size() + i + 1) + "String_Node_Str"+ processModulePortList.get(i)._name+ "String_Node_Str");
  }
  returnREDFormat.append("String_Node_Str");
  returnREDFormat.append(constantDefinition + "String_Node_Str");
  returnREDFormat.append("String_Node_Str" + String.valueOf(processModuleNameList.size() + processModulePortList.size()) + "String_Node_Str");
  returnREDFormat.append(variableDefinition + "String_Node_Str");
  if (globalClockSet.size() != 0) {
    returnREDFormat.append("String_Node_Str");
    Iterator<String> it=globalClockSet.iterator();
    while (it.hasNext()) {
      String sync=it.next();
      if (it.hasNext()) {
        returnREDFormat.append(sync + "String_Node_Str");
      }
 else {
        returnREDFormat.append(sync + "String_Node_Str");
      }
    }
  }
  if (globalSynchronizerSet.size() != 0) {
    returnREDFormat.append("String_Node_Str");
    Iterator<String> it=globalSynchronizerSet.iterator();
    while (it.hasNext()) {
      String sync=it.next();
      if (it.hasNext()) {
        returnREDFormat.append(sync + "String_Node_Str");
      }
 else {
        returnREDFormat.append(sync + "String_Node_Str");
      }
    }
  }
  returnREDFormat.append(moduleDefinition + "String_Node_Str");
  returnREDFormat.append("String_Node_Str");
  for (int i=0; i < processModuleNameList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + processModuleNameList.get(i)._initialStateDescription + "String_Node_Str"+ String.valueOf(i + 1)+ "String_Node_Str"+ "String_Node_Str");
  }
  for (int i=0; i < processModulePortList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + processModulePortList.get(i)._initialStateDescription + "String_Node_Str"+ String.valueOf(processModuleNameList.size() + i + 1)+ "String_Node_Str"+ "String_Node_Str");
  }
  Iterator<String> ite=variableAndItsInitialCondition.iterator();
  while (ite.hasNext()) {
    String sync=ite.next();
    returnREDFormat.append("String_Node_Str" + sync + "String_Node_Str");
  }
  Iterator<String> it=globalClockSet.iterator();
  while (it.hasNext()) {
    String clock=it.next();
    if (it.hasNext()) {
      returnREDFormat.append("String_Node_Str" + clock + "String_Node_Str");
    }
 else {
      returnREDFormat.append("String_Node_Str" + clock + "String_Node_Str");
    }
  }
  returnREDFormat.append("String_Node_Str");
  if (choice.equalsIgnoreCase("String_Node_Str")) {
    returnREDFormat.append("String_Node_Str");
  }
 else {
    returnREDFormat.append(pattern);
  }
  return returnREDFormat;
}

Fixed version (ground truth):
/** 
 * This is the main function which tries to generate the system  description with the type StringBuffer where its content is  acceptable by the tool RED (Regional Encoding Diagram). 
 * @param PreModel The original model in Ptolemy II
 * @param pattern The temporal formula in TCTL
 * @param choice  Specify the type of formula: buffer overflow detectionor general TCTL formula
 * @param span The size of the span used for domain analysis.
 * @param bufferSizeFSM Specify for each of the input port, the size ofthe buffer used for buffer overflow detection.
 * @return A Communicating Timed Automata system description of the original system
 * @throws IllegalActionException
 */
public static StringBuffer generateREDDescription(CompositeActor PreModel,String pattern,String choice,String span,String bufferSizeFSM) throws IllegalActionException, NameDuplicationException, CloneNotSupportedException {
  StringBuffer returnREDFormat=new StringBuffer("String_Node_Str");
  CompositeActor model=generateEquivalentSystemWithoutHierachy(PreModel);
  StringBuffer constantDefinition=new StringBuffer("String_Node_Str");
  StringBuffer variableDefinition=new StringBuffer("String_Node_Str");
  ArrayList<String> globalClockSet=new ArrayList<String>();
  StringBuffer moduleDefinition=new StringBuffer("String_Node_Str");
  HashSet<String> globalSynchronizerSet=new HashSet<String>();
  HashSet<String> variableAndItsInitialCondition=new HashSet<String>();
  ArrayList<REDModuleNameInitialBean> processModuleNameList=new ArrayList<REDModuleNameInitialBean>();
  ArrayList<REDModuleNameInitialBean> processModulePortList=new ArrayList<REDModuleNameInitialBean>();
  for (Iterator actors=(((CompositeActor)model).entityList()).iterator(); actors.hasNext(); ) {
    Entity innerEntity=(Entity)actors.next();
    HashSet<String> setOfSynchronizes=_decideSynchronizerVariableSet(innerEntity);
    Iterator<String> it=setOfSynchronizes.iterator();
    while (it.hasNext()) {
      globalSynchronizerSet.add(it.next());
    }
  }
  for (Iterator actors=(((CompositeActor)model).entityList()).iterator(); actors.hasNext(); ) {
    Entity innerEntity=(Entity)actors.next();
    if (innerEntity instanceof FSMActor) {
      REDSingleEntityBean bean=_translateFSMActor((FSMActor)innerEntity,span,bufferSizeFSM,globalSynchronizerSet);
      variableDefinition.append(bean._declaredVariables);
      constantDefinition.append(bean._defineConstants);
      Iterator<String> it=bean._clockSet.iterator();
      while (it.hasNext()) {
        globalClockSet.add(it.next());
      }
      Iterator<REDModuleNameInitialBean> portlists=bean._portSet.iterator();
      while (portlists.hasNext()) {
        processModulePortList.add(portlists.next());
      }
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
      moduleDefinition.append(bean._moduleDescription);
      processModuleNameList.add(bean._nameInitialState);
    }
 else     if (innerEntity instanceof BoundedBufferNondeterministicDelay) {
      String outputSignalName=null;
      Iterator outputConnectedPortList=((BoundedBufferNondeterministicDelay)innerEntity).output.connectedPortList().iterator();
      while (outputConnectedPortList.hasNext()) {
        String portName=((Port)outputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferNondeterministicDelay)innerEntity).output.getName().trim())) {
          continue;
        }
 else {
          outputSignalName=portName;
        }
      }
      String inputSignalName=null;
      Iterator inputConnectedPortList=((BoundedBufferNondeterministicDelay)innerEntity).input.connectedPortList().iterator();
      while (inputConnectedPortList.hasNext()) {
        String portName=((Port)inputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferNondeterministicDelay)innerEntity).input.getName().trim())) {
          continue;
        }
 else {
          inputSignalName=portName;
        }
      }
      REDSingleEntityBean bean=_translateNondeterministicDelayedActor((BoundedBufferNondeterministicDelay)innerEntity,inputSignalName,outputSignalName);
      variableDefinition.append(bean._declaredVariables);
      constantDefinition.append(bean._defineConstants);
      processModuleNameList.add(bean._nameInitialState);
      Iterator<String> it=bean._clockSet.iterator();
      while (it.hasNext()) {
        globalClockSet.add(it.next());
      }
      Iterator<REDModuleNameInitialBean> ports=bean._portSet.iterator();
      while (ports.hasNext()) {
        processModulePortList.add(ports.next());
      }
      moduleDefinition.append(bean._moduleDescription);
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
    }
 else     if (innerEntity instanceof BoundedBufferTimedDelay) {
      String outputSignalName=null;
      Iterator outputConnectedPortList=((BoundedBufferTimedDelay)innerEntity).output.connectedPortList().iterator();
      while (outputConnectedPortList.hasNext()) {
        String portName=((Port)outputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferTimedDelay)innerEntity).output.getName().trim())) {
          continue;
        }
 else {
          outputSignalName=portName;
        }
      }
      String inputSignalName=null;
      Iterator inputConnectedPortList=((BoundedBufferTimedDelay)innerEntity).input.connectedPortList().iterator();
      while (inputConnectedPortList.hasNext()) {
        String portName=((Port)inputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((BoundedBufferTimedDelay)innerEntity).input.getName().trim())) {
          continue;
        }
 else {
          inputSignalName=portName;
        }
      }
      REDSingleEntityBean bean=_translateTimedDelayedActor((BoundedBufferTimedDelay)innerEntity,inputSignalName,outputSignalName);
      constantDefinition.append(bean._defineConstants);
      variableDefinition.append(bean._declaredVariables);
      processModuleNameList.add(bean._nameInitialState);
      Iterator<String> clocks=bean._clockSet.iterator();
      while (clocks.hasNext()) {
        globalClockSet.add(clocks.next());
      }
      moduleDefinition.append(bean._moduleDescription);
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
    }
 else     if (innerEntity instanceof Clock) {
      String outputSignalName=null;
      Iterator outputConnectedPortList=((Clock)innerEntity).output.connectedPortList().iterator();
      while (outputConnectedPortList.hasNext()) {
        String portName=((Port)outputConnectedPortList.next()).getName();
        if (portName.equalsIgnoreCase(((Clock)innerEntity).output.getName().trim())) {
          continue;
        }
 else {
          outputSignalName=portName;
        }
      }
      REDSingleEntityBean bean=_translateClockActor((Clock)innerEntity,outputSignalName);
      variableDefinition.append(bean._declaredVariables);
      constantDefinition.append(bean._defineConstants);
      moduleDefinition.append(bean._moduleDescription);
      processModuleNameList.add(bean._nameInitialState);
      Iterator<String> clocks=bean._clockSet.iterator();
      while (clocks.hasNext()) {
        globalClockSet.add(clocks.next());
      }
      Iterator<String> variableInitialValues=bean._variableInitialDescriptionSet.iterator();
      while (variableInitialValues.hasNext()) {
        variableAndItsInitialCondition.add(variableInitialValues.next());
      }
    }
  }
  returnREDFormat.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  for (int i=0; i < processModuleNameList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + String.valueOf(i + 1) + "String_Node_Str"+ processModuleNameList.get(i)._name+ "String_Node_Str");
  }
  for (int i=0; i < processModulePortList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + String.valueOf(processModuleNameList.size() + i + 1) + "String_Node_Str"+ processModulePortList.get(i)._name+ "String_Node_Str");
  }
  returnREDFormat.append("String_Node_Str");
  returnREDFormat.append(constantDefinition + "String_Node_Str");
  returnREDFormat.append("String_Node_Str" + String.valueOf(processModuleNameList.size() + processModulePortList.size()) + "String_Node_Str");
  returnREDFormat.append(variableDefinition + "String_Node_Str");
  if (globalClockSet.size() != 0) {
    returnREDFormat.append("String_Node_Str");
    Iterator<String> it=globalClockSet.iterator();
    while (it.hasNext()) {
      String sync=it.next();
      if (it.hasNext()) {
        returnREDFormat.append(sync + "String_Node_Str");
      }
 else {
        returnREDFormat.append(sync + "String_Node_Str");
      }
    }
  }
  if (globalSynchronizerSet.size() != 0) {
    returnREDFormat.append("String_Node_Str");
    Iterator<String> it=globalSynchronizerSet.iterator();
    while (it.hasNext()) {
      String sync=it.next();
      if (it.hasNext()) {
        returnREDFormat.append(sync + "String_Node_Str");
      }
 else {
        returnREDFormat.append(sync + "String_Node_Str");
      }
    }
  }
  returnREDFormat.append(moduleDefinition + "String_Node_Str");
  returnREDFormat.append("String_Node_Str");
  for (int i=0; i < processModuleNameList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + processModuleNameList.get(i)._initialStateDescription + "String_Node_Str"+ String.valueOf(i + 1)+ "String_Node_Str"+ "String_Node_Str");
  }
  for (int i=0; i < processModulePortList.size(); i++) {
    returnREDFormat.append("String_Node_Str" + processModulePortList.get(i)._initialStateDescription + "String_Node_Str"+ String.valueOf(processModuleNameList.size() + i + 1)+ "String_Node_Str"+ "String_Node_Str");
  }
  Iterator<String> ite=variableAndItsInitialCondition.iterator();
  while (ite.hasNext()) {
    String sync=ite.next();
    returnREDFormat.append("String_Node_Str" + sync + "String_Node_Str");
  }
  Iterator<String> it=globalClockSet.iterator();
  while (it.hasNext()) {
    String clock=it.next();
    if (it.hasNext()) {
      returnREDFormat.append("String_Node_Str" + clock + "String_Node_Str");
    }
 else {
      returnREDFormat.append("String_Node_Str" + clock + "String_Node_Str");
    }
  }
  returnREDFormat.append("String_Node_Str");
  if (choice.equalsIgnoreCase("String_Node_Str")) {
    returnREDFormat.append("String_Node_Str");
  }
 else {
    returnREDFormat.append(pattern);
  }
  return returnREDFormat;
}