void (PsiElement closure) { Set<PsiVariable> variables = new HashSet<>(); Set<DfaVariableValue> escapedVars = new HashSet<>(); closure.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { super.visitReferenceExpression(expression); final PsiElement target = expression.resolve(); if (PsiUtil.isJvmLocalVariable(target)) { variables.add((PsiVariable)target); } if (target instanceof PsiMember) { DfaValue escapedVar = JavaDfaValueFactory.getQualifierOrThisValue(getFactory(), expression); if (escapedVar == null) { escapedVar = JavaDfaValueFactory.getExpressionDfaValue(getFactory(), expression); } if (escapedVar instanceof DfaVariableValue dfaVar) { escapedVars.add(dfaVar); } } } @Override public void visitThisExpression(@NotNull PsiThisExpression expression) { super.visitThisExpression(expression); DfaValue value = JavaDfaValueFactory.getExpressionDfaValue(getFactory(), expression); if (value instanceof DfaVariableValue dfaVar) { escapedVars.add(dfaVar); } } }); for (DfaValue value : getFactory().getValues()) { if (value instanceof DfaVariableValue dfaVar && dfaVar.getPsiVariable() instanceof PsiVariable var && variables.contains(var)) { escapedVars.add(dfaVar); } } if (!escapedVars.isEmpty()) { addInstruction(new EscapeInstruction(escapedVars)); } List<PsiElement> closures; if (closure instanceof PsiClass psiClass) { closures = getClosures(psiClass); } else if (closure instanceof PsiLambdaExpression lambda) { closures = ContainerUtil.createMaybeSingletonList(lambda.getBody()); } else { closures = List.of(); } if (!closures.isEmpty()) { addInstruction(new ClosureInstruction(closures)); } }