void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiMethodCallExpression writeCall = tryCast(element.getParent().getParent(), PsiMethodCallExpression.class); if (!FILES_WRITE.test(writeCall)) return; PsiExpressionList argumentList = writeCall.getArgumentList(); PsiExpression[] args = argumentList.getExpressions(); if (args.length < 2) return; PsiExpression bytesArg = args[1]; PsiMethodCallExpression bytesExpression = tryCast(ExpressionUtils.resolveExpression(bytesArg), PsiMethodCallExpression.class); if (!STRING_GET_BYTES.test(bytesExpression)) return; PsiExpression stringExpression = PsiUtil.skipParenthesizedExprDown(bytesExpression.getMethodExpression().getQualifierExpression()); if (stringExpression == null) return; PsiExpression charsetExpression = bytesExpression.getArgumentList().getExpressions()[0]; CommentTracker ct = new CommentTracker(); ExpressionUtils.bindCallTo(writeCall, "writeString"); if (!isUtf8Charset(charsetExpression)) { argumentList.addAfter(ct.markUnchanged(charsetExpression), bytesArg); } PsiLocalVariable variable = ExpressionUtils.resolveLocalVariable(bytesArg); ct.replaceAndRestoreComments(bytesArg, stringExpression); if (variable != null) { ct = new CommentTracker(); ct.markUnchanged(stringExpression); ct.deleteAndRestoreComments(variable); } }