Class CallGraph2JSON


  • public class CallGraph2JSON
    extends java.lang.Object
    Utility class to serialize call graphs as JSON objects.

    The serialised objects have the form

     {
       "<callsite1>": [ "<callee1>", "<callee2>", ... ],
       "<callsite2>": ...
     }
     
    where both call sites and callees are encoded as strings of the form
     "<filename>@<lineno>:<beginoff>-<endoff>"
     
    Here, filename is the name of the containing JavaScript file (not including its directory), and lineno, beginoff and endoff encode the source position of the call expression (for call sites) or the function declaration/expression (for callees) inside the file in terms of its starting line, its starting offset (in characters from the beginning of the file), and its end offset.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.Set<java.lang.String>>> extractEdges​(com.ibm.wala.ipa.callgraph.CallGraph cg)
      Extract the edges of the given callgraph as a map over strings that is easy to serialize.
      java.lang.String serialize​(com.ibm.wala.ipa.callgraph.CallGraph cg)  
      void serializeCallSite​(com.ibm.wala.ipa.callgraph.CGNode nd, com.ibm.wala.classLoader.CallSiteReference callsite, java.util.Set<com.ibm.wala.ipa.callgraph.CGNode> targets, java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> edges)  
      static java.lang.String toJSON​(java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.Set<java.lang.String>>> map)
      Converts a call graph map produced by extractEdges(CallGraph) to JSON, eliding call sites with no targets.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CallGraph2JSON

        public CallGraph2JSON()
      • CallGraph2JSON

        public CallGraph2JSON​(boolean ignoreHarness)
      • CallGraph2JSON

        public CallGraph2JSON​(boolean ignoreHarness,
                              boolean exposeContexts)
    • Method Detail

      • serialize

        public java.lang.String serialize​(com.ibm.wala.ipa.callgraph.CallGraph cg)
      • extractEdges

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.Set<java.lang.String>>> extractEdges​(com.ibm.wala.ipa.callgraph.CallGraph cg)
        Extract the edges of the given callgraph as a map over strings that is easy to serialize. The map keys are locations of methods. The map values are themselves maps, from call site locations within a method to the (locations of) potential target methods for the call sites.
      • serializeCallSite

        public void serializeCallSite​(com.ibm.wala.ipa.callgraph.CGNode nd,
                                      com.ibm.wala.classLoader.CallSiteReference callsite,
                                      java.util.Set<com.ibm.wala.ipa.callgraph.CGNode> targets,
                                      java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> edges)
      • toJSON

        public static java.lang.String toJSON​(java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.Set<java.lang.String>>> map)
        Converts a call graph map produced by extractEdges(CallGraph) to JSON, eliding call sites with no targets.