Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    *
    * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
    *
    * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    * Other names may be trademarks of their respective owners.
    *
    * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common
   * Development and Distribution License("CDDL") (collectively, the
   * "License"). You may not use this file except in compliance with the
   * License. You can obtain a copy of the License at
   * http://www.netbeans.org/cddl-gplv2.html
   * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   * specific language governing permissions and limitations under the
   * License.  When distributing the software, include this License Header
   * Notice in each file and include the License file at
   * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Oracle in the GPL Version 2 section of the License file that
   * accompanied this code. If applicable, add the following below the
   * License Header, with the fields enclosed by brackets [] replaced by
   * your own identifying information:
   * "Portions Copyrighted [year] [name of copyright owner]"
   * 
   * If you wish your version of this file to be governed by only the CDDL
   * or only the GPL Version 2, indicate your decision by adding
   * "[Contributor] elects to include this software in this distribution
   * under the [CDDL or GPL Version 2] license." If you do not indicate a
   * single choice of license, a recipient has the option to distribute
   * your version of this file under either the CDDL, the GPL Version 2 or
   * to extend the choice of license to its licensees as provided above.
   * However, if you add GPL Version 2 code and therefore, elected the GPL
   * Version 2 license, then the option applies only if the new code is
   * made subject to such option by the copyright holder.
   * 
   * Contributor(s):
   * 
   * Portions Copyrighted 2008 Sun Microsystems, Inc.
   */
  
  package org.netbeans.modules.cnd.editor.reformat;
  
  import static org.netbeans.cnd.api.lexer.CppTokenId.*;

Author(s):
Alexander Simon
  
  public class ReformatterImpl {
      /*package local*/ final ContextDetector ts;
      /*package local*/ final CodeStyle codeStyle;
      /*package local*/ final DiffLinkedList diffs = new DiffLinkedList();
      /*package local*/ final BracesStack braces;
      private final int startOffset;
      private final int endOffset;
      private int tabSize;
      private QtExtension qtExtension = new QtExtension();
      
      ReformatterImpl(TokenSequence<CppTokenIdtsint startOffsetint endOffsetCodeStyle codeStyle){
           = new BracesStack(codeStyle);
           = codeStyle.getTabSize();
          if ( <= 1) {
               = 8;
          }
          this. = new ContextDetector(ts);
          this. = startOffset;
          this. = endOffset;
          this. = codeStyle;
           = new PreprocessorFormatter(this);
      }
      
      LinkedList<Diffreformat(){
          .moveStart();
          Token<CppTokenIdprevious = .lookPrevious();
          while(.moveNext()){
              if (.offset() > ) {
                  break;
              }
              //System.out.println("========"+previous+"==========");
              //System.out.println(ts);
              Token<CppTokenIdcurrent = .token();
              CppTokenId id = current.id();
              if (previous != null && previous.id() ==  && id != ){
                  // indent afre preprocessor directive
                 if (.getStatementContinuation() == ..){
                     if (.isStatementContinuation()){
                         .setStatementContinuation(..);
                     }
                 }
                 if (doFormat()){
                     indentNewLine(current);
                 }
             }
             switch(id){
                 case //(null, "preprocessor"),
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                 case :
                     break;
                 case :
                     if (.isQtObject() && 
                        (.isSignals(current) || .isSlots(current))) {
                         break;
                     }
                     .setLastStatementStart();
                     break;
                 default:
                     .setLastStatementStart();
             }
             switch(id){
                 case //(null, "preprocessor"),
                 {
                     .indentPreprocessor(previous);
                     break;
                 }
                 case :
                 {
                     if (.getStatementContinuation() == ..){
                         if (.isStatementContinuation()){
                             .setStatementContinuation(..);
                         }
                     }
                     if (doFormat()) {
                         newLineFormat(previouscurrent.);
                     }
                     break;
                 }
                 case :
                 {
                     if (doFormat()) {
                         whiteSpaceFormat(previouscurrent);
                     }
                     break;
                 }
                 case :
                 case :
                 {
                     if (doFormat()) {
                         reformatBlockComment(previouscurrent);
                     }
                     break;
                 }
                 case //("{", "separator"),
                 {
                     int start = .;
                     .push();
                     if (doFormat()) {
                         braceFormat(previouscurrent);
 
                         StackEntry entry = .peek();
                         if (entry.getImportantKind() ==  ||
                             entry.getImportantKind() ==  ||    
                             entry.getImportantKind() ==  ||    
                             entry.getImportantKind() == ) {
                             // add new lines before class declaration
                             newLinesBeforeDeclaration(.blankLinesBeforeClass(), start);
                         } else if (entry.getImportantKind() == ){
                             // TODO blank lines before namespace
                         } else if (entry.isLikeToFunction()) {
                             // add new lines before method declaration
                             newLinesBeforeDeclaration(.blankLinesBeforeMethods(), start);
                         } else if (entry.isLikeToArrayInitialization()) {
                             // no action
                         } else {
                             Token<CppTokenIdprevImportant = .lookPreviousImportant();
                             if (prevImportant != null &&
                                 prevImportant.id() ==  &&
                                 .getLength() == 1) {
                                 // TODO detect K&R style.
                                 entry.setLikeToFunction(true);
                                 newLinesBeforeDeclaration(.blankLinesBeforeMethods(), .);
                             }
                         }
                     }
                     . = -1;
                     break;
                 }
                 case //("(", "separator"),
                 {
                     if (. == 0) {
                         if (.getStatementContinuation() == ..) {
                             .setStatementContinuation(..);
                         }
                         if (.getLength() == 0){
                             // save K&R start
                             . = .;
                         }
                         if (. >= 0) {
                             . = .index();
                         }
                     }
                     .++;
                     if (doFormat()) {
                         formatLeftParen(previouscurrent);
                     }
                     break;
                 }
                 case //(")", "separator"),
                 {
                     .--;
                     if (. < 0){
                         // unbalanced paren
                         . = 0;
                     }
                     if (. == 0) {
                         StackEntry entry = .peek();
                         if (entry == null || entry.getKind() !=  ||
                             entry.getImportantKind() ==  || entry.getImportantKind() ==  || entry.getImportantKind() == ){
                             Token<CppTokenIdnext = .lookNextImportant();
                             if (next != null && next.id() == ) {
                                 .setStatementContinuation(..);
                             } else {
                                 if (.getStatementContinuation() != ..) {
                                     .setStatementContinuation(..);
                                 }
                             }
                         }
                         if (. >= 0) {
                             . = -1;
                         }
                     }
                     if (doFormat()) {
                         formatRightParen(previouscurrent);
                     }
                     break;
                 }
                 case :
                 {
                     boolean isStart = false;
                     .checkQtObject(current);
                     Token<CppTokenIdnext = .lookNextImportant();
                     if (next != null && next.id() == ) {
                         if (.isQtObject() && .isSlots(current)) {
                             Token<CppTokenIdprev = .lookPreviousImportant();
                             if (.isFirstLineToken() && prev != null &&
                                (prev.id() ==  || prev.id() ==  || prev.id() == )) {
                                 StackEntry entry = .peek();
                                 if (doFormat()) {
                                     if (entry != null && entry.getImportantKind() != null){
                                         switch (entry.getImportantKind()) {
                                             case //("class", "keyword"), //C++
                                             case //("struct", "keyword"),
                                                 removeLineBefore(true);
                                         }
                                     }
                                 }
                             }
                             break;
                         } else if (.isQtObject() && .isSignals(current)) {
                             StackEntry entry = .peek();
                             if (doFormat()) {
                                 if (entry != null && entry.getImportantKind() != null){
                                     switch (entry.getImportantKind()) {
                                         case //("class", "keyword"), //C++
                                         case //("struct", "keyword"),
                                             newLineBefore(.);
                                     }
                                 }
                             }
                             break;
                         }
                     }
                     if (.getStatementContinuation() == ..) {
                         .setStatementContinuation(..);
                         isStart = .index() == .;
                     }
                     if (isStart) {
                         if (next != null && next.id() == ) {
                             indentLabel(previous);
                         }
                     }
                     break;
                 }
                 case //(";", "separator"),
                 {
                     StackEntry entry = .peek();
                     if (. == 0) {
                         .pop();
                     }
                     if (entry != null && 
                        ((entry.getKind() ==  || entry.getImportantKind() == )) && entry.getKind() != ) {
                         Token<CppTokenIdnext = .lookNextImportant();
                         if (next != null && next.id() == ) {
                             . = true;
                         }
                     }
                     if (doFormat()) {
                         spaceBefore(previous.spaceBeforeSemi(), .spaceKeepExtra());
                         if (. == 0) {
                             if (addNewLineAfterSemocolon(current)){
                                 break;
                             }
                         }
                         spaceAfter(current.spaceAfterSemi(), .spaceKeepExtra());
                     }
                     if (. == 0) {
                         .setStatementContinuation(..);
                     }
                     break;
                 }
                 case //(",", "separator"),
                 {
                     if (doFormat()) {
                         spaceBefore(previous.spaceBeforeComma(), .spaceKeepExtra());
                         spaceAfter(current.spaceAfterComma(), .spaceKeepExtra());
                     }
                     break;
                 }
                 case :
                 case :
                 case :
                 {
                     StackEntry entry = .peek();
                     if (doFormat()) {
                         if (entry != null && entry.getImportantKind() != null){
                             switch (entry.getImportantKind()) {
                                 case //("class", "keyword"), //C++
                                 case //("struct", "keyword"),
                                     Token<CppTokenIdnext = .lookNextImportant();
                                     if (next != null && next.id() == ) {
                                         if (.indentVisibility() == .) {
                                             newLineBefore(.);
                                         } else {
                                             newLineBefore(.);
                                         }
                                     } else if (next != null && next.id() ==  &&
                                                .isQtObject() && .isSlots(next)) {
                                         next = .lookNextImportant(2);
                                         if (next != null && next.id() == ) {
                                             if (.indentVisibility() == .) {
                                                 newLineBefore(.);
                                             } else {
                                                 newLineBefore(.);
                                             }
                                         }
                                     }
                                     break;
                             }
                         }
                     }
                     break;
                 }
                 case //(":", "operator"),
                     processColumn(previouscurrent);
                     break;
                 case //("}", "separator"),
                 {
                     StackEntry entry = .peek();
                     StackEntry statementEntry = null;
                     if (entry != null) {
                         if (entry.getKind() ==  || entry.getImportantKind() == ) {
                             Token<CppTokenIdnext = .lookNextImportant();
                             if (next != null && next.id() == ) {
                                 . = true;
                             }
                         } else if (entry.getImportantKind() ==  || entry.getImportantKind() == ) {
                             statementEntry = .lookPerevious();
                         }
                     }
                     .pop();
                     if (doFormat()) {
                         indentRbrace(entrypreviouscurrentstatementEntry);
                     }
                     break;
                 }
                 case //("?", "operator"),
                 {
                     if (doFormat()) {
                         spaceBefore(previous.spaceAroundTernaryOps(), .spaceKeepExtra());
                         spaceAfter(current.spaceAroundTernaryOps(), .spaceKeepExtra());
                     }
                     break;
                 }
                 case //("!", "operator"),
                 case //("~", "operator"),
                 {
                     if (doFormat()) {
                         if (isOperator()) {
                             spaceBefore(previousfalsefalse);
                             spaceAfter(current.spaceBeforeMethodDeclParen(), .spaceKeepExtra());
                         } else {
                             spaceAfter(current.spaceAroundUnaryOps(), .spaceKeepExtra());
                         }
                     }
                     break;
                 }
                 case //("++", "operator"),
                 case //("--","operator"),
                 {
                     if (doFormat()) {
                         if (isOperator()) {
                             spaceBefore(previousfalsefalse);
                             spaceAfter(current.spaceBeforeMethodDeclParen(), .spaceKeepExtra());
                         } else {
                             if (.isPrefixOperator(current)){
                                 spaceAfter(current.spaceAroundUnaryOps(), .spaceKeepExtra());
                             } else if (.isPostfixOperator(current)){
                                 spaceBefore(previous.spaceAroundUnaryOps(), .spaceKeepExtra());
                             }
                         }
                     }
                     break;
                 }
                 case //("+", "operator"),
                 case //("-", "operator"),
                 {
                     if (doFormat()) {
                         if (isOperator()) {
                             spaceBefore(previousfalsefalse);
                             spaceAfter(current.spaceBeforeMethodDeclParen(), .spaceKeepExtra());
                         } else {
                             OperatorKind kind = .getOperatorKind(current);
                             if (kind == .){
                                 spaceBefore(previous.spaceAroundBinaryOps(), .spaceKeepExtra());
                                 spaceAfter(current.spaceAroundBinaryOps(), .spaceKeepExtra());
                             } else if (kind == .){
                                 spaceAfter(current.spaceAroundUnaryOps(), .spaceKeepExtra());
                             }
                         }
                     }
                     break;
                 }
                 case //("*", "operator"),
                 case //("&", "operator"),
                 {
                     if (doFormat()) {
                         if (isOperator()) {
                             spaceBefore(previousfalsefalse);
                             spaceAfter(current.spaceBeforeMethodDeclParen(), .spaceKeepExtra());
                         } else {
                             OperatorKind kind = .getOperatorKind(current);
                             if (kind == .){
                                 spaceBefore(previous.spaceAroundBinaryOps(), .spaceKeepExtra());
                                 spaceAfter(current.spaceAroundBinaryOps(), .spaceKeepExtra());
                             } else if (kind == .){
                                 spaceAfter(current.spaceAroundUnaryOps(), .spaceKeepExtra());
                             } else if (kind == .){
                                 //TODO style of type declaration
                             }
                         }
                     }
                     break;
                 }
                 case //(">", "operator"),
                 case //("<", "operator"),
                 {
                     if (doFormat()) {
                         if (isOperator()) {
                             spaceBefore(previousfalse.spaceKeepExtra());
                             spaceAfter(current.spaceBeforeMethodDeclParen(), .spaceKeepExtra());
                         } else if (isNewStyleCast(current)){
                             if (current.id()==) {
                                 spaceAfter(current.spaceWithinTypeCastParens(), .spaceKeepExtra());
                             } else {
                                 spaceBefore(previous.spaceWithinTypeCastParens(), .spaceKeepExtra());
                                 spaceAfter(current.spaceAfterTypeCast(), .spaceKeepExtra());
                             }
                         } else {
                             OperatorKind kind = .getOperatorKind(current);
                             if (kind == .){
                                 spaceBefore(previous.spaceAroundBinaryOps(), .spaceKeepExtra());
                                 spaceAfter(current.spaceAroundBinaryOps(), .spaceKeepExtra());
                             } else if (kind == .){
                                 //TODO style of template declaration
                             }
                         }
                     }
                     break;
                 }
                 case //("==", "operator"),
                 case //("<=", "operator"),
                 case //(">=", "operator"),
                 case //("!=","operator"),
                 case //("&&", "operator"),
                 case //("||", "operator"),
                 case //("/", "operator"),
                 case //("|", "operator"),
                 case //("%", "operator"),
                 case //("<<", "operator"),
                 case //(">>", "operator"),
                 {
                     if (doFormat()) {
                         if (isOperator()) {
                             spaceBefore(previousfalsefalse);
                             spaceAfter(current.spaceBeforeMethodDeclParen(), .spaceKeepExtra());
                         } else {
                             spaceBefore(previous.spaceAroundBinaryOps(), .spaceKeepExtra());
                             spaceAfter(current.spaceAroundBinaryOps(), .spaceKeepExtra());
                         }
                     }
                     break;
                 }
                 case //("=", "operator"),
                 case //("+=", "operator"),
                 case //("-=", "operator"),
                 case //("*=", "operator"),
                 case //("/=", "operator"),
                 case //("&=", "operator"),
                 case //("|=", "operator"),
                 case //("^=", "operator"),
                 case //("%=", "operator"),
                 case //("<<=", "operator"),
                 case //(">>=", "operator"),
                 {
                     if (.getStatementContinuation() == ..) {
                         .setStatementContinuation(..);
                     }
                     if (doFormat()) {
                         if (!isOperator()) {
                             spaceBefore(previous.spaceAroundAssignOps(), .spaceKeepExtra());
                             spaceAfter(current.spaceAroundAssignOps(), .spaceKeepExtra());
                         } else {
                             spaceBefore(previousfalsefalse);
                             spaceAfter(current.spaceBeforeMethodDeclParen(), .spaceKeepExtra());
                         }
                     }
                     if (.getStatementContinuation() == ..){
                         .setStatementContinuation(..);
                     }
                     break;
                 }
                 case //("namespace", "keyword"), //C++
                 case //("class", "keyword"), //C++
                 case //("struct", "keyword"),
                 case //("enum", "keyword"),
                 case //("union", "keyword"),
                 {
                     break;
                 }
                 case //("if", "keyword-directive"),
                 {
                     .push();
                     . = .index();
                     if (doFormat()) {
                         spaceAfterBefore(current.spaceBeforeIfParen(), .spaceKeepExtra());
                     }
                     break;
                 }
                 case //("else", "keyword-directive"),
                 {
                     .push();
                     if (doFormat()) {
                        formatElse(previous);
                     }
                     break;
                 }
                 case //("while", "keyword-directive"),
                 {
                     .push();
                     . = .index();
                     if (doFormat()) {
                         boolean doSpaceBefore = true;
 
                         if (.) {
                             if (.isFirstLineToken()) {
                                 if (!.newLineWhile()) {
                                     // try to remove new line
                                     newLine(previouscurrent..,
                                             .spaceBeforeWhile(), 0);
                                     doSpaceBefore = false;
                                 }
                             } else {
                                 if (.newLineWhile()) {
                                     // add new line
                                     newLine(previouscurrent..,
                                             .spaceBeforeWhile(), 0);
                                     doSpaceBefore = false;
                                 }
                             }
                         }
                         if (doSpaceBefore){
                             spaceBefore(previous.spaceBeforeWhile(), .spaceKeepExtra());
                         }
                         spaceAfterBefore(current.spaceBeforeWhileParen(), .spaceKeepExtra());
                     }
                     . = false;
                     break;
                 }
                 case //("for", "keyword-directive"),
                 {
                     .push();
                     . = .index();
                     if (doFormat()) {
                         spaceAfterBefore(current.spaceBeforeForParen(), .spaceKeepExtra());
                     }
                     break;
                 }
                 case //("try", "keyword-directive"), // C++
                 {
                     .push();
                     if (doFormat()) {
                         // TODO need UI?
                         spaceBefore(previoustruefalse);
                     }
                     break;
                 }
                 case //("catch", "keyword-directive"), //C++
                 {
                     .push();
                     . = .index();
                     if (doFormat()) {
                         boolean doSpaceBefore = true;
                         if (.isFirstLineToken()) {
                             if (!.newLineCatch()){
                                 // try to remove new line
                                 newLine(previouscurrent..,
                                         .spaceBeforeCatch(), 0);
                                 doSpaceBefore = false;
                             }
                         } else {
                              if (.newLineCatch()){
                                 // add new line
                                 newLine(previouscurrent..,
                                         .spaceBeforeCatch(), 0);
                                 doSpaceBefore = false;
                             }
                        }
                        if (doSpaceBefore){
                           spaceBefore(previous.spaceBeforeCatch(), .spaceKeepExtra());
                        }
                        spaceAfterBefore(current.spaceBeforeCatchParen(), .spaceKeepExtra());
                     }
                     break;
                 }
                 case //("asm", "keyword-directive"), // gcc and C++
                 {
                     .push();
                     break;
                 }
                 case //("do", "keyword-directive"),
                 {
                     .push();
                     break;
                 }
                 case //("switch", "keyword-directive"),
                 {
                     .push();
                     . = .index();
                     if (doFormat()) {
                         spaceAfterBefore(current.spaceBeforeSwitchParen(), .spaceKeepExtra());
                     }
                     break;
                 }
                 case //("default", "keyword-directive"),
                 case //("case", "keyword-directive"),
                 {
                     .setStatementContinuation(..);
                     break;
                 }
                 case //("break", "keyword-directive"),
                 {
                     break;
                 }
                 case //("continue", "keyword-directive"),
                 {
                     break;
                 }
                 case :
                 {
                     if (doFormat()) {
                         Token<CppTokenIdp = .lookPreviousImportant(1);
                         if (p != null && p.id() == ) {
                             spaceBefore(previousfalsefalse);
                         }
                         spaceAfter(currentfalsefalse);
                     }
                     break;
                 }
                 case :
                 case :
                 case :
                 case :
                 {
                     if (doFormat()) {
                         spaceAfter(current.spaceWithinTypeCastParens(), .spaceKeepExtra());
                     }
                     break;
                 }
             }
             previous = current;
         }
         //System.out.println("Reformatter have prepared "+diffs.getStorage().size()+" diffs");
         return .getStorage();
     }
     
     /*package local*/ int getParentIndent() {
         return continuationIndent(.getSelfIndent());
     }
 
     /*package local*/ int getCaseIndent() {
             if (.indentCasesFromSwitch()) {
                 return getParentIndent() + .indentSize()/2;
             } else {
                 return getParentIndent();
             }
         } else {
             if (.indentCasesFromSwitch()) {
                 return getParentIndent() + .indentSize();
             } else {
                 return getParentIndent();
             }
         }
     }
 
     /*package local*/ int getIndent() {
         return continuationIndent(.getIndent());
     }
 
     /*package local*/ int continuationIndent(int shift){
         StackEntry entry = .peek();
         if (entry != null) {
                 switch (entry.getKind()){
                     case //("namespace", "keyword"), //C++
                     case //("class", "keyword"), //C++
                     case //("struct", "keyword"),
                     case //("enum", "keyword"),
                     case //("union", "keyword"),
                         break;
                     case 
                         if (.getFormatNewLineBeforeBraceSwitch() == .){
                             shift += .getFormatStatementContinuationIndent() - .indentSize()/2;
                         } else {
                             shift += .getFormatStatementContinuationIndent() - .indentSize();
                         }
                         break;
                     case 
                     case 
                     case 
                     case 
                     case 
                     case 
                         if (.getFormatNewlineBeforeBrace() == .){
                             shift += .getFormatStatementContinuationIndent() - .indentSize()/2;
                         } else {
                             shift += .getFormatStatementContinuationIndent() - .indentSize();
                         }
                         break;
                     default:
                     {
                         if (entry.getKind() == ) {
                             if (entry.getImportantKind() != null &&
                                 entry.getImportantKind() == ) {
                                 break;
                             }
                         }
                         if (entry.isLikeToArrayInitialization()){
                             break;
                         }
                         StatementKind kind = .getLastStatementKind();
                         if (kind == null || 
                             !(kind == . ||
                               kind == . && . == 0)) {
                             shift += .getFormatStatementContinuationIndent();
                         }
                         break;
                     }
                 }
             } else if (.getStatementContinuation() == ..){
                 if (entry.getKind() == ) {
                     if (entry.getImportantKind() != null &&
                         (entry.getImportantKind() ==  || entry.getImportantKind() == )) {
                         shift += .getConstructorInitializerListContinuationIndent();
                     }
                 }
             }
         } else {
                 StatementKind kind = .getLastStatementKind();
                 
                 if (kind == null || 
                     !(kind == . ||
                       kind == . && . == 0)) {
                     shift += .getFormatStatementContinuationIndent();
                 }
             } else if (.getStatementContinuation() == ..){
                 shift += .getConstructorInitializerListContinuationIndent();
             }
         }
         if (shift > 0) {
             return shift;
         } else {
             return 0;
         }
     }
     
     private boolean addNewLineAfterSemocolon(Token<CppTokenIdcurrent) {
         // TODO should be controlled
         // add new line after ;
         // TODO some styles allow short statement in line
         // For example: case 1: i++; break;
         if (!.isLastLineToken()) {
             .addAfterCurrent(current, 1, getIndent(), true);
             return true;
         }
         return false;
     }
 
     private void braceFormat(Token<CppTokenIdpreviousToken<CppTokenIdcurrent) {
         StackEntry entry = .peek();
         if (entry != null && entry.getImportantKind() != null) {
             switch (entry.getImportantKind()) {
                 case //("namespace", "keyword"), //C++
                 {
                     // TODO divide for neamespace
                     newLine(previouscurrent.getFormatNewlineBeforeBraceNamespace(),
                             .spaceBeforeClassDeclLeftBrace(), 1);
                     return;
                 }
                 case //("class", "keyword"), //C++
                 case //("struct", "keyword"),
                 case //("enum", "keyword"),
                 case //("union", "keyword"),
                 {
                     Token<CppTokenIdnext = .lookNextImportant();
                     if (next != null){
                         newLinesAfter(previouscurrent);
                     }
                     return;
                 }
                 case //("if", "keyword-directive"),
                 {
                     newLine(previouscurrent.getFormatNewlineBeforeBrace(),
                             .spaceBeforeIfLeftBrace(), 1);
                     return;
                 }