private static @NotNull PsiElement createElementFromText(@NotNull String text, @NotNull PsiElement context) {
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
    if (context instanceof PsiExpression) {
      return factory.createExpressionFromText(text, context);
    }
    else if (context instanceof PsiStatement) {
      return factory.createStatementFromText(text, context);
    }
    else if (context instanceof PsiTypeElement) {
      return factory.createTypeElementFromText(text, context);
    }
    else if (context instanceof PsiIdentifier) {
      return factory.createIdentifier(text);
    }
    else if (context instanceof PsiComment) {
      return factory.createCommentFromText(text, context);
    }
    else {
      throw new IllegalArgumentException("Unsupported element type: " + context);
    }
  }
private static @NotNull PsiElement createElementFromText(@NotNull String text, @NotNull PsiElement context)