@NotNull
  @Override
  public PsiCatchSection createCatchSection(
      @NotNull final PsiType exceptionType,
      @NotNull final String exceptionName,
      @Nullable final PsiElement context)
      throws IncorrectOperationException {
    if (!(exceptionType instanceof PsiClassType || exceptionType instanceof PsiDisjunctionType)) {
      throw new IncorrectOperationException("Unexpected type:" + exceptionType);
    }

    @NonNls
    final String text = "catch (" + exceptionType.getCanonicalText() + " " + exceptionName + ") {}";
    final DummyHolder holder =
        DummyHolderFactory.createHolder(
            myManager, new JavaDummyElement(text, CATCH_SECTION, level(context)), context);
    final PsiElement element =
        SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiCatchSection)) {
      throw new IncorrectOperationException(
          "Incorrect catch section '" + text + "'. Parsed element: " + element);
    }

    final Project project = myManager.getProject();
    final JavaPsiImplementationHelper helper = JavaPsiImplementationHelper.getInstance(project);
    helper.setupCatchBlock(exceptionName, exceptionType, context, (PsiCatchSection) element);
    final CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
    final PsiCatchSection catchSection = (PsiCatchSection) styleManager.reformat(element);

    GeneratedMarkerVisitor.markGenerated(catchSection);
    return catchSection;
  }
  @NotNull
  @Override
  public PsiDeclarationStatement createVariableDeclarationStatement(
      @NotNull String name, @NotNull PsiType type, @Nullable PsiExpression initializer)
      throws IncorrectOperationException {
    if (!isIdentifier(name)) {
      throw new IncorrectOperationException("\"" + name + "\" is not an identifier.");
    }
    if (PsiType.NULL.equals(type)) {
      throw new IncorrectOperationException("Cannot create variable with type \"null\".");
    }

    String text = "X " + name + (initializer != null ? " = x" : "") + ";";
    PsiDeclarationStatement statement =
        (PsiDeclarationStatement) createStatementFromText(text, null);

    PsiVariable variable = (PsiVariable) statement.getDeclaredElements()[0];
    replace(variable.getTypeElement(), createTypeElement(type), text);

    boolean generateFinalLocals =
        JavaCodeStyleSettingsFacade.getInstance(myManager.getProject()).isGenerateFinalLocals();
    PsiUtil.setModifierProperty(variable, PsiModifier.FINAL, generateFinalLocals);

    if (initializer != null) {
      replace(variable.getInitializer(), initializer, text);
    }

    GeneratedMarkerVisitor.markGenerated(statement);
    return statement;
  }
 @NotNull
 @Override
 public PsiTypeParameter createTypeParameterFromText(
     @NotNull final String text, final PsiElement context) throws IncorrectOperationException {
   final PsiTypeParameter typeParameter = super.createTypeParameterFromText(text, context);
   GeneratedMarkerVisitor.markGenerated(typeParameter);
   return typeParameter;
 }
 @NotNull
 @Override
 public PsiMethod createMethodFromText(
     @NotNull final String text, final PsiElement context, final LanguageLevel level)
     throws IncorrectOperationException {
   final PsiMethod method = super.createMethodFromText(text, context, level);
   GeneratedMarkerVisitor.markGenerated(method);
   return method;
 }
 @NotNull
 @Override
 public PsiStatement createStatementFromText(
     @NotNull final String text, @Nullable final PsiElement context)
     throws IncorrectOperationException {
   final PsiStatement statement = super.createStatementFromText(text, context);
   GeneratedMarkerVisitor.markGenerated(statement);
   return statement;
 }
 @NotNull
 @Override
 public PsiField createFieldFromText(
     @NotNull final String text, @Nullable final PsiElement context)
     throws IncorrectOperationException {
   final PsiField psiField = super.createFieldFromText(text, context);
   GeneratedMarkerVisitor.markGenerated(psiField);
   return psiField;
 }
 @NotNull
 @Override
 public PsiExpression createExpressionFromText(
     @NotNull final String text, @Nullable final PsiElement context)
     throws IncorrectOperationException {
   final PsiExpression expression = super.createExpressionFromText(text, context);
   GeneratedMarkerVisitor.markGenerated(expression);
   return expression;
 }
 @NotNull
 @Override
 public PsiCodeBlock createCodeBlockFromText(
     @NotNull final String text, @Nullable final PsiElement context)
     throws IncorrectOperationException {
   final PsiCodeBlock psiCodeBlock = super.createCodeBlockFromText(text, context);
   GeneratedMarkerVisitor.markGenerated(psiCodeBlock);
   return psiCodeBlock;
 }
 @NotNull
 @Override
 public PsiAnnotation createAnnotationFromText(
     @NotNull final String annotationText, @Nullable final PsiElement context)
     throws IncorrectOperationException {
   final PsiAnnotation psiAnnotation = super.createAnnotationFromText(annotationText, context);
   GeneratedMarkerVisitor.markGenerated(psiAnnotation);
   return psiAnnotation;
 }
  @NotNull
  @Override
  public PsiParameter createParameter(@NotNull final String name, @NotNull final PsiType type)
      throws IncorrectOperationException {
    PsiUtil.checkIsIdentifier(myManager, name);
    if (PsiType.NULL.equals(type)) {
      throw new IncorrectOperationException("Cannot create parameter with type \"null\".");
    }

    final String text = type.getCanonicalText() + " " + name;
    PsiParameter parameter = createParameterFromText(text, null);
    final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
    PsiUtil.setModifierProperty(
        parameter,
        PsiModifier.FINAL,
        JavaCodeStyleSettingsFacade.getInstance(myManager.getProject())
            .isGenerateFinalParameters());
    GeneratedMarkerVisitor.markGenerated(parameter);
    parameter =
        (PsiParameter)
            JavaCodeStyleManager.getInstance(myManager.getProject())
                .shortenClassReferences(parameter);
    return (PsiParameter) codeStyleManager.reformat(parameter);
  }