1.1 --- a/src/share/classes/com/sun/tools/javap/BasicWriter.java Thu Feb 06 21:11:27 2014 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javap/BasicWriter.java Tue Feb 11 19:05:50 2014 +0400 1.3 @@ -151,12 +151,22 @@ 1.4 for (int i = 0; i < s.length(); i++) { 1.5 char c = s.charAt(i); 1.6 switch (c) { 1.7 + case ' ': 1.8 + pendingSpaces++; 1.9 + break; 1.10 + 1.11 case '\n': 1.12 println(); 1.13 break; 1.14 + 1.15 default: 1.16 if (buffer.length() == 0) 1.17 indent(); 1.18 + if (pendingSpaces > 0) { 1.19 + for (int sp = 0; sp < pendingSpaces; sp++) 1.20 + buffer.append(' '); 1.21 + pendingSpaces = 0; 1.22 + } 1.23 buffer.append(c); 1.24 } 1.25 } 1.26 @@ -164,6 +174,8 @@ 1.27 } 1.28 1.29 protected void println() { 1.30 + // ignore/discard pending spaces 1.31 + pendingSpaces = 0; 1.32 out.println(buffer); 1.33 buffer.setLength(0); 1.34 } 1.35 @@ -173,26 +185,21 @@ 1.36 } 1.37 1.38 protected void tab() { 1.39 - if (buffer.length() == 0) 1.40 - indent(); 1.41 - space(indentCount * indentWidth + tabColumn - buffer.length()); 1.42 + int col = indentCount * indentWidth + tabColumn; 1.43 + pendingSpaces += (col <= buffer.length() ? 1 : col - buffer.length()); 1.44 } 1.45 1.46 private void indent() { 1.47 - space(indentCount * indentWidth); 1.48 + pendingSpaces += (indentCount * indentWidth); 1.49 } 1.50 1.51 - private void space(int n) { 1.52 - for (int i = 0; i < n; i++) 1.53 - buffer.append(' '); 1.54 - } 1.55 - 1.56 - private PrintWriter out; 1.57 - private StringBuilder buffer; 1.58 + private final PrintWriter out; 1.59 + private final StringBuilder buffer; 1.60 private int indentCount; 1.61 - private int indentWidth; 1.62 - private int tabColumn; 1.63 + private final int indentWidth; 1.64 + private final int tabColumn; 1.65 private boolean pendingNewline; 1.66 + private int pendingSpaces; 1.67 } 1.68 } 1.69