boolean (@NotNull PsiExpression expression, @NotNull PsiExpression unboxedExpression) { PsiElement parent = expression.getParent(); while (parent instanceof PsiParenthesizedExpression) { expression = (PsiExpression)parent; parent = parent.getParent(); } if (parent instanceof PsiPolyadicExpression polyadicExpression) { if (isPossibleObjectComparison(expression, polyadicExpression)) { return true; } } if (parent instanceof PsiTypeCastExpression typeCastExpression) { final PsiTypeElement typeElement = typeCastExpression.getCastType(); if (typeElement == null) { return true; } final PsiType castType = typeElement.getType(); final PsiType expressionType = expression.getType(); if (expressionType == null || !castType.isAssignableFrom(expressionType)) { return true; } } else if (parent instanceof PsiConditionalExpression conditionalExpression) { final PsiExpression thenExpression = conditionalExpression.getThenExpression(); if (thenExpression == null) { return true; } final PsiExpression elseExpression = conditionalExpression.getElseExpression(); if (elseExpression == null) { return true; } if (PsiTreeUtil.isAncestor(thenExpression, expression, false)) { final PsiType type = elseExpression.getType(); if (!(type instanceof PsiPrimitiveType)) { return true; } } else if (PsiTreeUtil.isAncestor(elseExpression, expression, false)) { final PsiType type = thenExpression.getType(); if (!(type instanceof PsiPrimitiveType)) { return true; } } } else if (MethodCallUtils.isNecessaryForSurroundingMethodCall(expression, unboxedExpression)) { return true; } if (!LambdaUtil.isSafeLambdaReturnValueReplacement(expression, unboxedExpression)) return true; if (onlyReportSuperfluouslyUnboxed) { final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false, true); if (!(expectedType instanceof PsiClassType)) { return true; } } return false; }