@Override public boolean matches(final INode other, final Match match) { if (other instanceof SwitchSection) { final SwitchSection otherSection = (SwitchSection) other; return !otherSection.isNull() && getCaseLabels().matches(otherSection.getCaseLabels(), match) && getStatements().matches(otherSection.getStatements(), match); } return false; } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof SwitchSection) { final SwitchSection otherSection = (SwitchSection) other; return !otherSection.isNull() && getCaseLabels().matches(otherSection.getCaseLabels(), match) && getStatements().matches(otherSection.getStatements(), match); } return false; } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof SwitchSection) { final SwitchSection otherSection = (SwitchSection) other; return !otherSection.isNull() && getCaseLabels().matches(otherSection.getCaseLabels(), match) && getStatements().matches(otherSection.getStatements(), match); } return false; } }
@Override public AstNode visitSwitchSection(final SwitchSection node, final Void _) { if (node.getStatements().size() != 1) { return super.visitSwitchSection(node, _); } final Statement firstStatement = node.getStatements().firstOrNullObject(); if (firstStatement instanceof BlockStatement) { final BlockStatement block = (BlockStatement) firstStatement; final boolean declaresVariables = any( block.getStatements(), new Predicate<Statement>() { @Override public boolean test(final Statement s) { return s instanceof VariableDeclarationStatement; } } ); if (!declaresVariables) { block.remove(); block.getStatements().moveTo(node.getStatements()); } } return super.visitSwitchSection(node, _); } }
@Override public AstNode visitSwitchSection(final SwitchSection node, final Void _) { if (node.getStatements().size() != 1) { return super.visitSwitchSection(node, _); } final Statement firstStatement = node.getStatements().firstOrNullObject(); if (firstStatement instanceof BlockStatement) { final BlockStatement block = (BlockStatement) firstStatement; final boolean declaresVariables = any( block.getStatements(), new Predicate<Statement>() { @Override public boolean test(final Statement s) { return s instanceof VariableDeclarationStatement; } } ); if (!declaresVariables) { block.remove(); block.getStatements().moveTo(node.getStatements()); } } return super.visitSwitchSection(node, _); } }
@Override public AstNode visitSwitchSection(final SwitchSection node, final Void p) { if (node.getStatements().size() != 1) { return super.visitSwitchSection(node, p); } final Statement firstStatement = node.getStatements().firstOrNullObject(); if (firstStatement instanceof BlockStatement) { final BlockStatement block = (BlockStatement) firstStatement; if (any(ofType(block.getStatements(), VariableDeclarationStatement.class))) { return super.visitSwitchSection(node, p); } block.remove(); block.getStatements().moveTo(node.getStatements()); } return super.visitSwitchSection(node, p); } }
@Override public Void visitSwitchSection(final SwitchSection node, final Void ignored) { startNode(node); boolean first = true; for (final CaseLabel label : node.getCaseLabels()) { if (!first) { newLine(); } label.acceptVisitor(this, ignored); first = false; } final boolean isBlock = node.getStatements().size() == 1 && firstOrDefault(node.getStatements()) instanceof BlockStatement; if (policy.IndentCaseBody && !isBlock) { formatter.indent(); } if (!isBlock) { newLine(); } for (final Statement statement : node.getStatements()) { statement.acceptVisitor(this, ignored); } if (policy.IndentCaseBody && !isBlock) { formatter.unindent(); } endNode(node); return null; }
@Override public Void visitSwitchSection(final SwitchSection node, final Void ignored) { startNode(node); boolean first = true; for (final CaseLabel label : node.getCaseLabels()) { if (!first) { newLine(); } label.acceptVisitor(this, ignored); first = false; } final boolean isBlock = node.getStatements().size() == 1 && firstOrDefault(node.getStatements()) instanceof BlockStatement; if (policy.IndentCaseBody && !isBlock) { formatter.indent(); } if (!isBlock) { newLine(); } for (final Statement statement : node.getStatements()) { statement.acceptVisitor(this, ignored); } if (policy.IndentCaseBody && !isBlock) { formatter.unindent(); } endNode(node); return null; }
@Override public Void visitSwitchSection(final SwitchSection node, final Void ignored) { startNode(node); boolean first = true; for (final CaseLabel label : node.getCaseLabels()) { if (!first) { newLine(); } label.acceptVisitor(this, ignored); first = false; } final boolean isBlock = node.getStatements().size() == 1 && firstOrDefault(node.getStatements()) instanceof BlockStatement; if (policy.IndentCaseBody && !isBlock) { formatter.indent(); } if (!isBlock) { newLine(); } for (final Statement statement : node.getStatements()) { statement.acceptVisitor(this, ignored); } if (policy.IndentCaseBody && !isBlock) { formatter.unindent(); } endNode(node); return null; }
handleStatementList(section.getStatements(), data); handleStatementList(section.getStatements(), null);
handleStatementList(section.getStatements(), data); handleStatementList(section.getStatements(), null);
handleStatementList(section.getStatements(), data); handleStatementList(section.getStatements(), null);
final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject());
final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject());
final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject()); defaultSection.getStatements().add(defaultBreak);
final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject()); defaultSection.getStatements().add(defaultBreak);
final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject()); defaultSection.getStatements().add(defaultBreak);
section.getStatements().add(transformBlock(caseBlock)); switchStatement.getSwitchSections().add(section);
section.getStatements().add(transformBlock(caseBlock)); switchStatement.getSwitchSections().add(section);
section.getStatements().add(transformBlock(caseBlock)); switchStatement.getSwitchSections().add(section);