@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; } }
public final AstNodeCollection<CaseLabel> getCaseLabels() { return getChildrenByRole(CaseLabelRole); }
final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels(); final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject()); final IfElseStatement test = first(m.<IfElseStatement>get("test")); final List<PrimitiveExpression> stringValues = toList(m.<PrimitiveExpression>get("stringValue")); final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels(); final SwitchSection defaultSection = new SwitchSection(); defaultSection.getCaseLabels().add(new CaseLabel()); defaultSection.getStatements().add(defaultBreak);
@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; }
final SwitchSection fallThroughSection = (SwitchSection) fallThroughBlock.getParent(); if (fallThroughSection.getNextSibling() != targetSection) { fallThroughSection.remove(); parentSwitch.getSwitchSections().insertBefore(targetSection, fallThroughSection);
@Override public boolean test(final SwitchSection s) { return !s.getCaseLabels().isEmpty() && all( s.getCaseLabels(), new Predicate<CaseLabel>() { @Override public boolean test(final CaseLabel c) { return c.getExpression().isNull() || (c.getExpression() instanceof PrimitiveExpression && ((PrimitiveExpression) c.getExpression()).getValue() instanceof Integer && tableInputMap.containsKey(((PrimitiveExpression) c.getExpression()).getValue())); } } ); } }
@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 Void visitSwitchStatement(final SwitchStatement node, final Void ignored) { startNode(node); writeKeyword(SwitchStatement.SWITCH_KEYWORD_ROLE); space(policy.SpaceBeforeSwitchParentheses); leftParenthesis(); space(policy.SpacesWithinSwitchParentheses); node.getExpression().acceptVisitor(this, ignored); space(policy.SpacesWithinSwitchParentheses); rightParenthesis(); openBrace(policy.StatementBraceStyle); if (policy.IndentSwitchBody) { formatter.indent(); } for (final SwitchSection section : node.getSwitchSections()) { section.acceptVisitor(this, ignored); } if (policy.IndentSwitchBody) { formatter.unindent(); } closeBrace(policy.StatementBraceStyle); newLine(); endNode(node); return null; }
final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels(); final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject()); final IfElseStatement test = first(m.<IfElseStatement>get("test")); final List<PrimitiveExpression> stringValues = toList(m.<PrimitiveExpression>get("stringValue")); final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels(); final SwitchSection defaultSection = new SwitchSection(); defaultSection.getCaseLabels().add(new CaseLabel()); defaultSection.getStatements().add(defaultBreak);
@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; }
final SwitchSection fallThroughSection = (SwitchSection) fallThroughBlock.getParent(); if (fallThroughSection.getNextSibling() != targetSection) { fallThroughSection.remove(); parentSwitch.getSwitchSections().insertBefore(targetSection, fallThroughSection);
@Override public boolean test(final SwitchSection s) { return !s.getCaseLabels().isEmpty() && all( s.getCaseLabels(), new Predicate<CaseLabel>() { @Override public boolean test(final CaseLabel c) { return c.getExpression().isNull() || (c.getExpression() instanceof PrimitiveExpression && ((PrimitiveExpression) c.getExpression()).getValue() instanceof Integer && tableInputMap.containsKey(((PrimitiveExpression) c.getExpression()).getValue())); } } ); } }
@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 Void visitSwitchStatement(final SwitchStatement node, final Void ignored) { startNode(node); writeKeyword(SwitchStatement.SWITCH_KEYWORD_ROLE); space(policy.SpaceBeforeSwitchParentheses); leftParenthesis(); space(policy.SpacesWithinSwitchParentheses); node.getExpression().acceptVisitor(this, ignored); space(policy.SpacesWithinSwitchParentheses); rightParenthesis(); openBrace(policy.StatementBraceStyle); if (policy.IndentSwitchBody) { formatter.indent(); } for (final SwitchSection section : node.getSwitchSections()) { section.acceptVisitor(this, ignored); } if (policy.IndentSwitchBody) { formatter.unindent(); } closeBrace(policy.StatementBraceStyle); newLine(); endNode(node); return null; }
final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels(); final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject()); final IfElseStatement test = first(m.<IfElseStatement>get("test")); final List<PrimitiveExpression> stringValues = toList(m.<PrimitiveExpression>get("stringValue")); final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels(); final SwitchSection defaultSection = new SwitchSection(); defaultSection.getCaseLabels().add(new CaseLabel()); defaultSection.getStatements().add(defaultBreak);
@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 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; } }
final SwitchSection fallThroughSection = (SwitchSection) fallThroughBlock.getParent(); if (fallThroughSection.getNextSibling() != targetSection) { fallThroughSection.remove(); parentSwitch.getSwitchSections().insertBefore(targetSection, fallThroughSection);
@Override public boolean test(final SwitchSection s) { return !s.getCaseLabels().isEmpty() && all( s.getCaseLabels(), new Predicate<CaseLabel>() { @Override public boolean test(final CaseLabel c) { return c.getExpression().isNull() || (c.getExpression() instanceof PrimitiveExpression && ((PrimitiveExpression) c.getExpression()).getValue() instanceof Integer && tableInputMap.containsKey(((PrimitiveExpression) c.getExpression()).getValue())); } } ); } }
public final AstNodeCollection<Statement> getStatements() { return getChildrenByRole(Roles.EMBEDDED_STATEMENT); }