public static void generateCreateComponentsMethod(final PsiClass aClass) {
    final PsiFile psiFile = aClass.getContainingFile();
    if (psiFile == null) return;
    final VirtualFile vFile = psiFile.getVirtualFile();
    if (vFile == null) return;
    if (!FileModificationService.getInstance().prepareFileForWrite(psiFile)) return;

    final Ref<SmartPsiElementPointer> refMethod = new Ref<>();
    CommandProcessor.getInstance().executeCommand(
      aClass.getProject(),
      () -> ApplicationManager.getApplication().runWriteAction(() -> {
        PsiElementFactory factory = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory();
        try {
          PsiMethod method = factory.createMethodFromText("private void " +
                                                          AsmCodeGenerator.CREATE_COMPONENTS_METHOD_NAME +
                                                          "() { \n // TODO: place custom component creation code here \n }", aClass);
          final PsiMethod psiMethod = (PsiMethod)aClass.add(method);
          refMethod.set(SmartPointerManager.getInstance(aClass.getProject()).createSmartPsiElementPointer(psiMethod));
          CodeStyleManager.getInstance(aClass.getProject()).reformat(psiMethod);
        }
        catch (IncorrectOperationException e) {
          LOG.error(e);
        }
      }), null, null
    );

    if (!refMethod.isNull()) {
      ApplicationManager.getApplication().invokeLater(() -> {
        final PsiMethod element = (PsiMethod) refMethod.get().getElement();
        if (element != null) {
          final PsiCodeBlock body = element.getBody();
          assert body != null;
          final PsiComment comment = PsiTreeUtil.getChildOfType(body, PsiComment.class);
          if (comment != null) {
            PsiNavigationSupport.getInstance().createNavigatable(comment.getProject(), vFile, comment.getTextOffset())
                                .navigate(true);
          }
        }
      });
    }
  }
public static void generateCreateComponentsMethod(final PsiClass aClass)