boolean (PsiExpression expression) { return hasMatchingOffspring(expression, PsiPatternVariable.class, v -> { final PsiElement scope = v.getDeclarationScope(); return !PsiTreeUtil.isAncestor(expression, scope, false) && hasMatchingOffspring(scope, PsiReferenceExpression.class, r -> r.isReferenceTo(v) && !PsiTreeUtil.isAncestor(expression, r, true)); }); }