void (ExtractInfoHelper helper, boolean isVoid, StringBuilder buffer, boolean forceReturn) { VariableInfo[] outputInfos = helper.getOutputVariableInfos(); ParameterInfo[] infos = helper.getParameterInfos(); Set<String> declaredVars = new HashSet<>(); for (ParameterInfo info : infos) { declaredVars.add(info.getName()); } for (VariableInfo info : mustAddVariableDeclaration(helper.getStatements(), outputInfos)) { declaredVars.add(info.getName()); } List<VariableInfo> genDecl = new ArrayList<>(); final Collection<GrVariable> outside = collectUsedLocalVarsOrParamsDeclaredOutside(helper); for (final GrVariable variable : outside) { if (!declaredVars.contains(variable.getName())) { genDecl.add(new VariableInfo() { @NotNull @Override public String getName() { return variable.getName(); } @Override public PsiType getType() { return variable.getDeclaredType(); } }); } } final List<GrStatement> statements = generateVarDeclarations(genDecl, helper.getProject(), null); for (GrStatement statement : statements) { buffer.append(statement.getText()).append('\n'); } final StringPartInfo stringPartInfo = helper.getStringPartInfo(); if (!isSingleExpression(helper.getStatements()) && stringPartInfo == null) { for (PsiElement element : helper.getInnerElements()) { buffer.append(element.getText()); } //append return statement if (!isVoid && outputInfos.length > 0) { buffer.append('\n'); if (forceReturn) { buffer.append("return "); } if (outputInfos.length > 1) buffer.append('['); for (VariableInfo info : outputInfos) { buffer.append(info.getName()).append(", "); } buffer.delete(buffer.length() - 2, buffer.length()); if (outputInfos.length > 1) buffer.append(']'); } } else { GrExpression expr = stringPartInfo != null ? stringPartInfo.createLiteralFromSelected() : (GrExpression)PsiUtil.skipParentheses(helper.getStatements()[0], false); boolean addReturn = !isVoid && forceReturn && !PsiUtil.isVoidMethodCall(expr); if (addReturn) { buffer.append("return "); final GrExpression methodCall = ApplicationStatementUtil.convertToMethodCallExpression(expr); buffer.append(methodCall.getText()); } else { buffer.append(expr != null ? expr.getText() : ""); } } }