File tree Expand file tree Collapse file tree
src/processing/app/format
src/test/processing/parsing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -301,7 +301,6 @@ private boolean lookup_com(final String keyword) {
301301 }
302302
303303 public String format (final String source ) {
304- // Adding an additional newline as a hack around other errors
305304 final String normalizedText = source .replaceAll ("\r " , "" );
306305 final String cleanText = normalizedText
307306 + (normalizedText .endsWith ("\n " ) ? "" : "\n " );
@@ -592,10 +591,20 @@ public String format(final String source) {
592591 case '(' :
593592 castFlags .push (Pattern .matches ("^.*?(?:int|color|float)\\ s*$" , buf ));
594593
594+ final boolean isFor = lookup ("for" );
595+ final boolean isIf = lookup ("if" );
596+
597+ if (isFor || isIf || lookup ("while" )) {
598+ if (!Character .isWhitespace (buf .charAt (buf .length () - 1 ))) {
599+ buf .append (' ' );
600+ }
601+ }
602+
595603 buf .append (c );
596604 paren ++;
597605
598- if ((lookup ("for" ))) {
606+ if (isFor ) {
607+ // TODO(feinberg): handle new-style for loops
599608 c = get_string ();
600609 while (c != ';' && c != ':' ) {
601610 c = get_string ();
@@ -618,8 +627,7 @@ public String format(final String source) {
618627 } // endwhile for_done
619628 paren --;
620629 if (paren < 0 ) {
621- paren = 0 ;//EOF = true;
622- //System.out.println("eof d");
630+ paren = 0 ;
623631 }
624632 writeIndentedLine ();
625633 if (getnl ()) {
@@ -629,9 +637,7 @@ public String format(final String source) {
629637 ind [level ] = 0 ;
630638 }
631639 break ;
632- }
633-
634- if (lookup ("if" )) {
640+ } else if (isIf ) {
635641 writeIndentedLine ();
636642 s_tabs [c_level ][if_lev ] = tabs ;
637643 sp_flg [c_level ][if_lev ] = p_flg [level ];
Original file line number Diff line number Diff line change 1+ for (int i : new int[] {1,2,3}) {
2+ println(i);
3+ }
Original file line number Diff line number Diff line change 1+ for (int i : new int [] {1 ,2 ,3 }) {
2+ println (i);
3+ }
Original file line number Diff line number Diff line change @@ -51,6 +51,11 @@ public void bug109() {
5151 expectGood ("bug109" );
5252 }
5353
54+ @ Test
55+ public void bug405 () {
56+ expectGood ("bug405" );
57+ }
58+
5459 @ Test
5560 public void bug420 () {
5661 expectGood ("bug420" );
You can’t perform that action at this time.
0 commit comments