Skip to content

Commit c7668f3

Browse files
committed
Add warning comment to all generated files.
1 parent e6565cd commit c7668f3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

java-spaghetti-gen/src/emit/preamble-contents.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// WARNING: This file was autogenerated by java-spaghetti. Any changes to this file may be lost!!!
2-
31
#![allow(unused_imports)]
42
#![allow(non_camel_case_types)] // We map Java inner classes to Outer_Inner
53
#![allow(dead_code)] // We generate structs for private Java types too, just in case.

java-spaghetti-gen/src/util/generated_file.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ pub fn write_generated(context: &emit::Context, path: &impl AsRef<Path>, content
1515
.ok_or_else(|| io_data_error!("{:?} has no parent directory", path))?;
1616
let _ = create_dir_all(dir);
1717

18+
// Determine comment prefix based on file extension
19+
let comment_prefix = match path.extension().and_then(|ext| ext.to_str()) {
20+
Some("rs") => "// ",
21+
Some("java") => "// ",
22+
Some("py") => "# ",
23+
Some("sh") => "# ",
24+
_ => "// ", // Default to // for unknown extensions
25+
};
26+
27+
// Create content with marker comment at the top
28+
let marker_line = format!("{}{}\n", comment_prefix, MARKER_COMMENT);
29+
let full_contents = [marker_line.as_bytes(), contents].concat();
30+
1831
match File::open(path) {
1932
Ok(file) => {
2033
let mut original = BufReader::new(file);
@@ -38,7 +51,7 @@ pub fn write_generated(context: &emit::Context, path: &impl AsRef<Path>, content
3851
);
3952
}
4053

41-
let difference = Difference::find(&mut original, &mut Cursor::new(contents))?;
54+
let difference = Difference::find(&mut original, &mut Cursor::new(&full_contents))?;
4255
match difference {
4356
None => {
4457
context
@@ -69,7 +82,7 @@ pub fn write_generated(context: &emit::Context, path: &impl AsRef<Path>, content
6982
}
7083
};
7184

72-
fs::write(path, contents)
85+
fs::write(path, &full_contents)
7386
}
7487

7588
fn read_line_no_eol(reader: &mut impl BufRead, buffer: &mut String) -> io::Result<usize> {

0 commit comments

Comments
 (0)