boolean (PsiExpression qualifier) { // Conservatively skip the results of method calls if there's an isPresent() call with the same qualifier in the method if (qualifier instanceof PsiMethodCallExpression) { PsiElement context = PsiTreeUtil.getParentOfType(qualifier, PsiMember.class, PsiLambdaExpression.class); if (context != null) { return !PsiTreeUtil.processElements(context, e -> { if (e == qualifier || !(e instanceof PsiMethodCallExpression call)) return true; String name = call.getMethodExpression().getReferenceName(); if ((!"isPresent".equals(name) && !"isEmpty".equals(name)) || !call.getArgumentList().isEmpty()) return true; PsiExpression isPresentQualifier = call.getMethodExpression().getQualifierExpression(); return isPresentQualifier == null || !PsiEquivalenceUtil.areElementsEquivalent(qualifier, isPresentQualifier); }); } } return false; }