Skip to content

Commit

Permalink
Remove indent. ustfmt can properly format the output now that there's…
Browse files Browse the repository at this point in the history
… no macro.
  • Loading branch information
Dirbaio committed Apr 5, 2024
1 parent a3fd4f9 commit 4dc4b84
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion java-spaghetti-gen/src/emit_rust/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ impl<'a> Context<'a> {

pub fn write(&self, out: &mut impl io::Write) -> io::Result<()> {
write_preamble(out)?;
self.module.write(self, "", out)
self.module.write(self, out)
}
}
6 changes: 3 additions & 3 deletions java-spaghetti-gen/src/emit_rust/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a> Field<'a> {
result
}

pub fn emit(&self, context: &Context, indent: &str, mod_: &str, out: &mut impl io::Write) -> io::Result<()> {
pub fn emit(&self, context: &Context, mod_: &str, out: &mut impl io::Write) -> io::Result<()> {
let mut emit_reject_reasons = Vec::new();

if !self.java.is_public() {
Expand Down Expand Up @@ -151,12 +151,12 @@ impl<'a> Field<'a> {

let emit_reject_reasons = emit_reject_reasons; // Freeze
let indent = if emit_reject_reasons.is_empty() {
format!("{} ", indent)
""
} else {
if !context.config.codegen.keep_rejected_emits {
return Ok(());
}
format!("{} // ", indent)
"// "
};

let keywords = format!(
Expand Down
6 changes: 3 additions & 3 deletions java-spaghetti-gen/src/emit_rust/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> Method<'a> {
};
}

pub fn emit(&self, context: &Context, indent: &str, mod_: &str, out: &mut impl io::Write) -> io::Result<()> {
pub fn emit(&self, context: &Context, mod_: &str, out: &mut impl io::Write) -> io::Result<()> {
let mut emit_reject_reasons = Vec::new();

let java_class_method = format!("{}\x1f{}", self.class.path.as_str(), &self.java.name);
Expand Down Expand Up @@ -310,12 +310,12 @@ impl<'a> Method<'a> {

let emit_reject_reasons = emit_reject_reasons; // Freeze
let indent = if emit_reject_reasons.is_empty() {
format!("{} ", indent)
""
} else {
if !context.config.codegen.keep_rejected_emits {
return Ok(());
}
format!("{} // ", indent)
"// "
};
let access = if self.java.is_public() { "pub " } else { "" };
let attributes = (if self.java.deprecated { "#[deprecated] " } else { "" }).to_string();
Expand Down
12 changes: 5 additions & 7 deletions java-spaghetti-gen/src/emit_rust/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ pub(crate) struct Module {
}

impl Module {
pub(crate) fn write(&self, context: &Context, indent: &str, out: &mut impl Write) -> io::Result<()> {
let next_indent = format!("{} ", indent);

pub(crate) fn write(&self, context: &Context, out: &mut impl Write) -> io::Result<()> {
for (name, module) in self.modules.iter() {
writeln!(out)?;

writeln!(out, "{}pub mod {} {{", indent, name)?;
module.write(context, &next_indent[..], out)?;
writeln!(out, "{}}}", indent)?;
writeln!(out, "pub mod {} {{", name)?;
module.write(context, out)?;
writeln!(out, "}}")?;
}

for (_, structure) in self.structs.iter() {
structure.write(context, indent, out)?;
structure.write(context, out)?;
}

Ok(())
Expand Down
19 changes: 6 additions & 13 deletions java-spaghetti-gen/src/emit_rust/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Struct {
Ok(Self { rust, java })
}

pub(crate) fn write(&self, context: &Context, indent: &str, out: &mut impl io::Write) -> io::Result<()> {
pub(crate) fn write(&self, context: &Context, out: &mut impl io::Write) -> io::Result<()> {
writeln!(out)?;

// Ignored access_flags: SUPER, SYNTHETIC, ANNOTATION, ABSTRACT
Expand All @@ -107,16 +107,9 @@ impl Struct {
let attributes = (if self.java.deprecated { "#[deprecated] " } else { "" }).to_string();

if let Some(url) = KnownDocsUrl::from_class(context, self.java.path.as_id()) {
writeln!(out, "{} /// {} {} {}", indent, visibility, keyword, url)?;
writeln!(out, "/// {} {} {}", visibility, keyword, url)?;
} else {
writeln!(
out,
"{} /// {} {} {}",
indent,
visibility,
keyword,
self.java.path.as_str()
)?;
writeln!(out, "/// {} {} {}", visibility, keyword, self.java.path.as_str())?;
}

let rust_name = &self.rust.struct_name;
Expand Down Expand Up @@ -219,14 +212,14 @@ impl Struct {
}
}

method.emit(context, indent, &self.rust.mod_, out)?;
method.emit(context, &self.rust.mod_, out)?;
}

for field in &mut fields {
field.emit(context, indent, &self.rust.mod_, out)?;
field.emit(context, &self.rust.mod_, out)?;
}

writeln!(out, "{}}}", indent)?;
writeln!(out, "}}")?;
Ok(())
}
}

0 comments on commit 4dc4b84

Please sign in to comment.