Program: 73412
Project: 73412
Buggy source:
/** 
 * Generate code for making transition. It generates code for both choice action and commit action.
 * @param code The string buffer that the generated code is appended to.
 * @param transitionRetriever An instance of a class implementinga method. which returns an iterator of all, preemptive or non-preemptive transitions of the current state.
 * @exception IllegalActionException If thrown while generatingtransition code.
 */
public void generateTransitionCode(StringBuffer code,TransitionRetriever transitionRetriever) throws IllegalActionException {
  StringBuffer codeBuffer=new StringBuffer();
  ptolemy.domains.modal.kernel.FSMActor fsmActor=(ptolemy.domains.modal.kernel.FSMActor)getComponent();
  codeBuffer.append("String_Node_Str" + _eol);
  codeBuffer.append("String_Node_Str" + _eol);
  for (  State state : (List<State>)fsmActor.entityList()) {
    codeBuffer.append("String_Node_Str" + _generateStateConstantLabel(state) + "String_Node_Str"+ _eol);
    Iterator transitions=transitionRetriever.retrieveTransitions(state);
    List reOrderedTransitions=new LinkedList();
    List defaultTransitions=new LinkedList();
    while (transitions.hasNext()) {
      Transition transition=(Transition)transitions.next();
      if (generateSimpleName(transition).equals("String_Node_Str")) {
        defaultTransitions.add(transition);
      }
 else {
        reOrderedTransitions.add(transition);
      }
    }
    reOrderedTransitions.addAll(defaultTransitions);
    transitions=reOrderedTransitions.iterator();
    int transitionCount=0;
    boolean hasDefaultCase=false;
    while (!hasDefaultCase && transitions.hasNext()) {
      Transition transition=(Transition)transitions.next();
      String guard=transition.getGuardExpression();
      if (transition.isDefault() || guard.toLowerCase().equals("String_Node_Str")) {
        hasDefaultCase=true;
      }
 else {
        if (transitionCount == 0) {
          codeBuffer.append("String_Node_Str");
        }
 else {
          codeBuffer.append("String_Node_Str");
        }
        transitionCount++;
        PtParser parser=new PtParser();
        int index=guard.indexOf("String_Node_Str");
        ASTPtRootNode guardParseTree=parser.generateParseTree(guard);
        ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
        parseTreeCodeGenerator.evaluateParseTree(guardParseTree,_scope);
        int index2=transition.getFullName().indexOf("String_Node_Str");
        String tempName=transition.getFullName().substring(1,index2) + guard.substring(0,index - 1);
        tempName=tempName.replace("String_Node_Str","String_Node_Str");
        codeBuffer.append(tempName + "String_Node_Str");
        codeBuffer.append("String_Node_Str");
        codeBuffer.append("String_Node_Str");
      }
      codeBuffer.append("String_Node_Str" + _eol);
      for (      AbstractActionsAttribute action : (List<AbstractActionsAttribute>)transition.choiceActionList()) {
        Iterator channelNumberList=action.getChannelNumberList().iterator();
        Iterator parseTreeList=action.getParseTreeList().iterator();
        for (        String destinationName : (List<String>)action.getDestinationNameList()) {
          Integer channelNumber=(Integer)channelNumberList.next();
          ASTPtRootNode parseTree=(ASTPtRootNode)parseTreeList.next();
          NamedObj destination=action.getDestination(destinationName);
          int channel=-1;
          if (channelNumber != null) {
            channel=channelNumber.intValue();
          }
          StringBuffer sendCode=new StringBuffer();
          if (channel >= 0) {
            codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str");
            if (((IOPort)destination).isInput()) {
              NamedProgramCodeGeneratorAdapter containerHelper=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(((IOPort)destination).getContainer().getContainer());
              StringBuffer containerReference=new StringBuffer();
              containerReference.append("String_Node_Str" + generateSimpleName(destination));
              if (((IOPort)destination).isMultiport()) {
                containerReference.append("String_Node_Str" + channel);
              }
              containerReference.append("String_Node_Str");
              codeBuffer.append((containerHelper).processCode(containerReference.toString()) + "String_Node_Str");
              sendCode.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str"+ _eol);
            }
          }
 else {
            int width=((IOPort)action.getDestination(destinationName)).getWidth();
            for (int i=0; i < width; i++) {
              codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ i+ "String_Node_Str");
              sendCode.append("String_Node_Str" + destinationName + "String_Node_Str"+ i+ "String_Node_Str"+ _eol);
              if (((IOPort)destination).isInput()) {
                NamedProgramCodeGeneratorAdapter containerHelper=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(((IOPort)destination).getContainer().getContainer());
                StringBuffer containerReference=new StringBuffer();
                containerReference.append("String_Node_Str" + generateSimpleName(destination));
                if (((IOPort)destination).isMultiport()) {
                  containerReference.append("String_Node_Str" + i);
                }
                containerReference.append("String_Node_Str");
                codeBuffer.append((containerHelper).processCode(containerReference.toString()) + "String_Node_Str");
                sendCode.append("String_Node_Str" + generateSimpleName(destination) + "String_Node_Str"+ i+ "String_Node_Str"+ _eol);
              }
            }
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str" + _eol);
          codeBuffer.append(sendCode);
        }
      }
      Actor[] actors=transition.getRefinement();
      if (actors != null) {
        for (int i=0; i < actors.length; i++) {
          NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actors[i]);
          codeBuffer.append(helper.generateFireCode());
        }
      }
      for (      AbstractActionsAttribute action : (List<AbstractActionsAttribute>)transition.commitActionList()) {
        Iterator channelNumberList=action.getChannelNumberList().iterator();
        Iterator parseTreeList=action.getParseTreeList().iterator();
        for (        String destinationName : (List<String>)action.getDestinationNameList()) {
          Integer channelNumber=(Integer)channelNumberList.next();
          ASTPtRootNode parseTree=(ASTPtRootNode)parseTreeList.next();
          NamedObj destination=action.getDestination(destinationName);
          int channel=-1;
          if (channelNumber != null) {
            channel=channelNumber.intValue();
          }
          if (destination instanceof IOPort) {
            if (channel >= 0) {
              codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str");
            }
 else {
              int width=((IOPort)action.getDestination(destinationName)).getWidth();
              for (int i=0; i < width; i++) {
                codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ i+ "String_Node_Str");
              }
            }
          }
 else           if (destination instanceof Variable) {
            codeBuffer.append(getCodeGenerator().generateVariableName(destination) + "String_Node_Str");
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str" + _eol);
        }
      }
      State destinationState=transition.destinationState();
      _updateCurrentState(codeBuffer,destinationState);
      BooleanToken resetToken=(BooleanToken)transition.reset.getToken();
      if (resetToken.booleanValue()) {
        actors=destinationState.getRefinement();
        if (actors != null) {
          for (int i=0; i < actors.length; ++i) {
            NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actors[i]);
            codeBuffer.append(helper.generateInitializeCode());
          }
        }
      }
      Director director=fsmActor.getExecutiveDirector();
      if (director instanceof ptolemy.domains.modal.kernel.MultirateFSMDirector) {
      }
      codeBuffer.append("String_Node_Str");
    }
    if (!hasDefaultCase) {
      if (transitionCount > 0) {
        codeBuffer.append("String_Node_Str" + _eol);
      }
 else {
        codeBuffer.append(_eol);
      }
      codeBuffer.append("String_Node_Str" + _eol);
      Director director=fsmActor.getExecutiveDirector();
      if (director instanceof ptolemy.domains.modal.kernel.MultirateFSMDirector) {
      }
      if (transitionCount > 0) {
        codeBuffer.append("String_Node_Str" + _eol);
      }
    }
    codeBuffer.append(_eol + "String_Node_Str" + _eol);
  }
  codeBuffer.append("String_Node_Str" + _eol);
  code.append(codeBuffer.toString());
}

