Class ModernTraceSerializer

java.lang.Object
cs1302.tracer.serialize.ModernTraceSerializer

public class ModernTraceSerializer extends Object
Serializes ExecutionSnapshot objects into the modern clean JSON trace format.
  • Constructor Details

    • ModernTraceSerializer

      public ModernTraceSerializer(boolean removeMainArgs, boolean inlineStrings, boolean removeMethodThis, TypeStyle typeStyle)
      Constructs a ModernTraceSerializer with the specified formatting options and TypeStyle.
      Parameters:
      removeMainArgs - Whether to remove args from the main stack frame.
      inlineStrings - Whether strings should be inlined.
      removeMethodThis - Whether this references should be omitted from method frames.
      typeStyle - The type qualification style (FQN or SIMPLE).
    • ModernTraceSerializer

      public ModernTraceSerializer(boolean removeMainArgs, boolean inlineStrings, boolean removeMethodThis)
      Constructs a ModernTraceSerializer defaulting to fully qualified type names.
      Parameters:
      removeMainArgs - Whether to remove args from the main stack frame.
      inlineStrings - Whether strings should be inlined.
      removeMethodThis - Whether this references should be omitted from method frames.
  • Method Details

    • getGson

      public static com.google.gson.Gson getGson()
      Gets the shared Gson serializer instance.
      Returns:
      The Gson instance.
    • getGson

      public static com.google.gson.Gson getGson(boolean pretty)
      Gets the shared Gson serializer instance with optional pretty-printing.
      Parameters:
      pretty - True to enable pretty-printing.
      Returns:
      The Gson instance.
    • createTrace

      public Trace createTrace(String javaSource, ExecutionSnapshot snapshot)
      Creates a modern trace for a single execution snapshot.
      Parameters:
      javaSource - The original Java source code.
      snapshot - The single execution snapshot.
      Returns:
      The generated modern Trace object.
    • createTrace

      public Trace createTrace(String javaSource, String stdin, ExecutionSnapshot snapshot)
      Creates a modern trace for a single snapshot with standard input.
      Parameters:
      javaSource - The original Java source code.
      stdin - The standard input string.
      snapshot - The single execution snapshot.
      Returns:
      The generated modern Trace object.
    • createTrace

      public Trace createTrace(String javaSource, List<ExecutionSnapshot> snapshots)
      Creates a modern trace for a chronological list of snapshots.
      Parameters:
      javaSource - The original Java source code.
      snapshots - The list of execution snapshots.
      Returns:
      The generated modern Trace object.
    • createTrace

      public Trace createTrace(String javaSource, String stdin, List<ExecutionSnapshot> snapshots)
      Creates a modern trace for a chronological list of snapshots with standard input.
      Parameters:
      javaSource - The original Java source code.
      stdin - The standard input string.
      snapshots - The list of execution snapshots.
      Returns:
      The generated modern Trace object.
    • createBreakpointsTrace

      public Trace createBreakpointsTrace(String javaSource, Map<Integer,?> breakpointSnapshots)
      Creates a modern trace for a breakpoints map.
      Parameters:
      javaSource - The original Java source code.
      breakpointSnapshots - The mapping of line numbers to snapshots.
      Returns:
      The generated modern Trace object.
    • createBreakpointsTrace

      public Trace createBreakpointsTrace(String javaSource, String stdin, Map<Integer,?> breakpointSnapshots)
      Creates a modern trace for a breakpoints map with standard input.
      Parameters:
      javaSource - The original Java source code.
      stdin - The standard input string.
      breakpointSnapshots - The mapping of line numbers to snapshots.
      Returns:
      The generated modern Trace object.
    • createStep

      public Step createStep(ExecutionSnapshot snapshot, int stepNumber, boolean isMultiFile)
      Converts an individual ExecutionSnapshot into a Step.
      Parameters:
      snapshot - The execution snapshot.
      stepNumber - The 1-based step sequence number.
      isMultiFile - True if file path attributes should be serialized.
      Returns:
      The converted Step.