@Override public Boolean visitSwitch(SwitchTree tree, Void unused) { // (1) if (tree.getCases().stream().allMatch(c -> c.getStatements().isEmpty())) { return true; } // (2) boolean lastCompletes = true; for (CaseTree c : tree.getCases()) { lastCompletes = scan(c.getStatements()); } if (lastCompletes) { return true; } // (3) if (getLast(tree.getCases()).getStatements().isEmpty()) { return true; } // (4) if (tree.getCases().stream().noneMatch(c -> c.getExpression() == null)) { return true; } // (5) if (breaks.contains(tree)) { return true; } return false; }
@Override public Description matchSwitch(SwitchTree tree, VisitorState state) { Type switchType = ASTHelpers.getType(tree.getExpression()); if (switchType.asElement().getKind() != ElementKind.ENUM) { return Description.NO_MATCH; } // default case is present if (tree.getCases().stream().anyMatch(c -> c.getExpression() == null)) { return Description.NO_MATCH; } ImmutableSet<String> handled = tree.getCases().stream() .map(CaseTree::getExpression) .filter(IdentifierTree.class::isInstance) .map(e -> ((IdentifierTree) e).getName().toString()) .collect(toImmutableSet()); Set<String> unhandled = Sets.difference(ASTHelpers.enumValues(switchType.asElement()), handled); if (unhandled.isEmpty()) { return Description.NO_MATCH; } return buildDescription(tree).setMessage(buildMessage(unhandled)).build(); }
@Override public Description matchSwitch(SwitchTree tree, VisitorState state) { Optional<? extends CaseTree> maybeDefault = tree.getCases().stream().filter(c -> c.getExpression() == null).findAny(); if (!maybeDefault.isPresent()) { return NO_MATCH; CaseTree caseTree = it.next(); defaultStatementGroup.add(caseTree); if (caseTree.getExpression() == null) { while (it.hasNext() && caseTree.getStatements().isEmpty()) { caseTree = it.next(); if (last.getExpression() == null || Reachability.canCompleteNormally(last)) { replacement = "break;\n" + replacement;
@Override public Choice<State<JCCase>> visitCase(final CaseTree node, State<?> state) { return chooseSubtrees( state, s -> unifyStatements(node.getStatements(), s), stmts -> maker().Case((JCExpression) node.getExpression(), stmts)); }
@Override public Void visitIdentifier(IdentifierTree tree, Void unused) { Symbol sym = ASTHelpers.getSymbol(tree); if (sym == null) { return null; } Tree parent = getCurrentPath().getParentPath().getLeaf(); if (parent.getKind() == Tree.Kind.CASE && ((CaseTree) parent).getExpression().equals(tree) && sym.owner.getKind() == ElementKind.ENUM) { // switch cases can refer to enum constants by simple name without importing them return null; } if (sym.owner.equals(owner) && unit.starImportScope.includes(sym)) { fix.prefixWith(tree, owner.getSimpleName() + "."); } return null; } }.scan(unit, null);
tree.getCases().stream().filter(c -> c.getExpression() == null).findFirst(); if (!maybeDefault.isPresent()) { Description.Builder description = buildDescription(tree);
@Override public Result visitSwitch(SwitchTree node, BreakContext cxt) { Result result = null; boolean seenDefault = false; cxt.loopDepth++; try { for (CaseTree caseTree : node.getCases()) { if (caseTree.getExpression() == null) { seenDefault = true; } if (result == null) { result = caseTree.accept(this, cxt); } else { result = result.or(caseTree.accept(this, cxt)); } } if (!seenDefault) { result = result.or(NEVER_EXITS); } return result; } finally { cxt.loopDepth--; } }
CaseTree defaultCase = null; for (CaseTree caseTree : tree.getCases()) { if (caseTree.getExpression() == null) { defaultCase = caseTree; break;
@Override public Void visitCase(CaseTree tree, EnumSet<UseTypes> p) { if (tree.getExpression() != null && tree.getExpression().getKind() == Kind.IDENTIFIER) { handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getExpression()), EnumSet.of(UseTypes.READ)); } return super.visitCase(tree, null); }
@Override public Void visitCase(CaseTree expected, Tree actual) { Optional<CaseTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getExpression(), other.get().getExpression()); parallelScan(expected.getStatements(), other.get().getStatements()); return null; }
@Override public Void visitCase(CaseTree expected, Tree actual) { Optional<CaseTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getExpression(), other.get().getExpression()); parallelScan(expected.getStatements(), other.get().getStatements()); return null; }
@Override public Void visitCase(CaseTree expected, Tree actual) { Optional<CaseTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getExpression(), other.get().getExpression()); parallelScan(expected.getStatements(), other.get().getStatements()); return null; }
public Boolean visitCase(CaseTree node, TreePath p) { if (p == null) { super.visitCase(node, p); return false; } CaseTree ct = (CaseTree) p.getLeaf(); if (!scan(node.getExpression(), ct.getExpression(), p)) return false; return checkLists(node.getStatements(), ct.getStatements(), p); }
public R visitCase(CaseTree node, P p) { R r = scan(node.getExpression(), p); r = scanAndReduce(node.getStatements(), p, r); return r; }
private CaseTree modifyCaseStatement(CaseTree kejs, int index, StatementTree statement, Operation op) { CaseTree copy = Case( kejs.getExpression(), c(kejs.getStatements(), index, statement, op) ); return copy; }
public R visitCase(CaseTree node, P p) { R r = scan(node.getExpression(), p); r = scanAndReduce(node.getStatements(), p, r); return r; }
@Override public List<Tree> visitCase(CaseTree node, ExpressionScanner.ExpressionsInfo p) { List<Tree> result = scan(node.getExpression(), p); result = reduce(result, scan(node.getStatements(), p)); return result; }
public List<Tree> visitCase(CaseTree node, ExpressionScanner.ExpressionsInfo p) { List<Tree> result = scan(node.getExpression(), p); result = reduce(result, scan(node.getStatements(), p)); return result; }
@Override public Choice<State<JCCase>> visitCase(final CaseTree node, State<?> state) { return chooseSubtrees( state, s -> unifyStatements(node.getStatements(), s), stmts -> maker().Case((JCExpression) node.getExpression(), stmts)); }
@Override public Tree visitCase(CaseTree tree, Void p) { CaseTree n = make.Case(tree.getExpression(), tree.getStatements()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }