@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); } }