Fixed version (ground truth):
/** 
 * Generate code for making transition. It generates code for both choice action and commit action.
 * @param code The string buffer that the generated code is appended to.
 * @param transitionRetriever An instance of a class implementinga method. which returns an iterator of all, preemptive or non-preemptive transitions of the current state.
 * @exception IllegalActionException If thrown while generatingtransition code.
 */
public void generateTransitionCode(StringBuffer code,TransitionRetriever transitionRetriever) throws IllegalActionException {
  StringBuffer codeBuffer=new StringBuffer();
  ptolemy.domains.modal.kernel.FSMActor fsmActor=(ptolemy.domains.modal.kernel.FSMActor)getComponent();
  codeBuffer.append("String_Node_Str" + _eol);
  codeBuffer.append("String_Node_Str" + _eol);
  for (  State state : (List<State>)fsmActor.entityList()) {
    codeBuffer.append("String_Node_Str" + _generateStateConstantLabel(state) + "String_Node_Str"+ _eol);
    Iterator transitions=transitionRetriever.retrieveTransitions(state);
    List reOrderedTransitions=new LinkedList();
    List defaultTransitions=new LinkedList();
    while (transitions.hasNext()) {
      Transition transition=(Transition)transitions.next();
      if (generateSimpleName(transition).equals("String_Node_Str")) {
        defaultTransitions.add(transition);
      }
 else {
        reOrderedTransitions.add(transition);
      }
    }
    reOrderedTransitions.addAll(defaultTransitions);
    transitions=reOrderedTransitions.iterator();
    int transitionCount=0;
    boolean hasDefaultCase=false;
    while (!hasDefaultCase && transitions.hasNext()) {
      Transition transition=(Transition)transitions.next();
      String guard=transition.getGuardExpression();
      if (transition.isDefault() || guard.toLowerCase().equals("String_Node_Str")) {
        hasDefaultCase=true;
      }
 else {
        if (transitionCount == 0) {
          codeBuffer.append("String_Node_Str");
        }
 else {
          codeBuffer.append("String_Node_Str");
        }
        transitionCount++;
        PtParser parser=new PtParser();
        int index=guard.indexOf("String_Node_Str");
        ASTPtRootNode guardParseTree=parser.generateParseTree(guard);
        ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
        parseTreeCodeGenerator.evaluateParseTree(guardParseTree,_scope);
        int index2=transition.getFullName().indexOf("String_Node_Str");
        String tempName=transition.getFullName().substring(1,index2) + guard.substring(0,index - 1);
        tempName=tempName.replace("String_Node_Str","String_Node_Str");
        codeBuffer.append(tempName + "String_Node_Str");
        codeBuffer.append("String_Node_Str");
        codeBuffer.append("String_Node_Str");
      }
      codeBuffer.append("String_Node_Str" + _eol);
      for (      AbstractActionsAttribute action : (List<AbstractActionsAttribute>)transition.choiceActionList()) {
        Iterator channelNumberList=action.getChannelNumberList().iterator();
        Iterator parseTreeList=action.getParseTreeList().iterator();
        for (        String destinationName : (List<String>)action.getDestinationNameList()) {
          Integer channelNumber=(Integer)channelNumberList.next();
          ASTPtRootNode parseTree=(ASTPtRootNode)parseTreeList.next();
          NamedObj destination=action.getDestination(destinationName);
          int channel=-1;
          if (channelNumber != null) {
            channel=channelNumber.intValue();
          }
          StringBuffer sendCode=new StringBuffer();
          if (channel >= 0) {
            codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str");
            if (((IOPort)destination).isInput()) {
              NamedProgramCodeGeneratorAdapter containerHelper=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(((IOPort)destination).getContainer().getContainer());
              StringBuffer containerReference=new StringBuffer();
              containerReference.append("String_Node_Str" + generateSimpleName(destination));
              if (((IOPort)destination).isMultiport()) {
                containerReference.append("String_Node_Str" + channel);
              }
              containerReference.append("String_Node_Str");
              codeBuffer.append((containerHelper).processCode(containerReference.toString()) + "String_Node_Str");
              sendCode.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str"+ _eol);
            }
          }
 else {
            int width=((IOPort)action.getDestination(destinationName)).getWidth();
            for (int i=0; i < width; i++) {
              codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ i+ "String_Node_Str");
              sendCode.append("String_Node_Str" + destinationName + "String_Node_Str"+ i+ "String_Node_Str"+ _eol);
              if (((IOPort)destination).isInput()) {
                NamedProgramCodeGeneratorAdapter containerHelper=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(((IOPort)destination).getContainer().getContainer());
                StringBuffer containerReference=new StringBuffer();
                containerReference.append("String_Node_Str" + generateSimpleName(destination));
                if (((IOPort)destination).isMultiport()) {
                  containerReference.append("String_Node_Str" + i);
                }
                containerReference.append("String_Node_Str");
                codeBuffer.append((containerHelper).processCode(containerReference.toString()) + "String_Node_Str");
                sendCode.append("String_Node_Str" + generateSimpleName(destination) + "String_Node_Str"+ i+ "String_Node_Str"+ _eol);
              }
            }
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str" + _eol);
          codeBuffer.append(sendCode);
        }
      }
      Actor[] actors=transition.getRefinement();
      if (actors != null) {
        for (int i=0; i < actors.length; i++) {
          NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actors[i]);
          codeBuffer.append(helper.generateFireCode());
        }
      }
      for (      AbstractActionsAttribute action : (List<AbstractActionsAttribute>)transition.commitActionList()) {
        Iterator channelNumberList=action.getChannelNumberList().iterator();
        Iterator parseTreeList=action.getParseTreeList().iterator();
        for (        String destinationName : (List<String>)action.getDestinationNameList()) {
          Integer channelNumber=(Integer)channelNumberList.next();
          ASTPtRootNode parseTree=(ASTPtRootNode)parseTreeList.next();
          NamedObj destination=action.getDestination(destinationName);
          int channel=-1;
          if (channelNumber != null) {
            channel=channelNumber.intValue();
          }
          if (destination instanceof IOPort) {
            if (channel >= 0) {
              codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str");
            }
 else {
              int width=((IOPort)action.getDestination(destinationName)).getWidth();
              for (int i=0; i < width; i++) {
                codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ i+ "String_Node_Str");
              }
            }
          }
 else           if (destination instanceof Variable) {
            codeBuffer.append(getCodeGenerator().generateVariableName(destination) + "String_Node_Str");
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str" + _eol);
        }
      }
      State destinationState=transition.destinationState();
      _updateCurrentState(codeBuffer,destinationState);
      BooleanToken resetToken=(BooleanToken)transition.reset.getToken();
      if (resetToken.booleanValue()) {
        actors=destinationState.getRefinement();
        if (actors != null) {
          for (int i=0; i < actors.length; ++i) {
            NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actors[i]);
            codeBuffer.append(helper.generateInitializeCode());
          }
        }
      }
      Director director=fsmActor.getExecutiveDirector();
      codeBuffer.append("String_Node_Str");
    }
    if (!hasDefaultCase) {
      if (transitionCount > 0) {
        codeBuffer.append("String_Node_Str" + _eol);
      }
 else {
        codeBuffer.append(_eol);
      }
      codeBuffer.append("String_Node_Str" + _eol);
      Director director=fsmActor.getExecutiveDirector();
      if (transitionCount > 0) {
        codeBuffer.append("String_Node_Str" + _eol);
      }
    }
    codeBuffer.append(_eol + "String_Node_Str" + _eol);
  }
  codeBuffer.append("String_Node_Str" + _eol);
  code.append(codeBuffer.toString());
}