}
}
@Check
public void checkCaseExpression(CaseExpression o) {
final Expression switchExpr = o.getSwitchExpr();
boolean theDefaultIsSeen = false;
// collect unreachable entries to avoid multiple unreachable markers for an entry
Set<Integer> unreachables = Sets.newHashSet();
Set<Integer> duplicates = Sets.newHashSet();
List<Expression> caseExpressions = Lists.newArrayList();
for(Case caze : o.getCases()) {
for(Expression e : caze.getValues()) {
caseExpressions.add(e);
if(e instanceof LiteralDefault)
theDefaultIsSeen = true;
}
}
// if a default is seen it should (optionally) appear last
if(theDefaultIsSeen) {
IValidationAdvisor advisor = advisor();
ValidationPreference shouldBeLast = advisor.caseDefaultShouldAppearLast();
if(shouldBeLast.isWarningOrError()) {
int last = caseExpressions.size() - 1;
for(int i = 0; i < last; i++)
if(caseExpressions.get(i) instanceof LiteralDefault)
acceptor.accept(
severity(shouldBeLast), "A 'default' should appear last", caseExpressions.get(i),
IPPDiagnostics.ISSUE__DEFAULT_NOT_LAST);
}
}
// Check duplicate by equivalence (mark as duplicate)
// Check equality to switch expression (mark all others as unreachable),
for(int i = 0; i < caseExpressions.size(); i++) {
Expression e1 = caseExpressions.get(i);
// if a case value is equivalent to the switch expression, all other are unreachable
if(eqCalculator.isEquivalent(e1, switchExpr))
for(int u = 0; u < caseExpressions.size(); u++)
if(u != i)