/** * Appends a String to an already opened array. * @param _json * @return */ public JsonBuilder appendToArray(String _string) { this.fixComma(); this.b.append(JsonBuilder.escape(_string)); return this; }
public JsonBuilder appendObjectProperty(String _property, Integer _value) { this.fixComma(); b.append(JsonBuilder.escape(_property)).append(":"); if(_value==null) b.append("null"); else b.append(_value); return this; }
public JsonBuilder startObjectProperty(String _property) { this.fixComma(); b.append(JsonBuilder.escape(_property)).append(":{"); this.openObjects++; return this; }
public JsonBuilder startArrayProperty(String _property) { this.fixComma(); b.append(JsonBuilder.escape(_property)).append(":["); this.openArrays++; return this; }
public JsonBuilder appendObjectProperty(String _property, Boolean _value) { this.fixComma(); b.append(JsonBuilder.escape(_property)).append(":"); if(_value==null) b.append("null"); else b.append(_value.booleanValue()); return this; }
/** * Appends an object property with the given name and value. The value is escaped depending on the boolean parameter _escape. * @param _property * @param _value * @param _escape * @return */ public JsonBuilder appendObjectProperty(String _property, String _value, boolean _escape) { this.fixComma(); b.append(JsonBuilder.escape(_property)).append(":"); if(_value==null) b.append("null"); else if(_escape) b.append(JsonBuilder.escape(_value)); // else if(!this.isSelfContainedJson(_value)) // throw new JsonFormatException("Value is expected to be either a self-contained JSON array enclosed by [ and ], or object enclosed by { and }"); else b.append(_value); return this; }
public String toJSON() { final StringBuilder b = new StringBuilder(); // Key information b.append("{"); b.append(" \"repo\" : \"").append(this.repo).append("\","); if(this.repoPath!=null) b.append(" \"repoPath\" : \"").append(this.repoPath).append("\","); b.append(" \"constructId\" : ").append(this.getConstruct().getId().toJSON()).append(","); if(this.commit!=null) b.append(" \"commit\" : \"").append(this.commit).append("\","); // Other information b.append(" \"constructChangeType\":\"").append(this.getType().toString()).append("\","); if(this.committedAt!=null) b.append(" \"committedAt\" : \"").append(StringUtil.formatDate(Long.parseLong(this.getCommittedAt()))).append("\""); // Buggy method body, fixed one and applied changes if(this.getType() == ConstructChangeType.MOD ){ if(this.fixSignature != null) //b.append(" \"description\" : ").append(JsonBuilder.escape(this.bugDescription)).append(", "); b.append(",\"fixedBody\":").append(JsonBuilder.escape(this.fixSignature.toJson().toString())); //b.append(getFixConstructASTSignature().toJson().toString()).append(" ,"); if(this.defSignature != null) b.append(",\"buggyBody\":").append(JsonBuilder.escape(this.defSignature.toJson().toString())); //b.append(getDefConstructASTSignature().toJson().toString()).append(" ,"); if(signatureChange != null) //b.append(" \"signatureChange\" : ").append(astDiff.toJSON().toString()).append(" ,"); //b.append("\"sigchg \" :[").append(JsonBuilder.escape(astDiff.toJSON().toString())).append("]").append(" ,"); b.append(",\"bodyChange\":").append(JsonBuilder.escape(signatureChange.toJSON().toString())); //b.append(astDiff.toJSON().toString()).append(" ,"); } b.append("}"); return b.toString(); }
b.append(",\"goal\":\"").append(this.goalType).append("\""); b.append(",\"startedAtClient\":\"").append(StringUtil.formatDate(this.stopWatch.getStartMillis())).append("\""); b.append(",\"clientVersion\":").append(JsonBuilder.escape(CoreConfiguration.getVulasRelease())); b.append(",\"exception\":").append(JsonBuilder.escape(this.exception.getMessage().substring(0, Math.min(this.exception.getMessage().length(), 255)))); final String[] value = this.getConfiguration().getConfiguration().getStringArray("vulas." + key); if(c++>0) b.append(","); b.append("{\"source\":\"GOAL_CONFIG\",\"name\":").append(JsonBuilder.escape(key)).append(",\"value\":").append(JsonBuilder.escape(StringUtil.join(value, ","))).append("}"); for(Map.Entry<String, Double> entry: this.goalStats.entrySet()) { if(c++>0) b.append(","); b.append(JsonBuilder.escape(entry.getKey())).append(":").append(entry.getValue()); for(Map.Entry<String, String> entry: this.systemInfo.entrySet()) { if(c++>0) b.append(","); b.append("{\"source\":\"SYSTEM_INFO\",\"name\":").append(JsonBuilder.escape(entry.getKey())).append(",\"value\":").append(JsonBuilder.escape(entry.getValue())).append("}");