add json output for convenience about more lang bindings for bmap.
This commit is contained in:
parent
824497f638
commit
aa8ec72df7
60
CodeGen/BMapBindings/JsonWriter.java
Normal file
60
CodeGen/BMapBindings/JsonWriter.java
Normal file
@ -0,0 +1,60 @@
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.Vector;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
public class JsonWriter {
|
||||
|
||||
private static JsonObject writeVariableType(VariableType vt) {
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
JsonArray hierarchy = new JsonArray();
|
||||
for (String item : vt.getBaseTypeHierarchy()) {
|
||||
hierarchy.add(item);
|
||||
}
|
||||
data.add("hierarchy", hierarchy);
|
||||
data.addProperty("pointer_level", vt.getPointerLevel());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private static JsonObject writeExpFctParamDecl(ExpFctParamDecl paramdecl) {
|
||||
JsonObject data = new JsonObject();
|
||||
data.addProperty("name", paramdecl.mVarName);
|
||||
data.addProperty("is_input", paramdecl.mIsInput);
|
||||
data.addProperty("desc", paramdecl.mVarDesc);
|
||||
data.add("type", writeVariableType(paramdecl.mVarType));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private static JsonObject writeExpFctDecl(ExpFctDecl fctdecl) {
|
||||
JsonObject data = new JsonObject();
|
||||
data.addProperty("name", fctdecl.mFctName);
|
||||
data.add("return", writeVariableType(fctdecl.mFctRetType));
|
||||
|
||||
JsonArray paramlist = new JsonArray();
|
||||
for (ExpFctParamDecl paramdecl : fctdecl.mFctParams) {
|
||||
paramlist.add(writeExpFctParamDecl(paramdecl));
|
||||
}
|
||||
data.add("params", paramlist);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void writeJson(Vector<ExpFctDecl> data) throws Exception {
|
||||
OutputStreamWriter writer = CommonHelper.openWriter("dest/BMExports.json");
|
||||
//Gson gson_instance = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
Gson gson_instance = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
JsonArray fcts = new JsonArray();
|
||||
for (ExpFctDecl fctdecl : data) {
|
||||
fcts.add(writeExpFctDecl(fctdecl));
|
||||
}
|
||||
|
||||
writer.write(gson_instance.toJson(fcts));
|
||||
writer.close();
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ public class MainRunner {
|
||||
Vector<ExpFctDecl> result = worker.getResult();
|
||||
PythonWriter.writePythonCode(result);
|
||||
CSharpWriter.writeCSharpCode(result);
|
||||
JsonWriter.writeJson(result);
|
||||
|
||||
// print message.
|
||||
System.out.println("DONE!");
|
||||
|
@ -68,6 +68,10 @@ public class VariableType {
|
||||
return mPointerLevel;
|
||||
}
|
||||
|
||||
public Vector<String> getBaseTypeHierarchy() {
|
||||
return (Vector<String>) mBaseType.clone();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return mBaseType.size() != 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user