1use super::*;
18use crate::common::{SeparatedSeqAccept, Str};
19use crate::cstyle_common::{
20 ModsAccept, TypeArgAccept, delegate_tuple_w, delegate_tuple_ws, delegate_tuple_ww,
21};
22use crate::{Output, Writable, WritableSeq};
23
24impl<O, Type, Expr> Writable<O> for DeclareVarStmt<Type, Expr>
25where
26 O: Output,
27 Type: Writable<O>,
28 Expr: Writable<O>,
29{
30 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
31 Stmt(DeclareParam(&self.0, &self.1)).write_to(output).await
32 }
33}
34
35impl<O, Assert> Writable<O> for AssertStmt<Assert>
36where
37 O: Output,
38 Assert: Writable<O>,
39{
40 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
41 o.write("assert ").await?;
42 self.0.write_to(o).await?;
43 o.write(";\n").await
44 }
45}
46
47delegate_tuple_w!(Stmt);
48
49delegate_tuple_ww!(AssignStmt);
50
51delegate_tuple_w!(ReturnStmt);
52
53delegate_tuple_ww!(AssignExpr);
54
55delegate_tuple_ww!(IfBlock);
56
57delegate_tuple_ww!(Else);
58
59delegate_tuple_w!(Block);
60
61delegate_tuple_ww!(MemberAccess);
62
63impl<O, Mods, Name, Body> Writable<O> for ClassDef<Mods, Name, Body>
64where
65 O: Output,
66 Mods: WritableSeq<O>,
67 Name: Writable<O>,
68 Body: Writable<O>,
69{
70 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
71 self.mods.for_each(&mut ModsAccept(o)).await?;
72 o.write("class ").await?;
73 self.name.write_to(o).await?;
74 o.write(" {\n").await?;
75 self.body.write_to(o).await?;
76 o.write("}\n").await
77 }
78}
79
80impl<O, Mods, Name, Body> Writable<O> for InterfaceDef<Mods, Name, Body>
81where
82 O: Output,
83 Mods: WritableSeq<O>,
84 Name: Writable<O>,
85 Body: Writable<O>,
86{
87 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
88 self.mods.for_each(&mut ModsAccept(o)).await?;
89 o.write("interface ").await?;
90 self.name.write_to(o).await?;
91 o.write(" {\n").await?;
92 self.body.write_to(o).await?;
93 o.write("}\n").await
94 }
95}
96
97impl<O, Expr, Super> Writable<O> for Extends<Expr, Super>
98where
99 O: Output,
100 Expr: Writable<O>,
101 Super: Writable<O>,
102{
103 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
104 self.0.write_to(o).await?;
105 o.write(" extends ").await?;
106 self.1.write_to(o).await
107 }
108}
109
110impl<O, Expr, Ifaces> Writable<O> for Implements<Expr, Ifaces>
111where
112 O: Output,
113 Expr: Writable<O>,
114 Ifaces: WritableSeq<O>,
115{
116 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
117 self.0.write_to(o).await?;
118 self.1
119 .for_each(&mut SeparatedSeqAccept::new(
120 o,
121 Str(" implements "),
122 Str(", "),
123 ))
124 .await
125 }
126}
127
128impl<O> Writable<O> for Modifier
129where
130 O: Output,
131{
132 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
133 output
134 .write(match self {
135 Self::Abstract => "abstract",
136 Self::Default => "default",
137 Self::Final => "final",
138 Self::Native => "native",
139 Self::Private => "private",
140 Self::Protected => "protected",
141 Self::Public => "public",
142 Self::Static => "static",
143 Self::StrictFp => "strictfp",
144 Self::Synchronized => "synchronized",
145 Self::Transient => "transient",
146 Self::Volatile => "volatile",
147 })
148 .await
149 }
150}
151
152impl<O, Name, Args> Writable<O> for FunctionCall<Name, Args>
153where
154 O: Output,
155 Name: Writable<O>,
156 Args: WritableSeq<O>,
157{
158 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
159 self.name.write_to(output).await?;
160 output.write("(").await?;
161 self.args
162 .for_each(&mut SeparatedSeqAccept::comma_separated(output))
163 .await?;
164 output.write(")").await
165 }
166}
167
168impl<O, Name, Args> Writable<O> for ConstructorCall<Name, Args>
169where
170 O: Output,
171 Name: Writable<O>,
172 Args: WritableSeq<O>,
173{
174 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
175 output.write("new ").await?;
176 FunctionCall {
177 name: &self.name,
178 args: &self.args,
179 }
180 .write_to(output)
181 .await
182 }
183}
184
185impl<O, Type, Name> Writable<O> for DeclareParam<Type, Name>
186where
187 O: Output,
188 Type: Writable<O>,
189 Name: Writable<O>,
190{
191 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
192 self.0.write_to(output).await?;
193 output.write(" ").await?;
194 self.1.write_to(output).await
195 }
196}
197
198delegate_tuple_ws!(Parameterized);
199
200impl<O, Name> Writable<O> for WithInference<Name>
201where
202 O: Output,
203 Name: Writable<O>,
204{
205 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
206 self.0.write_to(output).await?;
207 output.write("<>").await
208 }
209}
210
211impl<O, Component> Writable<O> for Array<Component>
212where
213 O: Output,
214 Component: Writable<O>,
215{
216 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
217 self.0.write_to(output).await?;
218 output.write("[]").await
219 }
220}
221
222impl<O, VarName, Iter, Body> Writable<O> for EnhancedFor<VarName, Iter, Body>
223where
224 O: Output,
225 VarName: Writable<O>,
226 Iter: Writable<O>,
227 Body: Writable<O>,
228{
229 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
230 output.write("for (").await?;
231 self.var_name.write_to(output).await?;
232 output.write(" : ").await?;
233 self.iter.write_to(output).await?;
234 output.write(") {\n").await?;
235 self.body.write_to(output).await?;
236 output.write("}\n").await
237 }
238}
239
240impl<O, Init, Predicate, Update, Body> Writable<O> for TraditionalFor<Init, Predicate, Update, Body>
241where
242 O: Output,
243 Init: Writable<O>,
244 Predicate: Writable<O>,
245 Update: Writable<O>,
246 Body: Writable<O>,
247{
248 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
249 output.write("for (").await?;
250 self.init.write_to(output).await?;
251 output.write("; ").await?;
252 self.predicate.write_to(output).await?;
253 output.write("; ").await?;
254 self.update.write_to(output).await?;
255 output.write(") {\n").await?;
256 self.body.write_to(output).await?;
257 output.write("}\n").await
258 }
259}
260
261impl<O, Mods, TypeArgs, Name, Args, Throws, Body> Writable<O>
262 for ConstructorDef<Mods, TypeArgs, Name, Args, Throws, Body>
263where
264 O: Output,
265 Mods: WritableSeq<O>,
266 TypeArgs: WritableSeq<O>,
267 Name: Writable<O>,
268 Args: WritableSeq<O>,
269 Throws: WritableSeq<O>,
270 Body: Writable<O>,
271{
272 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
273 self.mods.for_each(&mut ModsAccept(output)).await?;
274 TypeArgAccept::new(output)
275 .write_in_diamond_with_space_after(&self.type_args)
276 .await?;
277 FunctionCall {
278 name: &self.name,
279 args: &self.args,
280 }
281 .write_to(output)
282 .await?;
283 self.throws.for_each(&mut throws_decl(output)).await?;
284 output.write(" {\n").await?;
285 self.body.write_to(output).await?;
286 output.write("}\n\n").await
287 }
288}
289
290impl<O, Mods, TypeArgs, Return, Name, Args, Throws, Body> Writable<O>
291 for FunctionDef<Mods, TypeArgs, Return, Name, Args, Throws, Body>
292where
293 O: Output,
294 Mods: WritableSeq<O>,
295 TypeArgs: WritableSeq<O>,
296 Return: Writable<O>,
297 Name: Writable<O>,
298 Args: WritableSeq<O>,
299 Throws: WritableSeq<O>,
300 Body: Writable<O>,
301{
302 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
303 self.mods.for_each(&mut ModsAccept(output)).await?;
304 TypeArgAccept::new(output)
305 .write_in_diamond_with_space_after(&self.type_args)
306 .await?;
307 self.return_type.write_to(output).await?;
308 output.write(" ").await?;
309 FunctionCall {
310 name: &self.name,
311 args: &self.args,
312 }
313 .write_to(output)
314 .await?;
315 self.throws.for_each(&mut throws_decl(output)).await?;
316 output.write(" {\n").await?;
317 self.body.write_to(output).await?;
318 output.write("}\n\n").await
319 }
320}
321
322fn throws_decl<'o, O>(
323 output: &'o mut O,
324) -> SeparatedSeqAccept<'o, O, Str<&'static str>, Str<&'static str>> {
325 SeparatedSeqAccept::new(output, Str(" throws "), Str(", "))
326}