system/src/sc/parser/NewlineParseNode.java
public void format(FormatContext ctx) {
      if (ctx.replaceFormatting) {
         ctx.setReplaceNode(this);
      }

      if (ctx.semanticValueOnly)
         return;

      ctx.appendWithStyle(terminator);

      boolean suppressNewline = false;

      boolean doPop = false;
      boolean doPush = false;
      int indentIncr = 0;
      int nextInt = ctx.nextChar();
      Object val = null;
      int indent = -1;
      char nextChar = '\0';

      // For if (...) when there's no { we indent the current indent plus one and do not push (since it's only one line)
      if (needsIndent) {
         indentIncr = 1;
      }

      if (nextInt != -1) {
         nextChar = (char) nextInt;
         switch (nextChar) {
            case '}':
               doPop = true;
               break;
            case '{':
               // if (foo) { - all on one line
               if (terminator.equals(")")) {
                  suppressNewline = true;
               }
               break;
         }
      }

      int prevInt = ctx.prevChar();
      if (prevInt != -1) {
         char prevChar = (char) prevInt;
         switch (prevChar) {
            case '}':
               if (ctx.suppressNewlines) {
                  ctx.appendWithStyle(" ");
                  return;
               }
               break;
            case '{':
               // If this is {} just get out without popping since we did not push this one
               if (nextChar == '}')
                   return;
               break;
         }
      }

      if (doPop)
         indent = ctx.popIndent();

      if (!suppressNewline)
         ctx.appendWithStyle(getNewlineSeparator());

      if (indent == -1) {
         val = ctx.nextSemanticNode();
         if (val != null && val instanceof ISemanticNode) {
            ISemanticNode ival = (ISemanticNode) val;
            int incr = 0;

            // The first newline after the open brace will find the list of statements, not
            // an individual statement.  In this case, we unwrap and get the indent
            // for the first statement in the list.
            if (ival instanceof SemanticNodeList) {
               SemanticNodeList listVal = (SemanticNodeList) ival;
               if (listVal.size() > 0) {
                  val = listVal.get(0);
                  if (val instanceof ISemanticNode)
                     ival = (ISemanticNode) val;
                  // Since the string is inside of the list, we'll add 1 to the list's indent
                  else if (PString.isString(val))
                     incr = 1;
               }
            }
            indent = ival.getNestingDepth() + incr;
         }
      }
      // The close brace will automatically pop back to the indent from the open
      if (terminator.equals("{") || doPush)
         ctx.pushIndent();

      if (!suppressNewline)
         ctx.indentWithStyle(indent + indentIncr);
      else
         ctx.appendWithStyle(" ");
   }
/**
    * This node is inserted into the parse-node tree where formatting rules might require a newline.  It also chooses the indent
    * level to put in after the newline based on the indent level of the next semantic value.
    *
    * @param ctx
    */
This node is inserted into the parse-node tree where formatting rules might require a newline.  It also chooses the indent
level to put in after the newline based on the indent level of the next semantic value.

