Record Class PyTutorSerializer

java.lang.Object
java.lang.Record
cs1302.tracer.serialize.PyTutorSerializer
Record Components:
removeMainArgs - True if the args parameter to main should be excluded.
inlineStrings - True if strings should be inlined as literals.
removeMethodThis - True if this references for method calls should be excluded.
typeStyle - The type qualification style (FQN or SIMPLE).

public record PyTutorSerializer(boolean removeMainArgs, boolean inlineStrings, boolean removeMethodThis, TypeStyle typeStyle) extends Record
Container class for methods that help serialize a trace into the OnlinePythonTutor format using Gson.
  • Constructor Details

    • PyTutorSerializer

      public PyTutorSerializer(boolean removeMainArgs, boolean inlineStrings, boolean removeMethodThis)
      Constructs a PyTutorSerializer defaulting to fully qualified type names.
      Parameters:
      removeMainArgs - True if the args parameter to main should be excluded.
      inlineStrings - True if strings should be inlined as literals.
      removeMethodThis - True if this references for method calls should be excluded.
    • PyTutorSerializer

      public PyTutorSerializer(boolean removeMainArgs, boolean inlineStrings, boolean removeMethodThis, TypeStyle typeStyle)
      Creates an instance of a PyTutorSerializer record class.
      Parameters:
      removeMainArgs - the value for the removeMainArgs record component
      inlineStrings - the value for the inlineStrings record component
      removeMethodThis - the value for the removeMethodThis record component
      typeStyle - the value for the typeStyle record component
  • Method Details

    • getGson

      public static com.google.gson.Gson getGson()
      Get the configured Gson instance.
      Returns:
      The Gson instance.
    • getGson

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

      public PyTutorTrace createTrace(String javaSource, ExecutionSnapshot snapshot)
      Create a PyTutorTrace model representing the given snapshot.
      Parameters:
      javaSource - The source code for the program corresponding to the execution snapshot.
      snapshot - The snapshot that should be serialized.
      Returns:
      The structured PyTutorTrace model.
    • createTrace

      public PyTutorTrace createTrace(String javaSource, String stdin, ExecutionSnapshot snapshot)
      Create a PyTutorTrace model representing the given snapshot and standard input.
      Parameters:
      javaSource - The source code for the program corresponding to the execution snapshot.
      stdin - The standard input string.
      snapshot - The snapshot that should be serialized.
      Returns:
      The structured PyTutorTrace model.
    • createTrace

      public PyTutorTrace createTrace(String javaSource, String stdin, ExecutionSnapshot snapshot, SourceMetadata metadata)
      Create a snapshot trace using source metadata shared by one breakpoint output.
      Parameters:
      javaSource - The original source code.
      stdin - The standard input string.
      snapshot - The snapshot that should be serialized.
      metadata - The source metadata parsed once for the output.
      Returns:
      The structured PyTutorTrace model.
    • createTrace

      public PyTutorTrace createTrace(String javaSource, List<ExecutionSnapshot> snapshots)
      Create a PyTutorTrace model representing a chronological sequence of snapshots.
      Parameters:
      javaSource - The source code for the program corresponding to the execution snapshots.
      snapshots - The list of snapshots in chronological order that should be serialized.
      Returns:
      The structured PyTutorTrace model.
    • createTrace

      public PyTutorTrace createTrace(String javaSource, String stdin, List<ExecutionSnapshot> snapshots)
      Create a PyTutorTrace model representing a chronological sequence of snapshots and standard input.
      Parameters:
      javaSource - The source code for the program corresponding to the execution snapshots.
      stdin - The standard input string.
      snapshots - The list of snapshots in chronological order that should be serialized.
      Returns:
      The structured PyTutorTrace model.
    • createTraceStep

      public TraceStep createTraceStep(ExecutionSnapshot snapshot)
      Create a TraceStep model representing the given snapshot.
      Parameters:
      snapshot - The snapshot that should be transformed.
      Returns:
      The structured TraceStep model.
    • createTraceStep

      public TraceStep createTraceStep(ExecutionSnapshot snapshot, boolean isMultiFile)
      Create a TraceStep model representing the given snapshot with multi-file setting.
      Parameters:
      snapshot - The snapshot that should be transformed.
      isMultiFile - Whether to include source file path metadata.
      Returns:
      The structured TraceStep model.
    • serialize

      public String serialize(String javaSource, ExecutionSnapshot snapshot)
      Serialize an execution snapshot into the OnlinePythonTutor JSON trace string.
      Parameters:
      javaSource - The source code for the program corresponding to the execution snapshot.
      snapshot - The snapshot that should be serialized.
      Returns:
      The serialized execution snapshot as a JSON string.
    • serialize

      public String serialize(String javaSource, ExecutionSnapshot snapshot, boolean pretty)
      Serialize an execution snapshot into the OnlinePythonTutor JSON trace string.
      Parameters:
      javaSource - The source code for the program corresponding to the execution snapshot.
      snapshot - The snapshot that should be serialized.
      pretty - True to enable pretty-printing.
      Returns:
      The serialized execution snapshot as a JSON string.
    • serialize

      public String serialize(String javaSource, String stdin, ExecutionSnapshot snapshot, boolean pretty)
      Serialize an execution snapshot into the OnlinePythonTutor JSON trace string with stdin.
      Parameters:
      javaSource - The source code for the program corresponding to the execution snapshot.
      stdin - The standard input string.
      snapshot - The snapshot that should be serialized.
      pretty - True to enable pretty-printing.
      Returns:
      The serialized execution snapshot as a JSON string.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • removeMainArgs

      public boolean removeMainArgs()
      Returns the value of the removeMainArgs record component.
      Returns:
      the value of the removeMainArgs record component
    • inlineStrings

      public boolean inlineStrings()
      Returns the value of the inlineStrings record component.
      Returns:
      the value of the inlineStrings record component
    • removeMethodThis

      public boolean removeMethodThis()
      Returns the value of the removeMethodThis record component.
      Returns:
      the value of the removeMethodThis record component
    • typeStyle

      public TypeStyle typeStyle()
      Returns the value of the typeStyle record component.
      Returns:
      the value of the typeStyle record component