boolean (PsiExpression arg, PsiClass targetClass) { if (arg instanceof PsiMethodReferenceExpression) { PsiElement target = ((PsiMethodReferenceExpression)arg).resolve(); if (target instanceof PsiMethod method) { // Integer::new or Integer::valueOf if (targetClass == method.getContainingClass() && (method.isConstructor() || method.getName().equals("valueOf")) && method.getParameterList().getParametersCount() == 1) { return true; } } } if (arg instanceof PsiLambdaExpression lambda) { PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 1) return false; PsiParameter parameter = parameters[0]; PsiExpression expression = skipParenthesizedExprDown(LambdaUtil.extractSingleExpressionFromBody(lambda.getBody())); // x -> x if (ExpressionUtils.isReferenceTo(expression, parameter)) { return true; } if (expression instanceof PsiCallExpression) { PsiExpressionList list = ((PsiCallExpression)expression).getArgumentList(); if (list == null) return false; PsiExpression[] args = list.getExpressions(); if (args.length != 1 || !ExpressionUtils.isReferenceTo(args[0], parameter)) { return false; } // x -> new Integer(x) if (expression instanceof PsiNewExpression) { PsiJavaCodeReferenceElement ref = ((PsiNewExpression)expression).getClassReference(); if (ref != null && ref.isReferenceTo(targetClass)) return true; } // x -> Integer.valueOf(x) if (expression instanceof PsiMethodCallExpression) { PsiMethod method = ((PsiMethodCallExpression)expression).resolveMethod(); if (method != null && method.getContainingClass() == targetClass && method.getName().equals("valueOf")) return true; } } } return false; }