@param ctx
This node is inserted into the parse - node tree where formatting rules might require a newline . It also chooses the indent level to put in after the newline based on the indent level of the next semantic value . @param ctx
public void format(FormatContext ctx) {
      if (ctx.replaceFormatting) {
         ctx.setReplaceNode(this);
      }
      if (ctx.semanticValueOnly)
         return;
      ctx.appendWithStyle(terminator);
      boolean suppressNewline = false;
      boolean doPop = false;
      boolean doPush = false;
      int indentIncr = 0;
      int nextInt = ctx.nextChar();
      Object val = null;
      int indent = -1;
      char nextChar = '\0';
      if (needsIndent) {
         indentIncr = 1;
      }
      if (nextInt != -1) {
         nextChar = (char) nextInt;
         switch (nextChar) {
            case '}':
               doPop = true;
               break;
            case '{':
               if (terminator.equals(")")) {
                  suppressNewline = true;
               }
               break;
         }
      }
      int prevInt = ctx.prevChar();
      if (prevInt != -1) {
         char prevChar = (char) prevInt;
         switch (prevChar) {
            case '}':
               if (ctx.suppressNewlines) {
                  ctx.appendWithStyle(" ");
                  return;
               }
               break;
            case '{':
               if (nextChar == '}')
                   return;
               break;
         }
      }
      if (doPop)
         indent = ctx.popIndent();
      if (!suppressNewline)
         ctx.appendWithStyle(getNewlineSeparator());
      if (indent == -1) {
         val = ctx.nextSemanticNode();
         if (val != null && val instanceof ISemanticNode) {
            ISemanticNode ival = (ISemanticNode) val;
            int incr = 0;
            if (ival instanceof SemanticNodeList) {
               SemanticNodeList listVal = (SemanticNodeList) ival;
               if (listVal.size() > 0) {
                  val = listVal.get(0);
                  if (val instanceof ISemanticNode)
                     ival = (ISemanticNode) val;
                  else if (PString.isString(val))
                     incr = 1;
               }
            }
            indent = ival.getNestingDepth() + incr;
         }
      }
      if (terminator.equals("{") || doPush)
         ctx.pushIndent();
      if (!suppressNewline)
         ctx.indentWithStyle(indent + indentIncr);
      else
         ctx.appendWithStyle(" ");
   }
public void format ( FormatContext ctx ) { if ( ctx . replaceFormatting ) { ctx . setReplaceNode ( this ) ; } if ( ctx . semanticValueOnly ) return ; ctx . appendWithStyle ( terminator ) ; boolean suppressNewline = false ; boolean doPop = false ; boolean doPush = false ; int indentIncr = 0 ; int nextInt = ctx . nextChar ( ) ; Object val = null ; int indent = - 1 ; char nextChar = '\0' ; if ( needsIndent ) { indentIncr = 1 ; } if ( nextInt != - 1 ) { nextChar = ( char ) nextInt ; switch ( nextChar ) { case '}' : doPop = true ; break ; case '{' : if ( terminator . equals ( ")" ) ) { suppressNewline = true ; } break ; } } int prevInt = ctx . prevChar ( ) ; if ( prevInt != - 1 ) { char prevChar = ( char ) prevInt ; switch ( prevChar ) { case '}' : if ( ctx . suppressNewlines ) { ctx . appendWithStyle ( " " ) ; return ; } break ; case '{' : if ( nextChar == '}' ) return ; break ; } } if ( doPop ) indent = ctx . popIndent ( ) ; if ( ! suppressNewline ) ctx . appendWithStyle ( getNewlineSeparator ( ) ) ; if ( indent == - 1 ) { val = ctx . nextSemanticNode ( ) ; if ( val != null && val instanceof ISemanticNode ) { ISemanticNode ival = ( ISemanticNode ) val ; int incr = 0 ; if ( ival instanceof SemanticNodeList ) { SemanticNodeList listVal = ( SemanticNodeList ) ival ; if ( listVal . size ( ) > 0 ) { val = listVal . get ( 0 ) ; if ( val instanceof ISemanticNode ) ival = ( ISemanticNode ) val ; else if ( PString . isString ( val ) ) incr = 1 ; } } indent = ival . getNestingDepth ( ) + incr ; } } if ( terminator . equals ( "{" ) || doPush ) ctx . pushIndent ( ) ; if ( ! suppressNewline ) ctx . indentWithStyle ( indent + indentIncr ) ; else ctx . appendWithStyle ( " " ) ; }
This node is inserted into the parse-node tree where formatting rules might require a newline.
This node is inserted into the parse - node tree where formatting rules might require a newline .
// For if (...) when there's no { we indent the current indent plus one and do not push (since it's only one line) // if (foo) { - all on one line // If this is {} just get out without popping since we did not push this one // The first newline after the open brace will find the list of statements, not // an individual statement.  In this case, we unwrap and get the indent // for the first statement in the list. // Since the string is inside of the list, we'll add 1 to the list's indent // The close brace will automatically pop back to the indent from the open