String (PsiExpression expression, PsiType expectedType) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (!(expression instanceof PsiLiteralExpression) && !isNegatedLiteral(expression)) { return null; } final PsiType expressionType = expression.getType(); if (expressionType == null) { return null; } final String text = expression.getText(); if (expressionType.equals(PsiTypes.intType()) && expectedType.equals(PsiTypes.longType())) { return text + 'L'; } if (expressionType.equals(PsiTypes.intType()) && expectedType.equals(PsiTypes.floatType())) { if (!isDecimalLiteral(text)) { return null; } return text + ".0F"; } if (expressionType.equals(PsiTypes.intType()) && expectedType.equals(PsiTypes.doubleType())) { if (!isDecimalLiteral(text)) { return null; } return text + ".0"; } if (expressionType.equals(PsiTypes.longType()) && expectedType.equals(PsiTypes.floatType())) { if (!isDecimalLiteral(text)) { return null; } return text.substring(0, text.length() - 1) + ".0F"; } if (expressionType.equals(PsiTypes.longType()) && expectedType.equals(PsiTypes.doubleType())) { if (!isDecimalLiteral(text)) { return null; } return text.substring(0, text.length() - 1) + ".0"; } if (expressionType.equals(PsiTypes.doubleType()) && expectedType.equals(PsiTypes.floatType())) { final int length = text.length(); if (text.charAt(length - 1) == 'd' || text.charAt(length - 1) == 'D') { return text.substring(0, length - 1) + 'F'; } else { return text + 'F'; } } if (expressionType.equals(PsiTypes.floatType()) && expectedType.equals(PsiTypes.doubleType())) { final int length = text.length(); return text.substring(0, length - 1); } return null; }