List<ExpressionToConstantReplacementContext> (@NotNull List<ExpressionToConstantComparison> comparisons, @NotNull PsiClass aClass) { Set<String> orig = StreamEx.of(comparisons).map(c -> c.myConstantRepresentation).toSet(); List<ExpressionToConstantReplacementContext> copies = new ArrayList<>(); Set<PsiExpression> processedOperands = new HashSet<>(); aClass.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) { super.visitPolyadicExpression(expression); if (!expression.getOperationTokenType().equals(JavaTokenType.OROR)) return; for (PsiExpression operand : expression.getOperands()) { if (processedOperands.contains(operand)) continue; List<ExpressionToConstantComparison> otherComparisons = comparisons(operand).toList(); otherComparisons.stream().map(c -> c.myComparison).forEach(processedOperands::add); if (otherComparisons.size() == comparisons.size() && otherComparisons.get(0).myExpression != comparisons.get(0).myExpression && otherComparisons.get(0).myType.equals(comparisons.get(0).myType) && StreamEx.of(otherComparisons).map(c -> c.myConstantRepresentation).toSet().equals(orig)) { copies.add(new ExpressionToConstantReplacementContext(otherComparisons)); } } } }); return copies; }