Fix if-else autoformatting

This commit is contained in:
AmnonOwed
2014-04-23 18:51:47 +02:00
parent 34a3ed1852
commit 6146888909

View File

@@ -133,7 +133,7 @@ public class AutoFormat implements Formatter {
private void writeIndentedLine() {
if (buf.length() == 0) {
if (s_flag) {
s_flag = a_flg = false;
s_flag = a_flg = e_flg = false;
}
return;
}
@@ -150,9 +150,25 @@ public class AutoFormat implements Formatter {
}
a_flg = false;
}
if (e_flg) {
if (lastNonSpaceChar() == '}') {
trimRight(result);
result.append(" ");
}
}
result.append(buf);
buf.setLength(0);
}
private char lastNonSpaceChar() {
for (int i=result.length()-1; i>=0; i--) {
char c_i = result.charAt(i);
if (c_i == ' ' || c_i == '\n') continue;
else return c_i;
}
return 0;
}
private void writeIndentedComment() {
@@ -371,7 +387,8 @@ public class AutoFormat implements Formatter {
case ' ':
case '\t':
if (lookup("else")) {
e_flg = lookup("else");
if (e_flg) {
gotelse();
if ((!s_flag) || buf.length() > 0) {
buf.append(c);
@@ -380,7 +397,6 @@ public class AutoFormat implements Formatter {
// s_flag = false;
// trimRight(result);
// result.append(" ");
writeIndentedLine();
s_flag = false;
break;
@@ -418,7 +434,8 @@ public class AutoFormat implements Formatter {
break;
case '{':
if (lookup("else")) {
e_flg = lookup("else");
if (e_flg) {
gotelse();
}
if (s_if_lev.length == c_level) {