private static void copyToFinal(PsiVariable variable, PsiElement context) throws IncorrectOperationException {
    PsiManager psiManager = context.getManager();
    final Project project = psiManager.getProject();
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
    PsiExpression initializer = factory.createExpressionFromText(variable.getName(), context);
    String newName = suggestNewName(project, variable);
    PsiType type = variable.getType();
    PsiDeclarationStatement copyDecl = factory.createVariableDeclarationStatement(newName, type, initializer);
    PsiVariable newVariable = (PsiVariable)copyDecl.getDeclaredElements()[0];
    final boolean mustBeFinal =
      !PsiUtil.isAvailable(JavaFeature.EFFECTIVELY_FINAL, context) || JavaCodeStyleSettings.getInstance(context.getContainingFile()).GENERATE_FINAL_LOCALS;
    PsiUtil.setModifierProperty(newVariable, PsiModifier.FINAL, mustBeFinal);
    PsiElement statement = getStatementToInsertBefore(variable, context);
    if (statement == null) return;
    PsiExpression newExpression = factory.createExpressionFromText(newName, variable);
    replaceReferences(context, variable, newExpression);
    if (CommonJavaRefactoringUtil.isLoopOrIf(statement.getParent())) {
      CommonJavaRefactoringUtil.putStatementInLoopBody(copyDecl, statement.getParent(), statement);
    } else {
      statement.getParent().addBefore(copyDecl, statement);
    }
  }
private static void copyToFinal(PsiVariable variable, PsiElement context)