Commit 16bd0497 authored by Joachim Müssig's avatar Joachim Müssig
Browse files

clear up code, javadoc

parent 7e591a76
...@@ -11,16 +11,35 @@ package joanakey.persistence; ...@@ -11,16 +11,35 @@ package joanakey.persistence;
*/ */
public class JsonHelper { public class JsonHelper {
/**
* generate a key value pair and append it to the given stringBuilder object. The value is appended with quotes as String ("value").
* @param stringBuilder object to which you want append the key, value pair
* @param key json key
* @param value as string
*/
public static void addJsonStringToStringBuilder(StringBuilder stringBuilder, public static void addJsonStringToStringBuilder(StringBuilder stringBuilder,
String key, String value) { String key, String value) {
stringBuilder.append("\"" + key + "\" : " + "\"" + value + "\""); stringBuilder.append("\"" + key + "\" : " + "\"" + value + "\"");
} }
/**
* generate a key value pair and append it to the given stringBuilder object. The value is appended without quotes.
* @param stringBuilder object to which you want append the key, value pair
* @param key json key
* @param value as string
*/
public static void addKeyValueToJsonStringbuilder(StringBuilder stringBuilder, public static void addKeyValueToJsonStringbuilder(StringBuilder stringBuilder,
String key, String value) { String key, String value) {
stringBuilder.append("\"" + key + "\" : " + value); stringBuilder.append("\"" + key + "\" : " + value);
} }
/**
* generate a key value pair and append it to the given stringBuilder object. The value is appended with curly brackets.
* @param stringBuilder object to which you want to append the key, value pair.
* @param key json key
* @param value as string
*/
public static void addJsonObjValueToStringBuiler(StringBuilder stringBuilder, public static void addJsonObjValueToStringBuiler(StringBuilder stringBuilder,
String key, String value) { String key, String value) {
stringBuilder.append("\"" + key + "\" : {\n"); stringBuilder.append("\"" + key + "\" : {\n");
......
...@@ -12,6 +12,8 @@ import org.json.JSONObject; ...@@ -12,6 +12,8 @@ import org.json.JSONObject;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey; import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
import net.bytebuddy.asm.Advice.This;
/** /**
* *
* @author hklein * @author hklein
...@@ -25,6 +27,11 @@ public class PersistentCGNode { ...@@ -25,6 +27,11 @@ public class PersistentCGNode {
private static final String CG_NODE_ID ="cg_node_id"; private static final String CG_NODE_ID ="cg_node_id";
private static final String IR ="ir"; private static final String IR ="ir";
/**
* generate a {@link PersistentCGNode} object from the given jsonObj
* @param jsonObj which contains the call graph node information
* @return {@link PersistentCGNode}
*/
public static PersistentCGNode generateFromJsonObj(JSONObject jsonObj) { public static PersistentCGNode generateFromJsonObj(JSONObject jsonObj) {
PersistentCGNode node = PersistentCGNode node =
new PersistentCGNode(jsonObj.getInt(ID), jsonObj.getInt(CG_NODE_ID)); new PersistentCGNode(jsonObj.getInt(ID), jsonObj.getInt(CG_NODE_ID));
...@@ -46,6 +53,10 @@ public class PersistentCGNode { ...@@ -46,6 +53,10 @@ public class PersistentCGNode {
persistentIR = new PersistentIR(localPointerKeys, n, uniqueId); persistentIR = new PersistentIR(localPointerKeys, n, uniqueId);
} }
/**
* generate a string which contain the information of this {@link PersistentCGNode}.
* @return String containing information about this object (ID, CG Node ID, IR)
*/
public String generateSaveString() { public String generateSaveString() {
return "\"" + ID + "\" : " + uniqueId + ", " return "\"" + ID + "\" : " + uniqueId + ", "
+ "\""+ CG_NODE_ID + "\" :" + cgNodeId + ", " + + "\""+ CG_NODE_ID + "\" :" + cgNodeId + ", " +
......
...@@ -25,6 +25,11 @@ public class PersistentIR { ...@@ -25,6 +25,11 @@ public class PersistentIR {
private Map<Integer, String> vnsToLocalNames = new HashMap<>(); private Map<Integer, String> vnsToLocalNames = new HashMap<>();
private int containingNodeId; private int containingNodeId;
/**
* generate a {@link PersistentIR} object from the given jsonObj
* @param jsonObj which contains needed information
* @return {@link PersistentIR}
*/
public static PersistentIR generateFromJsonObj(JSONObject jsonObject, int nodeId) { public static PersistentIR generateFromJsonObj(JSONObject jsonObject, int nodeId) {
PersistentIR persistentIR = new PersistentIR(); PersistentIR persistentIR = new PersistentIR();
persistentIR.containingNodeId = nodeId; persistentIR.containingNodeId = nodeId;
...@@ -57,7 +62,11 @@ public class PersistentIR { ...@@ -57,7 +62,11 @@ public class PersistentIR {
} }
} }
} }
/**
* generate a string which contain the information of this {@link PersistentIR} object.
* @return String containing information about this object.
*/
public String generateSaveString() { public String generateSaveString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
vnsToLocalNames.forEach((i, s) -> { vnsToLocalNames.forEach((i, s) -> {
......
...@@ -26,6 +26,12 @@ public class PersistentLocalPointerKey { ...@@ -26,6 +26,12 @@ public class PersistentLocalPointerKey {
private PersistentCGNode persistentCGNode; private PersistentCGNode persistentCGNode;
private int id; private int id;
/**
* generate a {@link PersistentLocalPointerKey} object from the given jsonObj
* @param jsonObj which contains needed information
* @param cgNodes, list of {@link PersistentCGNode}
* @return {@link PersistentCGNode}
*/
public static PersistentLocalPointerKey generateFromJsonObj(JSONObject jsonObj, public static PersistentLocalPointerKey generateFromJsonObj(JSONObject jsonObj,
List<PersistentCGNode> cgNodes) { List<PersistentCGNode> cgNodes) {
int nodeIndex = jsonObj.getInt(NODE); int nodeIndex = jsonObj.getInt(NODE);
...@@ -42,6 +48,7 @@ public class PersistentLocalPointerKey { ...@@ -42,6 +48,7 @@ public class PersistentLocalPointerKey {
private PersistentLocalPointerKey() { private PersistentLocalPointerKey() {
} }
public PersistentLocalPointerKey(LocalPointerKey localPointerKey, PersistentCGNode persistentCGNode, public PersistentLocalPointerKey(LocalPointerKey localPointerKey, PersistentCGNode persistentCGNode,
int uniqueId) { int uniqueId) {
valueNumber = localPointerKey.getValueNumber(); valueNumber = localPointerKey.getValueNumber();
...@@ -61,6 +68,10 @@ public class PersistentLocalPointerKey { ...@@ -61,6 +68,10 @@ public class PersistentLocalPointerKey {
return id; return id;
} }
/**
* generate a string which contain the information of this {@link PersistentLocalPointerKey} object.
* @return String containing information about this object.
*/
public String generateSaveString() { public String generateSaveString() {
return "\"" + ID + "\" : " + id return "\"" + ID + "\" : " + id
+ ", \"" + VALUE_NUMBER + "\" : " + String.valueOf(valueNumber) + ", \"" + VALUE_NUMBER + "\" : " + String.valueOf(valueNumber)
......
...@@ -32,6 +32,11 @@ public class ViolationsSaverLoader { ...@@ -32,6 +32,11 @@ public class ViolationsSaverLoader {
private static final String VIOL_PATHS = "violpaths"; private static final String VIOL_PATHS = "violpaths";
private static final String NODE_IDS = "node_ids"; private static final String NODE_IDS = "node_ids";
/**
* generate a string which contain information of the given {@link IViolation} objects.
* @param violations you want to generate the String for.
* @return String
*/
public static String generateSaveString(Collection<? extends IViolation<SecurityNode>> violations) { public static String generateSaveString(Collection<? extends IViolation<SecurityNode>> violations) {
StringBuilder created = new StringBuilder(); StringBuilder created = new StringBuilder();
...@@ -76,6 +81,12 @@ public class ViolationsSaverLoader { ...@@ -76,6 +81,12 @@ public class ViolationsSaverLoader {
return created.toString(); return created.toString();
} }
/**
* generate a collection of {@link ClassifiedViolation}s from the given {@link JSONArray}
* @param violationsArr, containg multiple {@link JSONObjects} with violation informations.
* @param sdg Graph, used to get the corresponding sdg nodes
* @return
*/
public static Collection<ClassifiedViolation> generateFromJSON(JSONArray violationsArr, SDG sdg) { public static Collection<ClassifiedViolation> generateFromJSON(JSONArray violationsArr, SDG sdg) {
Collection<ClassifiedViolation> created = new ArrayList<>(); Collection<ClassifiedViolation> created = new ArrayList<>();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment