diff --git a/src/compiler/crystal/tools/doc/constant.cr b/src/compiler/crystal/tools/doc/constant.cr index 68e05ac6a36e..e028691dc4ae 100644 --- a/src/compiler/crystal/tools/doc/constant.cr +++ b/src/compiler/crystal/tools/doc/constant.cr @@ -25,10 +25,10 @@ class Crystal::Doc::Constant Highlighter.highlight value.to_s end - Item.def_to_json( - name: {nilable: false}, - value: {nilable: true, stringify: true}, - doc: {nilable: true}, - summary: {nilable: true, property: :formatted_summary}, + JSON.def_to_json( + name: true, + value: {converter: JSON::StringConverter}, + doc: true, + summary: {converter: JSON::StringConverter}, ) end diff --git a/src/compiler/crystal/tools/doc/generator.cr b/src/compiler/crystal/tools/doc/generator.cr index fa70d828ad13..45f393789c7f 100644 --- a/src/compiler/crystal/tools/doc/generator.cr +++ b/src/compiler/crystal/tools/doc/generator.cr @@ -353,10 +353,10 @@ class Crystal::Doc::Generator end record RelativeLocation, filename : String, line_number : Int32, url : String? do - Item.def_to_json( - filename: {nilable: false}, - line_number: {nilable: false}, - url: {nilable: true} + JSON.def_to_json( + filename: true, + line_number: true, + url: true ) end SRC_SEP = "src#{File::SEPARATOR}" diff --git a/src/compiler/crystal/tools/doc/item.cr b/src/compiler/crystal/tools/doc/item.cr index 56eaf056ed59..ef2b5abee8b9 100644 --- a/src/compiler/crystal/tools/doc/item.cr +++ b/src/compiler/crystal/tools/doc/item.cr @@ -6,68 +6,4 @@ module Crystal::Doc::Item def formatted_summary @generator.summary(self) end - - macro def_to_json(type, properties) - Item.def_to_json(nil, {{properties}}) - end - - macro def_to_json(type, **properties) - Item.def_to_json({{type}}, {{properties}}) - end - - macro def_to_json(type, properties) - def to_json({% if type %}value : {{type.id}}, {% end %}json : ::JSON::Builder) - json.object do - {% for key, value in properties %} - {% keyid = (value[:property] || key).id %} - _{{keyid}} = {{ (type ? "value" : "self").id }}.{{keyid}} - - {% unless value[:emit_null] %} - unless _{{keyid}}.nil? - {% end %} - - json.field({{key.id.stringify}}) do - {% if value[:root] %} - {% if value[:emit_null] %} - if _{{keyid}}.nil? - nil.to_json(json) - else - {% end %} - - json.object do - json.field({{value[:root]}}) do - {% end %} - - {% if value[:converter] %} - if _{{keyid}} - {{ value[:converter] }}.to_json(_{{keyid}}, json) - else - nil.to_json(json) - end - {% elsif value[:stringify] %} - _{{keyid}}.to_s.to_json(json) - {% else %} - _{{keyid}}.to_json(json) - {% end %} - - {% if value[:root] %} - {% if value[:emit_null] %} - end - {% end %} - end - end - {% end %} - end - - {% unless value[:emit_null] %} - end - {% end %} - {% end %} - end - end - end - - macro def_to_json(**properties) - Item.def_to_json(nil, {{properties}}) - end end diff --git a/src/compiler/crystal/tools/doc/json_converter.cr b/src/compiler/crystal/tools/doc/json_converter.cr index c83f7c5b051e..7b47353ee64a 100644 --- a/src/compiler/crystal/tools/doc/json_converter.cr +++ b/src/compiler/crystal/tools/doc/json_converter.cr @@ -10,10 +10,10 @@ module Crystal::Doc end end - Item.def_to_json( - repository_name: {nilable: false}, - body: {nilable: false}, - program: {nilable: false} + JSON.def_to_json( + repository_name: true, + body: true, + program: true ) end @@ -26,42 +26,41 @@ module Crystal::Doc end end - Item.def_to_json(Type, - html_id: {nilable: false}, - # json_path: {nilable: false}, - kind: {nilable: true}, - full_name: {nilable: false}, - name: {nilable: false} + JSON.def_to_json(Type, + html_id: true, + kind: true, + full_name: true, + name: true ) - Item.def_to_json(Crystal::Def, - name: {nilable: false}, - args: {nilable: false, converter: JsonConverter}, - double_splat: {nilable: true, converter: JsonConverter}, - splat_index: {nilable: true}, - yields: {nilable: true}, - block_arg: {nilable: true, converter: JsonConverter}, - return_type: {nilable: true, stringify: true}, - visibility: {nilable: false, stringify: true}, - body: {nilable: true, stringify: true}, + JSON.def_to_json(Crystal::Def, + name: true, + args: {converter: JsonConverter}, + double_splat: {converter: JsonConverter}, + splat_index: true, + yields: true, + block_arg: {converter: JsonConverter}, + return_type: {converter: JSON::StringConverter}, + visibility: {converter: JSON::StringConverter}, + body: {converter: JSON::StringConverter}, ) - Item.def_to_json(Crystal::Macro, - name: {nilable: false}, - args: {nilable: false, converter: JsonConverter}, - double_splat: {nilable: true, converter: JsonConverter}, - splat_index: {nilable: true}, - block_arg: {nilable: true, converter: JsonConverter}, - visibility: {nilable: false, stringify: true}, - body: {nilable: true, stringify: true}, + JSON.def_to_json(Crystal::Macro, + name: true, + args: {converter: JsonConverter}, + double_splat: {converter: JsonConverter}, + splat_index: true, + block_arg: {converter: JsonConverter}, + visibility: {converter: JSON::StringConverter}, + body: {converter: JSON::StringConverter}, ) - Item.def_to_json(Crystal::Arg, - name: {nilable: false}, - doc: {nilable: true}, - default_value: {nilable: true, stringify: true}, - external_name: {nilable: false, stringify: true}, - restriction: {nilable: true, stringify: true}, + JSON.def_to_json(Crystal::Arg, + name: true, + doc: true, + default_value: {converter: JSON::StringConverter}, + external_name: {converter: JSON::StringConverter}, + restriction: {converter: JSON::StringConverter}, ) end end diff --git a/src/compiler/crystal/tools/doc/macro.cr b/src/compiler/crystal/tools/doc/macro.cr index 8fd721a9f631..1c485a279c7d 100644 --- a/src/compiler/crystal/tools/doc/macro.cr +++ b/src/compiler/crystal/tools/doc/macro.cr @@ -93,16 +93,16 @@ class Crystal::Doc::Macro @generator.must_include? @macro end - Item.def_to_json( - id: {nilable: false}, - html_id: {nilable: false}, - name: {nilable: false}, - doc: {nilable: true}, - summary: {nilable: true, property: :formatted_summary}, - abstract: {nilable: false, property: :abstract?}, - args: {nilable: true, converter: JsonConverter}, - args_string: {nilable: true, property: :args_to_s}, - source_link: {nilable: true}, - def: {nilable: false, property: :macro, converter: JsonConverter} + JSON.def_to_json( + id: true, + html_id: true, + name: true, + doc: true, + summary: {property: :formatted_summary}, + abstract: {property: :abstract?}, + args: {converter: JsonConverter}, + args_string: {property: :args_to_s}, + source_link: true, + def: {property: :macro, converter: JsonConverter} ) end diff --git a/src/compiler/crystal/tools/doc/method.cr b/src/compiler/crystal/tools/doc/method.cr index 5e66c7a6ed71..9ca2022f17d0 100644 --- a/src/compiler/crystal/tools/doc/method.cr +++ b/src/compiler/crystal/tools/doc/method.cr @@ -203,16 +203,16 @@ class Crystal::Doc::Method !@def.args.empty? || @def.block_arg || @def.yields end - Item.def_to_json( - id: {nilable: false}, - html_id: {nilable: false}, - name: {nilable: false}, - doc: {nilable: true}, - summary: {nilable: true, property: :formatted_summary}, - abstract: {nilable: false, property: :abstract?}, - args: {nilable: true, converter: JsonConverter}, - args_string: {nilable: true, property: :args_to_s}, - source_link: {nilable: true}, - def: {nilable: false, converter: JsonConverter} + JSON.def_to_json( + id: true, + html_id: true, + name: true, + doc: true, + summary: {property: :formatted_summary}, + abstract: {property: :abstract?}, + args: {converter: JsonConverter}, + args_string: {property: :args_to_s}, + source_link: true, + def: {converter: JsonConverter} ) end diff --git a/src/compiler/crystal/tools/doc/type.cr b/src/compiler/crystal/tools/doc/type.cr index 7c145985eacb..02a695255047 100644 --- a/src/compiler/crystal/tools/doc/type.cr +++ b/src/compiler/crystal/tools/doc/type.cr @@ -773,35 +773,35 @@ class Crystal::Doc::Type delegate to_s, inspect, to: @type - Item.def_to_json( - html_id: {nilable: false}, - path: {nilable: false}, - # json_path: {nilable: false}, - kind: {nilable: true}, - full_name: {nilable: false}, - name: {nilable: false}, - abstract: {nilable: false, property: :abstract?}, - superclass: {nilable: true, converter: JsonConverter}, - ancestors: {nilable: false, converter: JsonConverter}, - locations: {nilable: false}, - repository_name: {nilable: false}, - program: {nilable: false, property: :program?}, - enum: {nilable: false, property: :enum?}, - alias: {nilable: false, property: :alias?}, - aliased: {nilable: true, property: :alias_definition, stringify: true}, - const: {nilable: false, property: :const?}, - constants: {nilable: false}, - included_modules: {nilable: false, converter: JsonConverter}, - extended_modules: {nilable: false, converter: JsonConverter}, - subclasses: {nilable: false, converter: JsonConverter}, - including_types: {nilable: false, converter: JsonConverter}, - namespace: {nilable: true, converter: JsonConverter}, - doc: {nilable: true}, - summary: {nilable: true, property: :formatted_summary}, - class_methods: {nilable: false}, - constructors: {nilable: false}, - instance_methods: {nilable: false}, - macros: {nilable: false}, - types: {nilable: false}, + JSON.def_to_json( + html_id: true, + path: true, + # json_path: true, + kind: true, + full_name: true, + name: true, + abstract: {property: :abstract?}, + superclass: {converter: JsonConverter}, + ancestors: {converter: JsonConverter}, + locations: true, + repository_name: true, + program: {property: :program?}, + enum: {property: :enum?}, + alias: {property: :alias?}, + aliased: {property: :alias_definition, converter: JSON::StringConverter}, + const: {property: :const?}, + constants: true, + included_modules: {converter: JsonConverter}, + extended_modules: {converter: JsonConverter}, + subclasses: {converter: JsonConverter}, + including_types: {converter: JsonConverter}, + namespace: {converter: JsonConverter}, + doc: true, + summary: {property: :formatted_summary}, + class_methods: true, + constructors: true, + instance_methods: true, + macros: true, + types: true, ) end