private static PsiClass createClassFromTemplate(@NotNull PsiDirectory dir,
                                                  String name,
                                                  String templateName,
                                                  boolean askToDefineVariables, @NotNull Map<String, String> additionalProperties) throws IncorrectOperationException {
    if (askToDefineVariables) {
      LOG.assertTrue(!ApplicationManager.getApplication().isWriteAccessAllowed());
    }
    //checkCreateClassOrInterface(dir, name);

    Project project = dir.getProject();
    FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(templateName);

    Properties defaultProperties = FileTemplateManager.getInstance(project).getDefaultProperties();
    Properties properties = new Properties(defaultProperties);
    properties.setProperty(FileTemplate.ATTRIBUTE_NAME, name);
    for (Map.Entry<String, String> entry : additionalProperties.entrySet()) {
      properties.setProperty(entry.getKey(), entry.getValue());
    }

    String ext = JavaFileType.INSTANCE.getDefaultExtension();
    String fileName = name + "." + ext;

    PsiElement element;
    try {
      element = askToDefineVariables ? new CreateFromTemplateDialog(project, dir, template, null, properties).create()
                                     : FileTemplateUtil.createFromTemplate(template, fileName, properties, dir);
    }
    catch (IncorrectOperationException | ProcessCanceledException e) {
      throw e;
    }
    catch (Exception e) {
      LOG.error(e);
      return null;
    }
    if (element == null) return null;
    final PsiJavaFile file = (PsiJavaFile)element.getContainingFile();
    PsiClass[] classes = file.getClasses();
    if (classes.length < 1) {
      throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, project));
    }
    if (template.isLiveTemplateEnabled()) {
      Document document = file.getViewProvider().getDocument();
      if (document != null) {
        PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
        CreateFromTemplateActionBase.startLiveTemplate(file);
      }
    }
    return classes[0];
  }
private static PsiClass createClassFromTemplate(@NotNull PsiDirectory dir,
                                                  String name,
                                                  String templateName,
                                                  boolean askToDefineVariables, @NotNull Map<String, String> additionalProperties)