String (CommentTracker ct, @NotNull PsiExpression expression, int expressionCount, boolean neighborIsString) { PsiType type = expression.getType(); if (expression instanceof PsiMethodCallExpression callExpression && isCallOf(callExpression, CommonClassNames.JAVA_LANG_STRING, "charAt")) { PsiExpression qualifierExpression = callExpression.getMethodExpression().getQualifierExpression(); PsiExpression[] expressions = callExpression.getArgumentList().getExpressions(); if (expressions.length == 1) { PsiExpression first = expressions[0]; if (qualifierExpression != null && ExpressionUtils.computeConstantExpression(first) instanceof Integer intValue) { String endIndex = String.valueOf(intValue + 1); return ct.text(qualifierExpression) + ".substring(" + ct.text(first) + "," + endIndex + ")"; } } } if (!InheritanceUtil.isInheritor(type, JAVA_LANG_CHAR_SEQUENCE)) { if (!neighborIsString || (type instanceof PsiArrayType && ((PsiArrayType)type).getComponentType().equals(PsiTypes.charType()))) { PsiLiteralExpression literalExpression = tryCast(expression, PsiLiteralExpression.class); if (literalExpression != null) { Object value = literalExpression.getValue(); if (value instanceof Character) { String text = ct.text(literalExpression); if ("'\"'".equals(text)) return "\"\\\"\""; return "\"" + text.substring(1, text.length() - 1) + "\""; } } return CommonClassNames.JAVA_LANG_STRING + ".valueOf(" + ct.text(expression) + ")"; } if (ParenthesesUtils.getPrecedence(expression) > ParenthesesUtils.ADDITIVE_PRECEDENCE || (expression.getType() instanceof PsiPrimitiveType && ParenthesesUtils.getPrecedence(expression) == ParenthesesUtils.ADDITIVE_PRECEDENCE) || expressionCount == 1) { return "(" + ct.text(expression) + ")"; } return ct.text(expression); } String expressionText = ct.text(expression); if(ParenthesesUtils.getPrecedence(expression) > ParenthesesUtils.ADDITIVE_PRECEDENCE && expressionCount > 1) { expressionText = "(" + expressionText + ")"; } return expressionText; }