TerminalBlock (PsiExpression condition, boolean negated, PsiStatement... statements) { TerminalBlock result = new TerminalBlock(this, new FilterOp(condition, myVariable, negated), myVariable, statements); List<PsiPatternVariable> vars = JavaPsiPatternUtil.getExposedPatternVariables(condition); if (!vars.isEmpty()) { List<PsiPatternVariable> used = ContainerUtil.filter(vars, var -> ContainerUtil.or(statements, st -> VariableAccessUtils.variableIsUsed(var, st))); if (used.size() > 1) return null; if (!used.isEmpty()) { PsiPatternVariable var = used.get(0); String text = JavaPsiPatternUtil.getEffectiveInitializerText(var); if (text == null) return null; if (ContainerUtil.or(statements, st -> VariableAccessUtils.variableIsUsed(myVariable, st))) return null; PsiExpression mappingExpression = JavaPsiFacade.getElementFactory(condition.getProject()).createExpressionFromText(text, var); result = new TerminalBlock(result, new MapOp(mappingExpression, myVariable, var.getType()), var, statements); } } return result; }