oo_bindgen/backend/java/api/
doc.rs1use crate::backend::*;
2use crate::model::*;
3
4use super::conversion::*;
5
6pub(crate) fn javadoc_print(f: &mut dyn Printer, doc: &Doc<Validated>) -> FormattingResult<()> {
7 f.newline()?;
8 docstring_print(f, &doc.brief)?;
9
10 for detail in &doc.details {
11 f.newline()?;
12
13 match detail {
14 DocParagraph::Details(docstring) => {
15 f.writeln("<p>")?;
16 docstring_print(f, docstring)?;
17 f.write("</p>")?;
18 }
19 DocParagraph::Warning(docstring) => {
20 f.writeln("<p><b>Warning:</b> ")?;
21 docstring_print(f, docstring)?;
22 f.write("</p>")?;
23 }
24 }
25 }
26
27 Ok(())
28}
29
30pub(crate) fn docstring_print(
31 f: &mut dyn Printer,
32 docstring: &DocString<Validated>,
33) -> FormattingResult<()> {
34 for el in docstring.elements() {
35 match el {
36 DocStringElement::Text(text) => f.write(text)?,
37 DocStringElement::Null => f.write("{@code null}")?,
38 DocStringElement::Iterator => f.write("{@link java.util.List}")?,
39 DocStringElement::Reference(reference) => reference_print(f, reference)?,
40 }
41 }
42
43 Ok(())
44}
45
46fn reference_print(f: &mut dyn Printer, reference: &Validated) -> FormattingResult<()> {
47 match reference {
48 Validated::Argument(param_name) => {
49 f.write(&format!("{{@code {}}}", param_name.mixed_case()))?
50 }
51 Validated::Class(class) => {
52 f.write(&format!("{{@link {}}}", class.name.camel_case()))?;
53 }
54 Validated::ClassMethod(class, method_name, _) => {
55 f.write(&format!(
56 "{{@link {}#{}}}",
57 class.name().camel_case(),
58 method_name.mixed_case()
59 ))?;
60 }
61 Validated::ClassConstructor(class, constructor) => {
62 let params = constructor
63 .function
64 .arguments
65 .iter()
66 .map(|param| param.arg_type.as_java_primitive())
67 .collect::<Vec<_>>()
68 .join(", ");
69
70 let class_name = class.name().camel_case();
71 f.write(&format!("{{@link {class_name}#{class_name}({params})}}"))?;
72 }
73 Validated::ClassDestructor(class, _) => {
74 let method_name = if let DestructionMode::Custom(name) = &class.destruction_mode {
75 name.mixed_case()
76 } else {
77 "close".to_string()
78 };
79
80 f.write(&format!(
81 "{{@link {}#{}}}",
82 class.name().camel_case(),
83 method_name
84 ))?;
85 }
86 Validated::Struct(st) => {
87 f.write(&format!("{{@link {}}}", st.name().camel_case()))?;
88 }
89 Validated::StructField(st, field_name) => {
90 f.write(&format!(
91 "{{@link {}#{}}}",
92 st.name().camel_case(),
93 field_name.mixed_case()
94 ))?;
95 }
96 Validated::Enum(handle) => {
97 f.write(&format!("{{@link {}}}", handle.name.camel_case()))?;
98 }
99 Validated::EnumVariant(handle, variant_name) => {
100 f.write(&format!(
101 "{{@link {}#{}}}",
102 handle.name.camel_case(),
103 variant_name.capital_snake_case()
104 ))?;
105 }
106 Validated::Interface(interface) => {
107 f.write(&format!("{{@link {}}}", interface.name.camel_case()))?;
108 }
109 Validated::InterfaceMethod(interface, callback_name) => {
110 f.write(&format!(
111 "{{@link {}#{}}}",
112 interface.name.camel_case(),
113 callback_name.mixed_case()
114 ))?;
115 }
116 }
117
118 Ok(())
119}