Program: 74944
Project: 74944
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 implementing a method which returns an iterator of all, preemptive or non-preemptive  transitions of the current state. 
 * @throws IllegalActionException If thrown while generating transition code.
 */
public void generateTransitionCode(StringBuffer code,TransitionRetriever transitionRetriever) throws IllegalActionException {
  StringBuffer codeBuffer=new StringBuffer();
  ptolemy.domains.fsm.kernel.FSMActor fsmActor=(ptolemy.domains.fsm.kernel.FSMActor)getComponent();
  int depth=1;
  codeBuffer.append(_getIndentPrefix(depth));
  codeBuffer.append("String_Node_Str");
  codeBuffer.append(_getIndentPrefix(depth));
  codeBuffer.append("String_Node_Str");
  Iterator states=fsmActor.entityList().iterator();
  int stateCount=0;
  depth++;
  while (states.hasNext()) {
    codeBuffer.append(_getIndentPrefix(depth));
    codeBuffer.append("String_Node_Str" + stateCount + "String_Node_Str");
    stateCount++;
    State state=(State)states.next();
    Iterator transitions=transitionRetriever.retrieveTransitions(state);
    int transitionCount=0;
    depth++;
    while (transitions.hasNext()) {
      if (transitionCount == 0) {
        codeBuffer.append(_getIndentPrefix(depth));
        codeBuffer.append("String_Node_Str");
      }
 else {
        codeBuffer.append("String_Node_Str");
      }
      transitionCount++;
      Transition transition=(Transition)transitions.next();
      String guard=transition.getGuardExpression();
      PtParser parser=new PtParser();
      ASTPtRootNode guardParseTree=parser.generateParseTree(guard);
      ParseTreeCodeGenerator parseTreeCodeGenerator=new ParseTreeCodeGenerator();
      parseTreeCodeGenerator.evaluateParseTree(guardParseTree,_scope);
      codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
      codeBuffer.append("String_Node_Str");
      depth++;
      Iterator actions=transition.choiceActionList().iterator();
      while (actions.hasNext()) {
        AbstractActionsAttribute action=(AbstractActionsAttribute)actions.next();
        Iterator destinationNameList=action.getDestinationNameList().iterator();
        while (destinationNameList.hasNext()) {
          String destinationName=(String)destinationNameList.next();
          NamedObj destination=(NamedObj)action.getDestination(destinationName);
          int channel=-1;
          if (action.isChannelSpecified(destinationName)) {
            channel=action.getChannel(destinationName);
          }
          ASTPtRootNode parseTree=action.getParseTree(destinationName);
          codeBuffer.append(_getIndentPrefix(depth));
          if (channel >= 0) {
            codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str");
            if (((IOPort)destination).isInput()) {
              codeBuffer.append(destination.getFullName().replace('.','_'));
              if (((IOPort)destination).isMultiport()) {
                codeBuffer.append("String_Node_Str" + channel + "String_Node_Str");
              }
              codeBuffer.append("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");
              if (((IOPort)destination).isInput()) {
                codeBuffer.append(destination.getFullName().replace('.','_'));
                if (((IOPort)destination).isMultiport()) {
                  codeBuffer.append("String_Node_Str" + i + "String_Node_Str");
                }
                codeBuffer.append("String_Node_Str");
              }
            }
          }
          parseTreeCodeGenerator=new ParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str");
        }
      }
      boolean inline=((BooleanToken)_codeGenerator.inline.getToken()).booleanValue();
      Actor[] actors=transition.getRefinement();
      if (actors != null) {
        for (int i=0; i < actors.length; i++) {
          ActorCodeGenerator helper=(ActorCodeGenerator)_getHelper((NamedObj)actors[i]);
          if (inline) {
            codeBuffer.append(helper.generateFireCode());
          }
 else {
            codeBuffer.append(actors[i].getFullName().replace('.','_') + "String_Node_Str");
          }
        }
      }
      actions=transition.commitActionList().iterator();
      while (actions.hasNext()) {
        AbstractActionsAttribute action=(AbstractActionsAttribute)actions.next();
        Iterator destinationNameList=action.getDestinationNameList().iterator();
        while (destinationNameList.hasNext()) {
          String destinationName=(String)destinationNameList.next();
          NamedObj destination=(NamedObj)action.getDestination(destinationName);
          int channel=-1;
          if (action.isChannelSpecified(destinationName)) {
            channel=action.getChannel(destinationName);
          }
          ASTPtRootNode parseTree=action.getParseTree(destinationName);
          codeBuffer.append(_getIndentPrefix(depth));
          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(destination.getFullName().replace('.','_') + "String_Node_Str");
          }
          parseTreeCodeGenerator=new ParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str");
        }
      }
      State destinationState=transition.destinationState();
      _updateCurrentState(codeBuffer,destinationState,depth);
      BooleanToken resetToken=(BooleanToken)transition.reset.getToken();
      if (resetToken.booleanValue()) {
        actors=destinationState.getRefinement();
        if (actors != null) {
          for (int i=0; i < actors.length; ++i) {
            ActorCodeGenerator helper=(ActorCodeGenerator)_getHelper((NamedObj)actors[i]);
            codeBuffer.append(helper.generateInitializeCode());
          }
        }
      }
      Director director=fsmActor.getExecutiveDirector();
      if (director instanceof ptolemy.domains.fsm.kernel.MultirateFSMDirector) {
        MultirateFSMDirector directorHelper=(MultirateFSMDirector)_getHelper((NamedObj)director);
        directorHelper._updateConfigurationNumber(codeBuffer,destinationState);
      }
      depth--;
      codeBuffer.append(_getIndentPrefix(depth));
      codeBuffer.append("String_Node_Str");
    }
    if (transitionCount > 0) {
      codeBuffer.append("String_Node_Str");
    }
 else {
      codeBuffer.append("String_Node_Str");
    }
    depth++;
    codeBuffer.append(_getIndentPrefix(depth));
    codeBuffer.append("String_Node_Str");
    Director director=fsmActor.getExecutiveDirector();
    if (director instanceof ptolemy.domains.fsm.kernel.MultirateFSMDirector) {
      MultirateFSMDirector directorHelper=(MultirateFSMDirector)_getHelper((NamedObj)director);
      directorHelper._updateConfigurationNumber(codeBuffer,state);
    }
    depth--;
    if (transitionCount > 0) {
      codeBuffer.append(_getIndentPrefix(depth));
      codeBuffer.append("String_Node_Str");
    }
    codeBuffer.append(_getIndentPrefix(depth));
    codeBuffer.append("String_Node_Str");
    depth--;
  }
  depth--;
  codeBuffer.append(_getIndentPrefix(depth));
  codeBuffer.append("String_Node_Str");
  code.append(processCode(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. 
 * @throws IllegalActionException If thrown while generatingtransition code.
 */
public void generateTransitionCode(StringBuffer code,TransitionRetriever transitionRetriever) throws IllegalActionException {
  StringBuffer codeBuffer=new StringBuffer();
  ptolemy.domains.fsm.kernel.FSMActor fsmActor=(ptolemy.domains.fsm.kernel.FSMActor)getComponent();
  int depth=1;
  codeBuffer.append(_getIndentPrefix(depth));
  codeBuffer.append("String_Node_Str");
  codeBuffer.append(_getIndentPrefix(depth));
  codeBuffer.append("String_Node_Str");
  Iterator states=fsmActor.entityList().iterator();
  int stateCount=0;
  depth++;
  while (states.hasNext()) {
    codeBuffer.append(_getIndentPrefix(depth));
    codeBuffer.append("String_Node_Str" + stateCount + "String_Node_Str");
    stateCount++;
    State state=(State)states.next();
    Iterator transitions=transitionRetriever.retrieveTransitions(state);
    int transitionCount=0;
    depth++;
    while (transitions.hasNext()) {
      if (transitionCount == 0) {
        codeBuffer.append(_getIndentPrefix(depth));
        codeBuffer.append("String_Node_Str");
      }
 else {
        codeBuffer.append("String_Node_Str");
      }
      transitionCount++;
      Transition transition=(Transition)transitions.next();
      String guard=transition.getGuardExpression();
      PtParser parser=new PtParser();
      ASTPtRootNode guardParseTree=parser.generateParseTree(guard);
      ParseTreeCodeGenerator parseTreeCodeGenerator=new ParseTreeCodeGenerator();
      parseTreeCodeGenerator.evaluateParseTree(guardParseTree,_scope);
      codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
      codeBuffer.append("String_Node_Str");
      depth++;
      Iterator actions=transition.choiceActionList().iterator();
      while (actions.hasNext()) {
        AbstractActionsAttribute action=(AbstractActionsAttribute)actions.next();
        Iterator destinationNameList=action.getDestinationNameList().iterator();
        while (destinationNameList.hasNext()) {
          String destinationName=(String)destinationNameList.next();
          NamedObj destination=(NamedObj)action.getDestination(destinationName);
          int channel=-1;
          if (action.isChannelSpecified(destinationName)) {
            channel=action.getChannel(destinationName);
          }
          ASTPtRootNode parseTree=action.getParseTree(destinationName);
          codeBuffer.append(_getIndentPrefix(depth));
          if (channel >= 0) {
            codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str");
            if (((IOPort)destination).isInput()) {
              codeBuffer.append(destination.getFullName().replace('.','_'));
              if (((IOPort)destination).isMultiport()) {
                codeBuffer.append("String_Node_Str" + channel + "String_Node_Str");
              }
              codeBuffer.append("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");
              if (((IOPort)destination).isInput()) {
                codeBuffer.append(destination.getFullName().replace('.','_'));
                if (((IOPort)destination).isMultiport()) {
                  codeBuffer.append("String_Node_Str" + i + "String_Node_Str");
                }
                codeBuffer.append("String_Node_Str");
              }
            }
          }
          parseTreeCodeGenerator=new ParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str");
        }
      }
      boolean inline=((BooleanToken)_codeGenerator.inline.getToken()).booleanValue();
      Actor[] actors=transition.getRefinement();
      if (actors != null) {
        for (int i=0; i < actors.length; i++) {
          ActorCodeGenerator helper=(ActorCodeGenerator)_getHelper((NamedObj)actors[i]);
          if (inline) {
            codeBuffer.append(helper.generateFireCode());
          }
 else {
            codeBuffer.append(actors[i].getFullName().replace('.','_') + "String_Node_Str");
          }
        }
      }
      actions=transition.commitActionList().iterator();
      while (actions.hasNext()) {
        AbstractActionsAttribute action=(AbstractActionsAttribute)actions.next();
        Iterator destinationNameList=action.getDestinationNameList().iterator();
        while (destinationNameList.hasNext()) {
          String destinationName=(String)destinationNameList.next();
          NamedObj destination=(NamedObj)action.getDestination(destinationName);
          int channel=-1;
          if (action.isChannelSpecified(destinationName)) {
            channel=action.getChannel(destinationName);
          }
          ASTPtRootNode parseTree=action.getParseTree(destinationName);
          codeBuffer.append(_getIndentPrefix(depth));
          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(destination.getFullName().replace('.','_') + "String_Node_Str");
          }
          parseTreeCodeGenerator=new ParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str");
        }
      }
      State destinationState=transition.destinationState();
      _updateCurrentState(codeBuffer,destinationState,depth);
      BooleanToken resetToken=(BooleanToken)transition.reset.getToken();
      if (resetToken.booleanValue()) {
        actors=destinationState.getRefinement();
        if (actors != null) {
          for (int i=0; i < actors.length; ++i) {
            ActorCodeGenerator helper=(ActorCodeGenerator)_getHelper((NamedObj)actors[i]);
            codeBuffer.append(helper.generateInitializeCode());
          }
        }
      }
      Director director=fsmActor.getExecutiveDirector();
      if (director instanceof ptolemy.domains.fsm.kernel.MultirateFSMDirector) {
        MultirateFSMDirector directorHelper=(MultirateFSMDirector)_getHelper((NamedObj)director);
        directorHelper._updateConfigurationNumber(codeBuffer,destinationState);
      }
      depth--;
      codeBuffer.append(_getIndentPrefix(depth));
      codeBuffer.append("String_Node_Str");
    }
    if (transitionCount > 0) {
      codeBuffer.append("String_Node_Str");
    }
 else {
      codeBuffer.append("String_Node_Str");
    }
    depth++;
    codeBuffer.append(_getIndentPrefix(depth));
    codeBuffer.append("String_Node_Str");
    Director director=fsmActor.getExecutiveDirector();
    if (director instanceof ptolemy.domains.fsm.kernel.MultirateFSMDirector) {
      MultirateFSMDirector directorHelper=(MultirateFSMDirector)_getHelper((NamedObj)director);
      directorHelper._updateConfigurationNumber(codeBuffer,state);
    }
    depth--;
    if (transitionCount > 0) {
      codeBuffer.append(_getIndentPrefix(depth));
      codeBuffer.append("String_Node_Str");
    }
    codeBuffer.append(_getIndentPrefix(depth));
    codeBuffer.append("String_Node_Str");
    depth--;
  }
  depth--;
  codeBuffer.append(_getIndentPrefix(depth));
  codeBuffer.append("String_Node_Str");
  code.append(processCode(codeBuffer.toString()));
}