Package cs1302.tracer.serialize
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 Summary
ConstructorsConstructorDescriptionPyTutorSerializer(boolean removeMainArgs, boolean inlineStrings, boolean removeMethodThis) Constructs a PyTutorSerializer defaulting to fully qualified type names.PyTutorSerializer(boolean removeMainArgs, boolean inlineStrings, boolean removeMethodThis, TypeStyle typeStyle) Creates an instance of aPyTutorSerializerrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncreateTrace(String javaSource, ExecutionSnapshot snapshot) Create aPyTutorTracemodel representing the given snapshot.createTrace(String javaSource, String stdin, ExecutionSnapshot snapshot) Create aPyTutorTracemodel representing the given snapshot and standard input.createTrace(String javaSource, String stdin, ExecutionSnapshot snapshot, SourceMetadata metadata) Create a snapshot trace using source metadata shared by one breakpoint output.createTrace(String javaSource, String stdin, List<ExecutionSnapshot> snapshots) Create aPyTutorTracemodel representing a chronological sequence of snapshots and standard input.createTrace(String javaSource, List<ExecutionSnapshot> snapshots) Create aPyTutorTracemodel representing a chronological sequence of snapshots.createTraceStep(ExecutionSnapshot snapshot) Create aTraceStepmodel representing the given snapshot.createTraceStep(ExecutionSnapshot snapshot, boolean isMultiFile) Create aTraceStepmodel representing the given snapshot with multi-file setting.final booleanIndicates whether some other object is "equal to" this one.static com.google.gson.GsongetGson()Get the configured Gson instance.static com.google.gson.GsongetGson(boolean pretty) Get the configured Gson instance with optional pretty-printing.final inthashCode()Returns a hash code value for this object.booleanReturns the value of theinlineStringsrecord component.booleanReturns the value of theremoveMainArgsrecord component.booleanReturns the value of theremoveMethodThisrecord component.serialize(String javaSource, ExecutionSnapshot snapshot) Serialize an execution snapshot into the OnlinePythonTutor JSON trace string.serialize(String javaSource, ExecutionSnapshot snapshot, boolean pretty) Serialize an execution snapshot into the OnlinePythonTutor JSON trace string.serialize(String javaSource, String stdin, ExecutionSnapshot snapshot, boolean pretty) Serialize an execution snapshot into the OnlinePythonTutor JSON trace string with stdin.final StringtoString()Returns a string representation of this record class.Returns the value of thetypeStylerecord component.
-
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 aPyTutorSerializerrecord class.- Parameters:
removeMainArgs- the value for theremoveMainArgsrecord componentinlineStrings- the value for theinlineStringsrecord componentremoveMethodThis- the value for theremoveMethodThisrecord componenttypeStyle- the value for thetypeStylerecord 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
Create aPyTutorTracemodel 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
Create aPyTutorTracemodel 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
Create aPyTutorTracemodel 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
Create aPyTutorTracemodel 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
Create aTraceStepmodel representing the given snapshot.- Parameters:
snapshot- The snapshot that should be transformed.- Returns:
- The structured TraceStep model.
-
createTraceStep
Create aTraceStepmodel 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
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
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
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
removeMainArgs
public boolean removeMainArgs()Returns the value of theremoveMainArgsrecord component.- Returns:
- the value of the
removeMainArgsrecord component
-
inlineStrings
public boolean inlineStrings()Returns the value of theinlineStringsrecord component.- Returns:
- the value of the
inlineStringsrecord component
-
removeMethodThis
public boolean removeMethodThis()Returns the value of theremoveMethodThisrecord component.- Returns:
- the value of the
removeMethodThisrecord component
-
typeStyle
Returns the value of thetypeStylerecord component.- Returns:
- the value of the
typeStylerecord component
-