From 20f60d8b72a27655abef227d3a213946d61c2370 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 31 Jul 2026 11:11:18 +0100 Subject: Make all Java classes final --- .../hobgoblin/compiler/output/lang/java/JavaWriter.java | 2 +- .../hobgoblin/compiler/output/lang/java/JavaWriterTests.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java index 7af7e01..6c7410e 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java @@ -88,7 +88,7 @@ public class JavaWriter implements AutoCloseable { private void writeClassDeclaration(JavaClassDeclaration classDeclaration) throws IOException { writeDocComment(classDeclaration.docComment()); - this.writer.write("public class "); + this.writer.write("public final class "); this.writeIdentifier(classDeclaration.name()); this.writer.write(" "); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java index 9b16328..fe5fa81 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java @@ -37,7 +37,7 @@ public class JavaWriterTests { // Custom area start: com.example.shapes.Rectangle imports // Custom area end: com.example.shapes.Rectangle imports - public class Rectangle { + public final class Rectangle { // Custom area start: com.example.shapes.Rectangle body // Custom area end: com.example.shapes.Rectangle body } @@ -61,7 +61,7 @@ public class JavaWriterTests { var string = write(writer -> writer.writeTypeDeclaration(java)); assertThat(string, equalTo(""" - public class Rectangle { + public final class Rectangle { // Custom area start: Rectangle body // Custom area end: Rectangle body }""" @@ -85,7 +85,7 @@ public class JavaWriterTests { var string = write(writer -> writer.writeTypeDeclaration(java)); assertThat(string, equalTo(""" - public class Rectangle implements com.example.Shape { + public final class Rectangle implements com.example.Shape { // Custom area start: Rectangle body // Custom area end: Rectangle body }""" @@ -107,7 +107,7 @@ public class JavaWriterTests { var string = write(writer -> writer.writeTypeDeclaration(java)); assertThat(string, equalTo(""" - public class Rectangle implements com.example.Shape, com.example.Drawable { + public final class Rectangle implements com.example.Shape, com.example.Drawable { // Custom area start: Rectangle body // Custom area end: Rectangle body }""" @@ -141,7 +141,7 @@ public class JavaWriterTests { var string = write(writer -> writer.writeTypeDeclaration(java)); assertThat(string, equalTo(""" - public class Rectangle { + public final class Rectangle { public void a() { } @@ -167,7 +167,7 @@ public class JavaWriterTests { assertThat(string, equalTo(""" /// A 2D point. - public class Point { + public final class Point { // Custom area start: Point body // Custom area end: Point body }""" -- cgit v1.2.3