Property definitions

serialization $ InspectSerializer :: defaultinit
# Serialization engine writing the object attributes to strings
private class InspectSerializer
	super CachingSerializer

	# Target writing stream
	var stream: Writer

	redef var current_object = null

	var first_object: nullable Object = null

	redef fun serialize(object)
	do
		if object == null then
			stream.write "null"
		else
			if current_object == null then
				first_object = object
			end

			var last_object = current_object
			current_object = object
			object.accept_inspect_serializer self
			current_object = last_object
		end
	end

	var first_attribute_serialized = false

	redef fun serialize_attribute(name, value)
	do
		if first_attribute_serialized then
			stream.write ", "
		else
			stream.write " "
			first_attribute_serialized = true
		end

		stream.write name
		stream.write ":"

		super
	end

	redef fun serialize_reference(object)
	do
		if cache.has_object(object) then
			# Cycle
			var id = object.object_id
			if inspect_testing then id = cache.id_for(object)

			stream.write "<"
			stream.write object.class_name
			stream.write "#"
			stream.write id.to_s
			stream.write ">"
		else if object != first_object and (not object isa DirectSerializable) then
			# Another object, print class and id only
			var id = object.object_id
			if inspect_testing then id = cache.new_id_for(object)

			stream.write "<"
			stream.write object.class_name
			stream.write "#"
			stream.write id.to_s
			stream.write ">"
		else
			# Main object
			serialize object
		end
	end
end
lib/serialization/inspect.nit:23,1--94,3