boolean (@Nullable PsiExpression expression) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (expression instanceof PsiLiteralExpression || expression instanceof PsiThisExpression || expression instanceof PsiClassObjectAccessExpression || isEvaluatedAtCompileTime(expression)) { return true; } if (expression instanceof PsiConditionalExpression cond) { return isSafelyRecomputableExpression(cond.getCondition()) && isSafelyRecomputableExpression(cond.getThenExpression()) && isSafelyRecomputableExpression(cond.getElseExpression()); } if (expression instanceof PsiReferenceExpression ref) { PsiElement target = ref.resolve(); if (target instanceof PsiLocalVariable || target instanceof PsiParameter) return true; PsiExpression qualifier = ref.getQualifierExpression(); if (target == null && qualifier == null) return true; if (target instanceof PsiField field) { if (!field.hasModifierProperty(PsiModifier.FINAL)) return false; return qualifier == null || qualifier instanceof PsiThisExpression || field.hasModifierProperty(PsiModifier.STATIC); } } if (expression instanceof PsiMethodCallExpression call) { return KNOWN_SIMPLE_CALLS.test(call); } return false; }