String (@NotNull GrExpression initializer) { GrExpression inner = initializer; while (inner instanceof GrParenthesizedExpression) inner = ((GrParenthesizedExpression)inner).getOperand(); if (inner != null) initializer = inner; if (initializer instanceof GrReferenceExpression) { final GrExpression qualifier = ((GrReferenceExpression)initializer).getQualifier(); if (qualifier == null) { final PsiElement resolved = ((GrReferenceExpression)initializer).resolve(); if (resolved instanceof GrVariable && !(resolved instanceof GrField)) { //don't create new var. it is already exists return ((GrVariable)resolved).getName(); } } } final String name = GenerationUtil.suggestVarName(initializer, context); final StringBuilder builder = new StringBuilder(); builder.append("final "); TypeWriter.writeType(builder, initializer.getType(), initializer); builder.append(' ').append(name).append(" = "); initializer.accept(new ExpressionGenerator(builder, context)); builder.append(';'); context.myStatements.add(builder.toString()); return name; }