@NotNull
  public static Document createDocument(@NotNull Project project, @Nullable LanguageFileType fileType, Language dialect,
                                        PatternContext patternContext, @NotNull String text, @Nullable StructuralSearchProfile profile) {
    if (fileType != null && profile != null) {
      final String contextId = (patternContext == null) ? null : patternContext.getId();
      PsiFile codeFragment = profile.createCodeFragment(project, text, contextId);
      if (codeFragment == null) {
        codeFragment = createFileFragment(project, fileType, dialect, text);
      }

      if (codeFragment != null) {
        final Document doc = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
        assert doc != null : "code fragment element should be physical";
        return doc;
      }
    }
    return EditorFactory.getInstance().createDocument(text);
  }
@NotNull
  public static Document createDocument(@NotNull Project project, @Nullable LanguageFileType fileType, Language dialect,
                                        PatternContext patternContext, @NotNull String text, @Nullable StructuralSearchProfile profile)