StringCase (@Nullable PsiExpression expression, int energy) { if (expression == null || energy <= 0) return StringCase.UNSURE; expression = PsiUtil.skipParenthesizedExprDown(expression); String str = tryCast(ExpressionUtils.computeConstantExpression(expression), String.class); if (str != null) { return fromConstant(str); } if (expression instanceof PsiMethodCallExpression call) { if (CASE_PRESERVING_METHODS.test(call)) { return fromExpression(call.getMethodExpression().getQualifierExpression(), energy - 1); } if (TO_LOWER_CASE.test(call)) { return new StringCase(ThreeState.UNSURE, ThreeState.NO); } if (TO_UPPER_CASE.test(call)) { return new StringCase(ThreeState.NO, ThreeState.UNSURE); } } if (expression instanceof PsiConditionalExpression) { PsiExpression thenBranch = ((PsiConditionalExpression)expression).getThenExpression(); StringCase thenCase = fromExpression(thenBranch, energy / 2); if (thenCase.equals(StringCase.UNSURE)) return thenCase; PsiExpression elseBranch = ((PsiConditionalExpression)expression).getElseExpression(); return fromExpression(elseBranch, energy / 2).either(thenCase); } if (expression instanceof PsiPolyadicExpression && ((PsiPolyadicExpression)expression).getOperationTokenType().equals(JavaTokenType.PLUS)) { PsiExpression[] operands = ((PsiPolyadicExpression)expression).getOperands(); StringCase result = new StringCase(ThreeState.NO, ThreeState.NO); for (PsiExpression operand : operands) { StringCase operandCase = fromExpression(operand, energy / operands.length); result = result.concat(operandCase); if (result.myHasLower == ThreeState.YES && result.myHasUpper == ThreeState.YES) { break; } } return result; } if (expression instanceof PsiReferenceExpression) { return fromExpression(resolveDefinition(expression), energy - 4); } return StringCase.UNSURE; }