jMerger.setFixInterfaceBrace(true);
jMerger.setFixInterfaceBrace(jControlModel.getFacadeHelper().fixInterfaceBrace());
  protected void generateJava    (String targetPath,     String packageName,     String className,     JETEmitter jetEmitter,     Object[] arguments,     Monitor monitor)  {    try    {      monitor.beginTask("", 4);      URI targetDirectory = toURI(targetPath).appendSegments(packageName.split("\\."));      URI targetFile = targetDirectory.appendSegment(className + ".java");      monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_Generating_message", new Object[] { targetFile }));      ensureContainerExists(targetDirectory, createMonitor(monitor, 1));      if (arguments == null)      {        arguments = new Object[] { generatingObject };      }      createImportManager(packageName, className);      String emitterResult = jetEmitter.generate(createMonitor(monitor, 1), arguments);      boolean changed = true;      String newContents = emitterResult;      JControlModel jControlModel = getGenerator().getJControlModel();      //DMS This is not right. It replaced "if (EMFPlugin.IS_ECLIPSE_RUNNING)" but can also be false if an invalid facade has been specified.      if (jControlModel.canMerge())      {        JMerger jMerger = new JMerger(jControlModel);        jMerger.setFixInterfaceBrace(true);        jMerger.setSourceCompilationUnit(jMerger.createCompilationUnitForContents(emitterResult));        // Create a code formatter for this compilation unit, if needed.        //        Object codeFormatter = getGenerator().getOptions().codeFormatting ?          createCodeFormatter(getGenerator().getOptions().codeFormatterOptions, targetFile) : null;        if (exists(targetFile))        {          monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_ExaminingOld_message", new Object[] { targetFile }));          jMerger.setTargetCompilationUnit(jMerger.createCompilationUnitForInputStream(createInputStream(targetFile), getEncoding(targetFile)));          String oldContents = jMerger.getTargetCompilationUnitContents();          monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_PreparingNew_message", new Object[] { targetFile }));          jMerger.merge();          newContents = formatCode(jMerger.getTargetCompilationUnitContents(), codeFormatter);          changed = !oldContents.equals(newContents);          // If the target is read-only, we can ask the platform to release it, and it may be updated in the process.          //          if (changed && isReadOnly(targetFile) && validateEdit(targetFile, createMonitor(monitor, 1)))          {            jMerger.setTargetCompilationUnit(jMerger.createCompilationUnitForInputStream(createInputStream(targetFile), getEncoding(targetFile)));            jMerger.remerge();            newContents = formatCode(jMerger.getTargetCompilationUnitContents(), codeFormatter);          }        }        else        {          changed = true;          monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_PreparingNew_message", new Object[] { targetFile }));                    jMerger.merge();          newContents = formatCode(jMerger.getTargetCompilationUnitContents(), codeFormatter);        }        if (jControlModel.getFacadeHelper() != null)        {          jControlModel.getFacadeHelper().reset();        }      }      else      {        //DMS What if Eclipse is running, but an invalid facade has been specified?  We still should format code, use encoding,...        newContents =           CodeGenUtil.convertFormat(jControlModel.getLeadingTabReplacement(), jControlModel.convertToStandardBraceStyle(), emitterResult);        if (exists(targetFile))        {          monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_ExaminingOld_message", new Object[] { targetFile }));          String oldContents = getContents(targetFile, null);           changed = !oldContents.equals(newContents);        }        else        {          changed = true;        }      }      monitor.worked(1);      if (changed)      {        String encoding = getEncoding(targetFile);        byte[] bytes = encoding == null ? newContents.getBytes() : newContents.getBytes(encoding);        // Apply a redirection pattern, if specified.        //        String redirection = getGenerator().getOptions().redirectionPattern;        boolean redirect = redirection != null && redirection.indexOf("{0}") != -1;        if (redirect)        {          String baseName = MessageFormat.format(redirection, new Object[] { className + ".java" });          targetFile = targetDirectory.appendSegment(baseName);          monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_UsingAlternate_message", new Object[] { targetFile }));        }         if (isReadOnly(targetFile))        {          if (getGenerator().getOptions().forceOverwrite)          {            setWriteable(targetFile);          }          else          {            targetFile = targetDirectory.appendSegment("." + className + ".java.new");            monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_UsingDefaultAlternate_message", new Object[] { targetFile }));          }        }        OutputStream outputStream = createOutputStream(targetFile);        outputStream.write(bytes);        outputStream.close();      }    }    catch (Exception e)    {      //DMS  Do a better job with specific exceptions? Just use chained RuntimeExceptions?      throw e instanceof RuntimeException ? (RuntimeException)e : new WrappedException(e);    }//    catch (JETException exception)//    {//      CodeGenEcorePlugin.INSTANCE.log(exception);//    }//    catch (Exception exception)//    {//      CodeGenEcorePlugin.INSTANCE.log(exception);//    }    finally    {      clearImportManager();      monitor.done();    }  }