|
|
@ -20,6 +20,8 @@ import java.io.PrintWriter;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class JSONOutputUtils {
|
|
|
|
public class JSONOutputUtils {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAB = " ";
|
|
|
|
|
|
|
|
|
|
|
|
private JSONOutputUtils() {}
|
|
|
|
private JSONOutputUtils() {}
|
|
|
|
|
|
|
|
|
|
|
|
// print a comma between all JSON objects except for the last one
|
|
|
|
// print a comma between all JSON objects except for the last one
|
|
|
@ -31,20 +33,34 @@ public class JSONOutputUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void outputTabbed(PrintWriter out, String toWrite, int numTabs) {
|
|
|
|
|
|
|
|
for (int i = 0; i < numTabs; i++) {
|
|
|
|
|
|
|
|
out.print(TAB);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
out.print(toWrite);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void outputlnTabbed(PrintWriter out, String toWrite, int numTabs) {
|
|
|
|
|
|
|
|
outputTabbed(out, toWrite, numTabs);
|
|
|
|
|
|
|
|
out.println();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String quote(String raw) {
|
|
|
|
|
|
|
|
return "\"" + raw + "\"";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void outputMethod(PrintWriter out, String clazz, String method,
|
|
|
|
public static void outputMethod(PrintWriter out, String clazz, String method,
|
|
|
|
int elemCount, int elemMax) {
|
|
|
|
int elemCount, int elemMax) {
|
|
|
|
String TAB1 = " ";
|
|
|
|
outputlnTabbed(out, "{", 1);
|
|
|
|
String TAB2 = TAB1 + TAB1;
|
|
|
|
outputlnTabbed(out, "\"language\": \"Java\",", 2);
|
|
|
|
out.println(TAB1 + "{");
|
|
|
|
outputTabbed(out, "\"class\": \"" + clazz + "\"", 2);
|
|
|
|
out.println(TAB2 +"\"language\": \"Java\",");
|
|
|
|
|
|
|
|
out.print(TAB2 + "\"class\": \"" + clazz + "\"");
|
|
|
|
|
|
|
|
if (method != null) {
|
|
|
|
if (method != null) {
|
|
|
|
out.println(",");
|
|
|
|
out.println(",");
|
|
|
|
out.println(TAB2 + "\"method\": \"" + method + "\"");
|
|
|
|
outputlnTabbed(out, "\"method\": \"" + method + "\"", 2);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
out.println();
|
|
|
|
out.println();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out.print(TAB1 + "}");
|
|
|
|
outputlnTabbed(out, "}", 1);
|
|
|
|
outputCommaIfNotLast(out, elemCount, elemMax);
|
|
|
|
outputCommaIfNotLast(out, elemCount, elemMax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -54,8 +70,7 @@ public class JSONOutputUtils {
|
|
|
|
|
|
|
|
|
|
|
|
public static void outputClassSourcePair(PrintWriter out, String clazz, String source,
|
|
|
|
public static void outputClassSourcePair(PrintWriter out, String clazz, String source,
|
|
|
|
int elemCount, int elemMax) {
|
|
|
|
int elemCount, int elemMax) {
|
|
|
|
String TAB = " ";
|
|
|
|
outputlnTabbed(out, "\"" + clazz + "\": \"" + source + "\"", 1);
|
|
|
|
out.print(TAB + "\"" + clazz + "\": \"" + source + "\"");
|
|
|
|
|
|
|
|
outputCommaIfNotLast(out, elemCount, elemMax);
|
|
|
|
outputCommaIfNotLast(out, elemCount, elemMax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|