PsiExpression (PsiVariable variable) { PsiExpression initializer = variable.getInitializer(); if (initializer != null) { PsiModifierList modifierList = variable.getModifierList(); if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.FINAL) && !(initializer instanceof PsiLiteralExpression || initializer instanceof PsiPrefixExpression)) { JavaPsiFacade instance = JavaPsiFacade.getInstance(variable.getProject()); Object o = instance.getConstantEvaluationHelper().computeConstantExpression(initializer); if (o != null) { String text = o.toString(); PsiType type = variable.getType(); if (type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { text = '"' + StringUtil.escapeStringCharacters(StringUtil.shortenPathWithEllipsis(text, 120)) + '"'; } else if (type.equalsToText("char")) { text = '\'' + text + '\''; } try { return instance.getElementFactory().createExpressionFromText(text, variable); } catch (IncorrectOperationException ex) { LOG.info("type:" + type.getCanonicalText() + "; text: " + text, ex); } } } } return null; }