void (@NotNull GrSwitchElement switchElement) { final Set<GrExpression> duplicateExpressions = new HashSet<>(); final GrCaseSection[] sections = switchElement.getCaseSections(); final List<GrExpression> allMatchingExpressions = new ArrayList<>(sections.length); for (final GrCaseSection label : sections) { final GrExpression[] expressions = label.getExpressions(); allMatchingExpressions.addAll(Arrays.asList(expressions)); } for (int i = 0; i < allMatchingExpressions.size(); ++i) { for (int j = i + 1; j < allMatchingExpressions.size(); ++j) { // this has complexity O(n^2). I assume there are not so many matching expressions, // so we may be happy with this straightforward algorithm if (EquivalenceChecker.expressionsAreEquivalent(allMatchingExpressions.get(i), allMatchingExpressions.get(j))) { duplicateExpressions.add(allMatchingExpressions.get(i)); duplicateExpressions.add(allMatchingExpressions.get(j)); } } } for (GrExpression duplicateExpression : duplicateExpressions) { registerError(duplicateExpression); } }