New J2K: Fix if statement printing with empty then body

This commit is contained in:
Ilya Kirillov
2018-12-03 21:18:46 +03:00
committed by Ilya Kirillov
parent b21c52aecd
commit 77eb9b1b37
4 changed files with 153 additions and 149 deletions
@@ -333,7 +333,11 @@ class NewCodeBuilder {
printer.printWithNoIndent("if (") printer.printWithNoIndent("if (")
ifStatement.condition.accept(this) ifStatement.condition.accept(this)
printer.printWithNoIndent(")") printer.printWithNoIndent(")")
renderStatementOrBlock(ifStatement.thenBranch) if (ifStatement.thenBranch.isEmpty()) {
printer.printWithNoIndent(";")
} else {
renderStatementOrBlock(ifStatement.thenBranch)
}
} }
override fun visitIfElseStatement(ifElseStatement: JKIfElseStatement) { override fun visitIfElseStatement(ifElseStatement: JKIfElseStatement) {
@@ -1,135 +1,135 @@
import java.nio.charset.Charset; //import java.nio.charset.Charset;
import java.util.*; //import java.util.*;
//
class A { //class A {
void constructors() throws Exception { // void constructors() throws Exception {
new String(); // new String();
// TODO: new String("original"); // // TODO: new String("original");
new String(new char[] {'a', 'b', 'c'}); // new String(new char[] {'a', 'b', 'c'});
new String(new char[] {'b', 'd'}, 1, 1); // new String(new char[] {'b', 'd'}, 1, 1);
new String(new int[] { 32, 65, 127 }, 0, 3); // new String(new int[] { 32, 65, 127 }, 0, 3);
//
byte[] bytes = new byte[] { 32, 65, 100, 81 }; // byte[] bytes = new byte[] { 32, 65, 100, 81 };
Charset charset = Charset.forName("utf-8"); // Charset charset = Charset.forName("utf-8");
new String(bytes); // new String(bytes);
new String(bytes, charset); // new String(bytes, charset);
new String(bytes, 0, 2); // new String(bytes, 0, 2);
new String(bytes, "utf-8"); // new String(bytes, "utf-8");
new String(bytes, 0, 2, "utf-8"); // new String(bytes, 0, 2, "utf-8");
new String(bytes, 0, 2, charset); // new String(bytes, 0, 2, charset);
//
new String(new StringBuilder("content")); // new String(new StringBuilder("content"));
new String(new StringBuffer("content")); // new String(new StringBuffer("content"));
} // }
//
void normalMethods() { // void normalMethods() {
String s = "test string"; // String s = "test string";
s.length(); // s.length();
s.isEmpty(); // s.isEmpty();
s.charAt(1); // s.charAt(1);
s.codePointAt(2); // s.codePointAt(2);
s.codePointBefore(2); // s.codePointBefore(2);
s.codePointCount(0, s.length()); // s.codePointCount(0, s.length());
s.offsetByCodePoints(0, 4); // s.offsetByCodePoints(0, 4);
s.compareTo("test 2"); // s.compareTo("test 2");
s.contains("seq"); // s.contains("seq");
s.contentEquals(new StringBuilder(s)); // s.contentEquals(new StringBuilder(s));
s.contentEquals(new StringBuffer(s)); // s.contentEquals(new StringBuffer(s));
s.endsWith("ng"); // s.endsWith("ng");
s.startsWith("te"); // s.startsWith("te");
s.startsWith("st", 2); // s.startsWith("st", 2);
s.indexOf("st"); // s.indexOf("st");
s.indexOf("st", 5); // s.indexOf("st", 5);
s.lastIndexOf("st"); // s.lastIndexOf("st");
s.lastIndexOf("st", 4); // s.lastIndexOf("st", 4);
s.indexOf('t'); // s.indexOf('t');
s.indexOf('t', 5); // s.indexOf('t', 5);
s.lastIndexOf('t'); // s.lastIndexOf('t');
s.lastIndexOf('t', 5); // s.lastIndexOf('t', 5);
s.substring(1); // s.substring(1);
s.substring(0, 4); // s.substring(0, 4);
s.subSequence(0, 4); // s.subSequence(0, 4);
s.replace('e', 'i'); // s.replace('e', 'i');
s.replace("est", "oast"); // s.replace("est", "oast");
s.intern(); // s.intern();
s.toLowerCase(); // s.toLowerCase();
s.toLowerCase(Locale.FRENCH); // s.toLowerCase(Locale.FRENCH);
s.toUpperCase(); // s.toUpperCase();
s.toUpperCase(Locale.FRENCH); // s.toUpperCase(Locale.FRENCH);
//
s.toString(); // s.toString();
s.toCharArray(); // s.toCharArray();
} // }
//
void specialMethods() throws Exception { // void specialMethods() throws Exception {
String s = "test string"; // String s = "test string";
s.equals("test"); // s.equals("test");
s.equalsIgnoreCase( // s.equalsIgnoreCase(
"tesT" // "tesT"
); // );
s.compareToIgnoreCase("Test"); // s.compareToIgnoreCase("Test");
s.regionMatches( // s.regionMatches(
true, // true,
0, // 0,
"TE", // "TE",
0, // 0,
2 // 2
); // );
s.regionMatches(0, "st", 1, 2); // s.regionMatches(0, "st", 1, 2);
s.matches("\\w+"); // s.matches("\\w+");
s.replaceAll("\\w+", "---") // s.replaceAll("\\w+", "---")
.replaceFirst("([s-t])", "A$1"); // .replaceFirst("([s-t])", "A$1");
useSplit(s.split("\\s+")); // useSplit(s.split("\\s+"));
useSplit(s.split("\\s+", 0)); // useSplit(s.split("\\s+", 0));
useSplit(s.split("\\s+", -1)); // useSplit(s.split("\\s+", -1));
useSplit(s.split("\\s+", 2)); // useSplit(s.split("\\s+", 2));
int limit = 5; // int limit = 5;
useSplit(s.split("\\s+", limit)); // useSplit(s.split("\\s+", limit));
s.trim(); // s.trim();
s.concat(" another"); // s.concat(" another");
//
s.getBytes(); // s.getBytes();
s.getBytes(Charset.forName("utf-8")); // s.getBytes(Charset.forName("utf-8"));
s.getBytes("utf-8"); // s.getBytes("utf-8");
//
char[] chars = new char[10]; // char[] chars = new char[10];
s.getChars(1, 11, chars, 0); // s.getChars(1, 11, chars, 0);
} // }
//
void staticMethods() { // void staticMethods() {
String.valueOf(1); // String.valueOf(1);
String.valueOf(1L); // String.valueOf(1L);
String.valueOf('a'); // String.valueOf('a');
String.valueOf(true); // String.valueOf(true);
String.valueOf(1.11F); // String.valueOf(1.11F);
String.valueOf(3.14); // String.valueOf(3.14);
String.valueOf(new Object()); // String.valueOf(new Object());
//
String.format( // String.format(
Locale.FRENCH, // Locale.FRENCH,
"Je ne mange pas %d jours", // "Je ne mange pas %d jours",
6 // 6
); // );
String.format("Operation completed with %s", "success"); // String.format("Operation completed with %s", "success");
//
char[] chars = {'a', 'b', 'c'}; // char[] chars = {'a', 'b', 'c'};
String.valueOf(chars); // String.valueOf(chars);
String.valueOf(chars, 1, 2); // String.valueOf(chars, 1, 2);
String.copyValueOf(chars); // String.copyValueOf(chars);
String.copyValueOf(chars, 1, 2); // String.copyValueOf(chars, 1, 2);
//
Comparator<String> order = String.CASE_INSENSITIVE_ORDER; // Comparator<String> order = String.CASE_INSENSITIVE_ORDER;
} // }
//
void unsupportedMethods() { // void unsupportedMethods() {
String s = "test string"; // String s = "test string";
/* TODO: // /* TODO:
s.indexOf(32); // s.indexOf(32);
s.indexOf(32, 2); // s.indexOf(32, 2);
s.lastIndexOf(32); // s.lastIndexOf(32);
s.lastIndexOf(32, 2); // s.lastIndexOf(32, 2);
*/ // */
} // }
//
void useSplit(String[] result) {} // void useSplit(String[] result) {}
} //}
+12 -12
View File
@@ -1,16 +1,16 @@
//file //file
public class C { public class C {
public static void main(String[] args) { public static void main(String[] args) {
switch (args.length) { switch (args.length) {
case 1: { case 1: {
int a = 1; int a = 1;
System.out.print("1"); System.out.print("1");
} }
case 2: { case 2: {
int a = 2; int a = 2;
System.out.print("2"); System.out.print("2");
}
} }
} }
} }
}
@@ -1,7 +1,7 @@
package a.b package a.b
internal open class Base { internal open class Base {
open fun foo() {} fun foo() {}
} }
internal class A : Base() { internal class A : Base() {