| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e1e204f commit b06f563
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -301,7 +301,6 @@ private boolean lookup_com(final String keyword) { | |||
| 301 | 301 | } | |
| 302 | 302 | ||
| 303 | 303 | public String format(final String source) { | |
| 304 | - // Adding an additional newline as a hack around other errors | ||
| 305 | 304 | final String normalizedText = source.replaceAll("\r", ""); | |
| 306 | 305 | final String cleanText = normalizedText | |
| 307 | 306 | + (normalizedText.endsWith("\n") ? "" : "\n"); | |
@@ -592,10 +591,20 @@ public String format(final String source) { | |||
| 592 | 591 | case '(': | |
| 593 | 592 | castFlags.push(Pattern.matches("^.*?(?:int|color|float)\\s*$", buf)); | |
| 594 | 593 | ||
| 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 | + | ||
| 595 | 603 | buf.append(c); | |
| 596 | 604 | paren++; | |
| 597 | 605 | ||
| 598 | - if ((lookup("for"))) { | ||
| 606 | + if (isFor) { | ||
| 607 | + // TODO(feinberg): handle new-style for loops | ||
| 599 | 608 | c = get_string(); | |
| 600 | 609 | while (c != ';' && c != ':') { | |
| 601 | 610 | c = get_string(); | |
@@ -618,8 +627,7 @@ public String format(final String source) { | |||
| 618 | 627 | } // endwhile for_done | |
| 619 | 628 | paren--; | |
| 620 | 629 | if (paren < 0) { | |
| 621 | - paren = 0;//EOF = true; | ||
| 622 | - //System.out.println("eof d"); | ||
| 630 | + paren = 0; | ||
| 623 | 631 | } | |
| 624 | 632 | writeIndentedLine(); | |
| 625 | 633 | if (getnl()) { | |
@@ -629,9 +637,7 @@ public String format(final String source) { | |||
| 629 | 637 | ind[level] = 0; | |
| 630 | 638 | } | |
| 631 | 639 | break; | |
| 632 | - } | ||
| 633 | - | ||
| 634 | - if (lookup("if")) { | ||
| 640 | + } else if (isIf) { | ||
| 635 | 641 | writeIndentedLine(); | |
| 636 | 642 | s_tabs[c_level][if_lev] = tabs; | |
| 637 | 643 | sp_flg[c_level][if_lev] = p_flg[level]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + for (int i : new int[] {1,2,3}) { | ||
| 2 | + println(i); | ||
| 3 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 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() { | |||
| 51 | 51 | expectGood("bug109"); | |
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | + @Test | ||
| 55 | + public void bug405() { | ||
| 56 | + expectGood("bug405"); | ||
| 57 | + } | ||
| 58 | + | ||
| 54 | 59 | @Test | |
| 55 | 60 | public void bug420() { | |
| 56 | 61 | expectGood("bug420"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments