ExtractionUnit (@NotNull PsiStatement thenStmt, @NotNull PsiStatement elseStmt, @NotNull List<PsiLocalVariable> conditionVariables, @NotNull LocalEquivalenceChecker equivalence) { if (!equivalence.topLevelVarsAreEqualNotConsideringInitializers(thenStmt, elseStmt)) return null; PsiLocalVariable thenVariable = extractVariable(thenStmt); PsiLocalVariable elseVariable = extractVariable(elseStmt); if (thenVariable == null || elseVariable == null) return null; PsiExpression thenInitializer = thenVariable.getInitializer(); if (thenInitializer == null) return null; boolean statementMayChangeSemantics = SideEffectChecker.mayHaveSideEffects(thenInitializer, e -> false); boolean mayInfluenceCondition = mayInfluenceCondition(thenInitializer, conditionVariables); boolean equivalent = equivalence.expressionsAreEquivalent(thenInitializer, elseVariable.getInitializer()); return new VariableDeclarationUnit(thenStmt, elseStmt, statementMayChangeSemantics, mayInfluenceCondition, equivalent, thenVariable, elseVariable); }