From 1ef3f22c18659c7b5a104aaa8824854f6623c987 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 24 May 2022 15:42:41 +0200 Subject: [PATCH] Add AST To Target AST emptyClass testcase --- .../target/generate/ASTToTargetAST.java | 6 ++++ .../java/targetast/ASTToTypedTargetAST.java | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/test/java/targetast/ASTToTypedTargetAST.java diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 709a3350..23f04d2b 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.target.generate; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.ASTVisitor; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.Field; @@ -9,6 +10,7 @@ import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.target.tree.*; import de.dhbwstuttgart.target.tree.expression.TargetBlock; import de.dhbwstuttgart.target.tree.type.*; +import de.dhbwstuttgart.typeinference.result.ResultSet; import java.util.ArrayList; import java.util.List; @@ -17,6 +19,10 @@ import java.util.stream.Collectors; public class ASTToTargetAST { + public TargetClass convert(ClassOrInterface input, ResultSet resultSet){ + throw new NotImplementedException(); + } + public TargetClass convert(ClassOrInterface input, Map sigma){ List targetConstructors = new ArrayList<>(); //TODO constructor conversion -> also reduce syntactic sugar diff --git a/src/test/java/targetast/ASTToTypedTargetAST.java b/src/test/java/targetast/ASTToTypedTargetAST.java new file mode 100644 index 00000000..e4c93d1a --- /dev/null +++ b/src/test/java/targetast/ASTToTypedTargetAST.java @@ -0,0 +1,32 @@ +package targetast; + +import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.target.generate.ASTToTargetAST; +import de.dhbwstuttgart.target.tree.TargetClass; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.antlr.v4.runtime.Token; +import org.junit.Test; + +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; + +public class ASTToTypedTargetAST { + + @Test + public void emptyClass(){ + ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), java.util.Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), + new RefType(new JavaClassName("Object"), new NullToken()), false, new ArrayList<>(), new NullToken()); + ResultSet emptyResultSet = new ResultSet(new HashSet<>()); + TargetClass emptyTargetClass = new ASTToTargetAST().convert(emptyClass, emptyResultSet); + assert emptyTargetClass.getName().equals("EmptyClass"); + assert emptyTargetClass.methods().size() == 0; + assert emptyTargetClass.fields().size() == 0; + } + +}