private void visitSwitch(IASTSwitchStatement statement) throws BadLocationException {
   String hint = statement.getControllerExpression().getRawSignature();
   IASTFileLocation location = statement.getBody().getFileLocation();
   int endLoc = location.getNodeOffset() + location.getNodeLength() - 1;
   int startLoc = statement.getFileLocation().getNodeOffset();
   hint = "switch( " + hint + " )"; // $NON-NLS-1$ //$NON-NLS-2$
   _container.add(new Hint("switch", startLoc, endLoc, hint)); // $NON-NLS-1$
   _scopeStack.push(new ScopeInfo(hint, startLoc, statement));
 }
 public static boolean hasDefaultStatement(IASTSwitchStatement stmt) {
   if (stmt.getBody() == null) {
     return false;
   }
   final Predicate<IASTNode> breakStatement =
       new Predicate<IASTNode>() {
         public boolean apply(IASTNode node) {
           return node instanceof IASTDefaultStatement;
         }
       };
   List<IASTNode> nodes = Arrays.asList(stmt.getBody().getChildren());
   return Iterables.any(nodes, breakStatement);
 }
  public static List<List<IASTNode>> getStatementsGroupedByClause(IASTSwitchStatement switchStmt) {
    List<List<IASTNode>> groups = Lists.newArrayList();

    if (switchStmt.getBody() != null) {
      IASTNode[] nodes = switchStmt.getBody().getChildren();
      List<IASTNode> group = null;
      for (IASTNode astNode : nodes) {
        if (astNode instanceof IASTCaseStatement || astNode instanceof IASTDefaultStatement) {
          // When we meet a Case or default statement we create a new
          // group of statements
          group = Lists.newArrayList();
          groups.add(group);
        }
        group.add(astNode);
      }
    }
    return groups;
  }
예제 #4
0
  private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
    switchIsNew = true;

    scribe.print(SWITCH_BRACKET);
    scribe.noNewLines();
    if (switchStatement instanceof ICPPASTSwitchStatement) {
      ICPPASTSwitchStatement cppSwitchStatement = (ICPPASTSwitchStatement) switchStatement;
      if (cppSwitchStatement.getControllerDeclaration() == null) {
        cppSwitchStatement.getControllerExpression().accept(visitor);
      } else {
        declWriter.writeDeclaration(cppSwitchStatement.getControllerDeclaration(), false);
      }
    } else {
      switchStatement.getControllerExpression().accept(visitor);
    }
    scribe.print(')');
    scribe.newLines();
    nextCompoundNoNewLine();
    writeBodyStatement(switchStatement.getBody(), false);

    switchIsNew = false;
  }