Program: 72748
Project: 72748
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();
  codeBuffer.append(getCodeGenerator().comment("String_Node_Str"));
  ptolemy.domains.modal.kernel.FSMActor fsmActor=(ptolemy.domains.modal.kernel.FSMActor)getComponent();
  String name=fsmActor.getFullName().substring(1);
  String modalName=name.replace("String_Node_Str","String_Node_Str");
  modalName=modalName.replace('.','_').replace(' ','_');
  codeBuffer.append(getCodeGenerator().comment("String_Node_Str"));
  codeBuffer.append(_eol + modalName + "String_Node_Str"+ _eol);
  codeBuffer.append("String_Node_Str" + _eol + "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(Locale.getDefault()).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();
        ASTPtRootNode guardParseTree=parser.generateParseTree(guard);
        if (getTemplateParser() == null) {
          if (getCodeGenerator() == null) {
            throw new InternalErrorException(this,null,"String_Node_Str");
          }
          getCodeGenerator().getAdapter(fsmActor);
        }
        ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
        parseTreeCodeGenerator.evaluateParseTree(guardParseTree,_scope);
        codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
        codeBuffer.append("String_Node_Str");
      }
      codeBuffer.append(_eol + "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();
              codeBuffer.append("String_Node_Str");
              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");
              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");
              }
            }
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str" + _eol);
        }
      }
      Actor[] actors=transition.getRefinement();
      if (actors != null) {
        for (        Actor actor : actors) {
          NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actor);
          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();
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          String scopeFireCode=parseTreeCodeGenerator.generateFireCode();
          if (destination instanceof IOPort) {
            if (channel >= 0) {
              codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str"+ scopeFireCode+ "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"+ scopeFireCode+ "String_Node_Str");
              }
            }
          }
 else           if (destination instanceof Variable) {
            codeBuffer.append(getCodeGenerator().generateVariableName(destination) + "String_Node_Str" + scopeFireCode+ "String_Node_Str");
          }
        }
      }
      State destinationState=transition.destinationState();
      _updateCurrentState(codeBuffer,destinationState);
      if (!transition.isHistory()) {
        actors=destinationState.getRefinement();
        if (actors != null) {
          for (int i=0; i < actors.length; ++i) {
            NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actors[i]);
            codeBuffer.append(helper.generateInitializeCode());
          }
        }
      }
      codeBuffer.append(_eol + "String_Node_Str" + _eol);
    }
    if (!hasDefaultCase) {
      if (transitionCount > 0) {
        codeBuffer.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol);
      }
 else {
        codeBuffer.append(_eol);
      }
      codeBuffer.append(_eol + modalName + "String_Node_Str"+ _eol);
      if (transitionCount > 0) {
        codeBuffer.append(_eol + "String_Node_Str" + _eol);
      }
    }
    codeBuffer.append(_eol + "String_Node_Str" + _eol);
  }
  codeBuffer.append(_eol + "String_Node_Str" + _eol);
  code.append(TemplateParser.unescapeName(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.
 * @exception IllegalActionException If thrown while generatingtransition code.
 */
public void generateTransitionCode(StringBuffer code,TransitionRetriever transitionRetriever) throws IllegalActionException {
  StringBuffer codeBuffer=new StringBuffer();
  codeBuffer.append(getCodeGenerator().comment("String_Node_Str"));
  ptolemy.domains.modal.kernel.FSMActor fsmActor=(ptolemy.domains.modal.kernel.FSMActor)getComponent();
  String name=fsmActor.getFullName().substring(1);
  String modalName=name.replace("String_Node_Str","String_Node_Str");
  modalName=modalName.replace('.','_').replace(' ','_');
  codeBuffer.append(getCodeGenerator().comment("String_Node_Str"));
  codeBuffer.append(_eol + modalName + "String_Node_Str"+ _eol);
  codeBuffer.append("String_Node_Str" + _eol + "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(Locale.getDefault()).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();
        ASTPtRootNode guardParseTree=parser.generateParseTree(guard);
        if (getTemplateParser() == null) {
          if (getCodeGenerator() == null) {
            throw new InternalErrorException(this,null,"String_Node_Str");
          }
          getCodeGenerator().getAdapter(fsmActor);
        }
        ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
        parseTreeCodeGenerator.evaluateParseTree(guardParseTree,_scope);
        codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
        codeBuffer.append("String_Node_Str");
      }
      codeBuffer.append(_eol + "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");
              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");
              }
            }
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
          codeBuffer.append("String_Node_Str" + _eol);
        }
      }
      Actor[] actors=transition.getRefinement();
      if (actors != null) {
        for (        Actor actor : actors) {
          NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actor);
          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();
          }
          ParseTreeCodeGenerator parseTreeCodeGenerator=getTemplateParser().getParseTreeCodeGenerator();
          parseTreeCodeGenerator.evaluateParseTree(parseTree,_scope);
          String scopeFireCode=parseTreeCodeGenerator.generateFireCode();
          if (destination instanceof IOPort) {
            if (channel >= 0) {
              codeBuffer.append("String_Node_Str" + destinationName + "String_Node_Str"+ channel+ "String_Node_Str"+ scopeFireCode+ "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"+ scopeFireCode+ "String_Node_Str");
              }
            }
          }
 else           if (destination instanceof Variable) {
            codeBuffer.append(getCodeGenerator().generateVariableName(destination) + "String_Node_Str" + scopeFireCode+ "String_Node_Str");
          }
        }
      }
      State destinationState=transition.destinationState();
      _updateCurrentState(codeBuffer,destinationState);
      if (!transition.isHistory()) {
        actors=destinationState.getRefinement();
        if (actors != null) {
          for (int i=0; i < actors.length; ++i) {
            NamedProgramCodeGeneratorAdapter helper=(NamedProgramCodeGeneratorAdapter)getAdapter(actors[i]);
            codeBuffer.append(helper.generateInitializeCode());
          }
        }
      }
      codeBuffer.append(_eol + "String_Node_Str" + _eol);
    }
    if (!hasDefaultCase) {
      if (transitionCount > 0) {
        codeBuffer.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol);
      }
 else {
        codeBuffer.append(_eol);
      }
      codeBuffer.append(_eol + modalName + "String_Node_Str"+ _eol);
      if (transitionCount > 0) {
        codeBuffer.append(_eol + "String_Node_Str" + _eol);
      }
    }
    codeBuffer.append(_eol + "String_Node_Str" + _eol);
  }
  codeBuffer.append(_eol + "String_Node_Str" + _eol);
  code.append(TemplateParser.unescapeName(processCode(codeBuffer.toString())));
}