@Override
  public PsiElement @NotNull [] createPatternTree(@NotNull String text,
                                                  @NotNull PatternTreeContext context,
                                                  @NotNull LanguageFileType fileType,
                                                  @NotNull Language language,
                                                  String contextId,
                                                  @NotNull Project project,
                                                  boolean physical) {
    if (MEMBER_CONTEXT.getId().equals(contextId)) {
      context = PatternTreeContext.Class;
    }
    if (context == PatternTreeContext.Block) {
      final PsiCodeFragment fragment = JavaCodeFragmentFactory.getInstance(project).createCodeBlockCodeFragment(text, null, physical);
      final List<PsiElement> result = getNonWhitespaceChildren(fragment);
      if (result.isEmpty()) return PsiElement.EMPTY_ARRAY;

      if (shouldTryExpressionPattern(result)) {
        try {
          final PsiElement[] expressionPattern =
            createPatternTree(text, PatternTreeContext.Expression, fileType, language, contextId, project, physical);
          if (expressionPattern.length == 1) {
            return expressionPattern;
          }
        } catch (IncorrectOperationException ignore) {}
      }
      else if (shouldTryClassPattern(result)) {
        final PsiElement[] classPattern =
          createPatternTree(text, PatternTreeContext.Class, fileType, language, contextId, project, physical);
        if (classPattern.length <= result.size()) {
          return classPattern;
        }
      }
      return PsiUtilCore.toPsiElementArray(result);
    }
    else if (context == PatternTreeContext.Class) {
      final JavaCodeFragment fragment = JavaCodeFragmentFactory.getInstance(project).createMemberCodeFragment(text, null, physical);
      final List<PsiElement> result = getNonWhitespaceChildren(fragment);

      return PsiUtilCore.toPsiElementArray(result);
    }
    else if (context == PatternTreeContext.Expression) {
      final PsiExpressionCodeFragment fragment =
        JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, null, null, physical);
      final PsiExpression expression = fragment.getExpression();
      return (expression == null) ? PsiElement.EMPTY_ARRAY : new PsiElement[] {expression};
    }
    else {
      return new PsiElement[] {PsiFileFactory.getInstance(project).createFileFromText("__dummy.java", JavaFileType.INSTANCE, text)};
    }
  }
@Override
  public PsiElement @NotNull [] createPatternTree(@NotNull String text,
                                                  @NotNull PatternTreeContext context,
                                                  @NotNull LanguageFileType fileType,
                                                  @NotNull Language language,
                                                  String contextId,
                                                  @NotNull Project project,
                                                  boolean physical)