PsiDeclarationStatement (@NotNull PsiElement parent, @NotNull PsiElement anchor, @NotNull String varName, @NotNull PsiType type, @Nullable PsiExpression initializer) { PsiElementFactory elementFactory = PsiElementFactory.getInstance(parent.getProject()); PsiType displayType; if ( initializer != null && parent.getContext() != null && PsiUtil.isLanguageLevel10OrHigher(parent.getContainingFile()) && JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_VAR_TYPE ) { displayType = TypeUtils.getType(PsiKeyword.VAR, parent.getContext()); } else { displayType = type; } PsiDeclarationStatement declaration = elementFactory .createVariableDeclarationStatement(varName, displayType, initializer); declaration = (PsiDeclarationStatement)parent.addBefore(declaration, anchor); JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(parent.getProject()); return (PsiDeclarationStatement)codeStyleManager.shortenClassReferences(declaration); }