private void _generate(final LwRootContainer rootContainer, final Module module) throws CodeGenerationException, IncorrectOperationException{
    myBuffer = new StringBuffer();
    myIsFirstParameterStack = new BooleanStack();

    final HashMap<LwComponent,String> component2variable = new HashMap<>();
    final Object2IntMap<String> class2variableIndex = new Object2IntOpenHashMap<>();
    final HashMap<String,LwComponent> id2component = new HashMap<>();

    if (rootContainer.getComponentCount() != 1) {
      throw new CodeGenerationException(null, UIDesignerBundle.message("error.one.toplevel.component.required"));
    }
    final LwComponent topComponent = (LwComponent)rootContainer.getComponent(0);
    String id = Utils.findNotEmptyPanelWithXYLayout(topComponent);
    if (id != null) {
      throw new CodeGenerationException(id, UIDesignerBundle.message("error.nonempty.xy.panels.found"));
    }

    final PsiClass classToBind = FormEditingUtil.findClassToBind(module, rootContainer.getClassToBind());
    if (classToBind == null) {
      throw new ClassToBindNotFoundException(UIDesignerBundle.message("error.class.to.bind.not.found", rootContainer.getClassToBind()));
    }

    final boolean haveCustomCreateComponents = Utils.getCustomCreateComponentCount(rootContainer) > 0;
    if (haveCustomCreateComponents) {
      if (FormEditingUtil.findCreateComponentsMethod(classToBind) == null) {
        throw new CodeGenerationException(null, UIDesignerBundle.message("error.no.custom.create.method"));
      }
      myBuffer.append(AsmCodeGenerator.CREATE_COMPONENTS_METHOD_NAME).append("();");
    }

    generateSetupCodeForComponent(topComponent,
                                  component2variable,
                                  class2variableIndex,
                                  id2component, module, classToBind);
    generateComponentReferenceProperties(topComponent, component2variable, class2variableIndex, id2component, classToBind);
    generateButtonGroups(rootContainer, component2variable, class2variableIndex, id2component, classToBind);

    final String methodText = myBuffer.toString();

    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();

    PsiClass newClass = (PsiClass) classToBind.copy();

    PsiElement initializerComment = null;
    PsiElement firstMethodMarker = null;
    PsiMethod[] methods = newClass.findMethodsByName(AsmCodeGenerator.SETUP_METHOD_NAME, false);
    PsiClassInitializer[] initializers = newClass.getInitializers();

    for (PsiMethod method: methods) {
      if (method.hasParameters()) {
        continue;
      }
      for (PsiClassInitializer initializer : initializers) {
        if (containsMethodIdentifier(initializer, method)) {
          PsiElement child = initializer.getFirstChild();
          // very smart java PSI move comment node before class initializer to initializer children
          if (child instanceof PsiComment && child.getTextOffset() == initializer.getTextOffset()) {
            initializerComment = child.copy();
            break;
          }
        }
      }
      firstMethodMarker = newClass
        .addBefore(elementFactory.createFieldFromText("private int ____temp_field__" + System.currentTimeMillis() + ";", null), method);
      break;
    }

    cleanup(newClass);

    // [anton] the comments are written according to the SCR 26896
    final PsiClass fakeClass = elementFactory.createClassFromText(
      "{\n" +
      "// GUI initializer generated by " + ApplicationNamesInfo.getInstance().getFullProductName() + " GUI Designer\n" +
      "// >>> IMPORTANT!! <<<\n" +
      "// DO NOT EDIT OR ADD ANY CODE HERE!\n" +
      AsmCodeGenerator.SETUP_METHOD_NAME + "();\n" +
      "}\n" +
      "\n" +
      "/** Method generated by " + ApplicationNamesInfo.getInstance().getFullProductName() + " GUI Designer\n" +
      " * >>> IMPORTANT!! <<<\n" +
      " * DO NOT edit this method OR call it in your code!\n" +
      " * @noinspection ALL\n" +
      " */\n" +
      "private void " + AsmCodeGenerator.SETUP_METHOD_NAME + "()\n" +
      "{\n" +
      methodText +
      "}\n",
      null
    );

    final CodeStyleManager formatter = CodeStyleManager.getInstance(module.getProject());
    final JavaCodeStyleManager styler = JavaCodeStyleManager.getInstance(module.getProject());

    PsiMethod method = (PsiMethod)(firstMethodMarker == null
                                   ? newClass.add(fakeClass.getMethods()[0])
                                   : newClass.addAfter(fakeClass.getMethods()[0], firstMethodMarker));
    if (firstMethodMarker != null) {
      firstMethodMarker.delete();
    }

    // don't generate initializer block if $$$setupUI$$$() is called explicitly from one of the constructors
    boolean needInitializer = true;
    boolean needSetupUI = false;
    for(PsiMethod constructor: newClass.getConstructors()) {
      if (containsMethodIdentifier(constructor, method)) {
        needInitializer = false;
      }
      else if (haveCustomCreateComponents && hasCustomComponentAffectingReferences(constructor, newClass, rootContainer, null)) {
        needInitializer = false;
        needSetupUI = true;
      }
    }

    if (needSetupUI) {
      for(PsiMethod constructor: newClass.getConstructors()) {
        addSetupUICall(constructor, rootContainer, method);
      }
    }

    if (needInitializer) {
      PsiElement initializer = newClass.addBefore(fakeClass.getInitializers()[0], method);
      if (initializerComment != null) {
        newClass.addBefore(initializerComment, initializer);
      }
    }

    final @NonNls String grcMethodText = "/** @noinspection ALL */ public javax.swing.JComponent " +
                                         AsmCodeGenerator.GET_ROOT_COMPONENT_METHOD_NAME +
                                         "() { return " + topComponent.getBinding() + "; }";
    generateMethodIfRequired(newClass, method, AsmCodeGenerator.GET_ROOT_COMPONENT_METHOD_NAME, grcMethodText, topComponent.getBinding() != null);

    final String loadButtonTextMethodText = getLoadMethodText(AsmCodeGenerator.LOAD_BUTTON_TEXT_METHOD, AbstractButton.class, module);
    generateMethodIfRequired(newClass, method, AsmCodeGenerator.LOAD_BUTTON_TEXT_METHOD, loadButtonTextMethodText, myNeedLoadButtonText);
    final String loadLabelTextMethodText = getLoadMethodText(AsmCodeGenerator.LOAD_LABEL_TEXT_METHOD, JLabel.class, module);
    generateMethodIfRequired(newClass, method, AsmCodeGenerator.LOAD_LABEL_TEXT_METHOD, loadLabelTextMethodText, myNeedLoadLabelText);

    generateGetMessageFromBundle(newClass, method, elementFactory, myNeedGetMessageFromBundle);

    if (myGetFontMethod != null) {
      String getFontMethod =
        "/** @noinspection ALL */ " +
        "private java.awt.Font " + myGetFontMethod +
        "(java.lang.String fontName, int style, int size, java.awt.Font currentFont) {" +
        "if (currentFont == null) return null;" +
        "java.lang.String resultName;" +
        "if (fontName == null) {resultName = currentFont.getName();}" +
        "else {" +
        "  java.awt.Font testFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 10);" +
        "  if (testFont.canDisplay('a') && testFont.canDisplay('1')) {resultName = fontName;}" +
        "  else {resultName = currentFont.getName();}" +
        "}" +
        "java.awt.Font font = new java.awt.Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());" +
        "boolean isMac = java.lang.System.getProperty(\"os.name\", \"\").toLowerCase(java.util.Locale.ENGLISH).startsWith(\"mac\");" +
        "java.awt.Font fontWithFallback = isMac" +
        "? new java.awt.Font(font.getFamily(), font.getStyle(), font.getSize())" +
        ": new javax.swing.text.StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());" +
        "return fontWithFallback instanceof javax.swing.plaf.FontUIResource ? fontWithFallback : new javax.swing.plaf.FontUIResource(fontWithFallback);}";

      generateMethodIfRequired(newClass, method, myGetFontMethod, getFontMethod, true);
    }

    newClass = (PsiClass) styler.shortenClassReferences(newClass);
    newClass = (PsiClass) formatter.reformat(newClass);

    if (!lexemsEqual(classToBind, newClass)) {
      classToBind.replace(newClass);
    }
  }
private void _generate(final LwRootContainer rootContainer, final Module module)