From 3a7767213c91a5f1c58689eb8c79935576d87f03 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Wed, 18 May 2016 03:02:32 -0700 Subject: [PATCH] adding some functionality to JSONOutputUtils Reviewed By: jeremydubreil Differential Revision: D3301475 fbshipit-source-id: 5d257eb --- .../infer/annotprocess/JSONOutputUtils.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/infer/annotations/com/facebook/infer/annotprocess/JSONOutputUtils.java b/infer/annotations/com/facebook/infer/annotprocess/JSONOutputUtils.java index fe422964d..9f50e2cde 100644 --- a/infer/annotations/com/facebook/infer/annotprocess/JSONOutputUtils.java +++ b/infer/annotations/com/facebook/infer/annotprocess/JSONOutputUtils.java @@ -20,6 +20,8 @@ import java.io.PrintWriter; */ public class JSONOutputUtils { + private static final String TAB = " "; + private JSONOutputUtils() {} // 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, int elemCount, int elemMax) { - String TAB1 = " "; - String TAB2 = TAB1 + TAB1; - out.println(TAB1 + "{"); - out.println(TAB2 +"\"language\": \"Java\","); - out.print(TAB2 + "\"class\": \"" + clazz + "\""); + outputlnTabbed(out, "{", 1); + outputlnTabbed(out, "\"language\": \"Java\",", 2); + outputTabbed(out, "\"class\": \"" + clazz + "\"", 2); if (method != null) { out.println(","); - out.println(TAB2 + "\"method\": \"" + method + "\""); + outputlnTabbed(out, "\"method\": \"" + method + "\"", 2); } else { out.println(); } - out.print(TAB1 + "}"); + outputlnTabbed(out, "}", 1); outputCommaIfNotLast(out, elemCount, elemMax); } @@ -54,8 +70,7 @@ public class JSONOutputUtils { public static void outputClassSourcePair(PrintWriter out, String clazz, String source, int elemCount, int elemMax) { - String TAB = " "; - out.print(TAB + "\"" + clazz + "\": \"" + source + "\""); + outputlnTabbed(out, "\"" + clazz + "\": \"" + source + "\"", 1); outputCommaIfNotLast(out, elemCount, elemMax); }