String () { if (myHasWriteAccess || myOccurrences.isEmpty()) return null; PsiExpression expression = myOccurrences.get(0); // The whole lambda body selected if (myOccurrences.size() == 1 && expression.getParent() instanceof PsiLambdaExpression) return null; PsiElement parent = PsiTreeUtil.findCommonParent(myOccurrences); if (parent == null) return null; PsiType type = expression.getType(); PsiLambdaExpression lambda = PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class, true, PsiStatement.class); ChainCallExtractor extractor = ChainCallExtractor.findExtractor(lambda, expression, type); if (extractor == null) return null; PsiParameter parameter = lambda.getParameterList().getParameters()[0]; if (!ReferencesSearch.search(parameter).forEach((Processor<PsiReference>)ref -> myOccurrences.stream().anyMatch(expr -> PsiTreeUtil.isAncestor(expr, ref.getElement(), false)))) { return null; } return extractor.getMethodName(parameter, expression, type); }