diff --git a/resources/syntaxtreegenerator/Sealed.ast b/resources/syntaxtreegenerator/Sealed.ast new file mode 100644 index 00000000..24423ca0 --- /dev/null +++ b/resources/syntaxtreegenerator/Sealed.ast @@ -0,0 +1,144 @@ +class Shape { + +Shape(){ + super(()); + } + Shape(){ + super(()); + } + +}class Circle { + +Circle(){ + super(()); + } + Circle(){ + super(()); + } + +}class Rectangle { + +Rectangle(){ + super(()); + } + Rectangle(){ + super(()); + } + +}class TransparentRectangle { + +TransparentRectangle(){ + super(()); + } + TransparentRectangle(){ + super(()); + } + +}class FilledRectangle { + +FilledRectangle(){ + super(()); + } + FilledRectangle(){ + super(()); + } + +}class Square { + +Square(){ + super(()); + } + Square(){ + super(()); + } + +}class WeirdShape { + +WeirdShape(){ + super(()); + } + WeirdShape(){ + super(()); + } + +}class Expr { + +}class ConstantExpr { + + java.lang.Integer i; +ConstantExpr(java.lang.Integer i){ + super(()); + this.i = i; + } + java.lang.Integer i(){ + return this.i; + } + + ConstantExpr(java.lang.Integer i){ + super(()); + this.i = i; + } + +}class PlusExpr { + + Expr a; + Expr b; +PlusExpr(Expr a, Expr b){ + super(()); + this.a = a; + this.b = b; + } + Expr a(){ + return this.a; + } + + Expr b(){ + return this.b; + } + + PlusExpr(Expr a, Expr b){ + super(()); + this.a = a; + this.b = b; + } + +}class TimesExpr { + + Expr a; + Expr b; +TimesExpr(Expr a, Expr b){ + super(()); + this.a = a; + this.b = b; + } + Expr a(){ + return this.a; + } + + Expr b(){ + return this.b; + } + + TimesExpr(Expr a, Expr b){ + super(()); + this.a = a; + this.b = b; + } + +}class NegExpr { + + Expr e; +NegExpr(Expr e){ + super(()); + this.e = e; + } + Expr e(){ + return this.e; + } + + NegExpr(Expr e){ + super(()); + this.e = e; + } + +} \ No newline at end of file diff --git a/resources/syntaxtreegenerator/javFiles/Sealed.jav b/resources/syntaxtreegenerator/javFiles/Sealed.jav new file mode 100644 index 00000000..b7a68e5a --- /dev/null +++ b/resources/syntaxtreegenerator/javFiles/Sealed.jav @@ -0,0 +1,21 @@ +public abstract sealed class Shape + permits Circle, Rectangle, Square, WeirdShape { } + +public final class Circle extends Shape { } + +public sealed class Rectangle extends Shape + permits TransparentRectangle, FilledRectangle { } +public final class TransparentRectangle extends Rectangle { } +public final class FilledRectangle extends Rectangle { } + +public final class Square extends Shape { } + +public non-sealed class WeirdShape extends Shape { } + +public sealed interface Expr + permits ConstantExpr, PlusExpr, TimesExpr, NegExpr { } + +public record ConstantExpr(int i) implements Expr { } +public record PlusExpr(Expr a, Expr b) implements Expr { } +public record TimesExpr(Expr a, Expr b) implements Expr { } +public record NegExpr(Expr e) implements Expr { } \ No newline at end of file diff --git a/src/test/java/syntaxtreegenerator/TestNewFeatures.java b/src/test/java/syntaxtreegenerator/TestNewFeatures.java index 3bf0cfe8..067dc0f4 100644 --- a/src/test/java/syntaxtreegenerator/TestNewFeatures.java +++ b/src/test/java/syntaxtreegenerator/TestNewFeatures.java @@ -69,6 +69,26 @@ public class TestNewFeatures { } } + @Test + public void sealedTest() { + try { + FileInputStream fileIn = new FileInputStream(javFiles.get("Sealed")[1]); + String expectedAST = new String(fileIn.readAllBytes()); + fileIn.close(); + expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH"); + File srcfile = javFiles.get("Sealed")[0]; + JavaTXCompiler compiler = new JavaTXCompiler(srcfile); + String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile))); + resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH"); + System.out.println("Expected:\n" + new String(expectedAST)); + System.out.println("Result:\n" + new String(resultingAST)); + assertEquals("Comparing expected and resulting AST for Sealed.jav", expectedAST, resultingAST); + } catch (Exception exc) { + exc.printStackTrace(); + fail("An error occured while generating the AST for Sealed.jav"); + } + } + @Test public void switchTest() { try {