-
Notifications
You must be signed in to change notification settings - Fork 13
/
java.rs
32 lines (25 loc) · 934 Bytes
/
java.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use genco::fmt;
use genco::prelude::*;
fn main() -> anyhow::Result<()> {
let car = &java::import("se.tedro", "Car");
let list = &java::import("java.util", "List");
let array_list = &java::import("java.util", "ArrayList");
let tokens = quote! {
public class HelloWorld {
public static void main(String[] args) {
$list<$car> cars = new $array_list<$car>();
cars.add(new $car("Volvo"));
cars.add(new $car("Audi"));
for ($car car : cars) {
System.out.println(car);
}
}
}
};
let stdout = std::io::stdout();
let mut w = fmt::IoWriter::new(stdout.lock());
let fmt = fmt::Config::from_lang::<Java>().with_newline("\n\r");
let config = java::Config::default().with_package("se.tedro");
tokens.format_file(&mut w.as_formatter(&fmt), &config)?;
Ok(())
}