diff --git a/pom.xml b/pom.xml index 95b20386f..105ce8776 100644 --- a/pom.xml +++ b/pom.xml @@ -118,6 +118,14 @@ http://maven.apache.org/maven-v4_0_0.xsd"> + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + @@ -129,8 +137,11 @@ http://maven.apache.org/maven-v4_0_0.xsd"> UTF-8 UTF-8 - 1.8 - 1.8 + 17 + 17 + + --enable-preview + 0.23.0 de.dhbwstuttgart.core.ConsoleInterface diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java new file mode 100644 index 000000000..14896b830 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -0,0 +1,70 @@ +package de.dhbwstuttgart.target.generate; + +import de.dhbwstuttgart.syntaxtree.ASTVisitor; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.type.*; +import de.dhbwstuttgart.target.tree.TargetClass; +import de.dhbwstuttgart.target.tree.TargetConstructor; +import de.dhbwstuttgart.target.tree.TargetField; +import de.dhbwstuttgart.target.tree.TargetMethod; +import de.dhbwstuttgart.target.tree.type.TargetRefType; +import de.dhbwstuttgart.target.tree.type.TargetSuperWildcard; +import de.dhbwstuttgart.target.tree.type.TargetType; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class ASTToTargetAST { + + public TargetClass convert(ClassOrInterface input, Map sigma){ + List targetConstructors = new ArrayList<>(); + //TODO constructor conversion -> also reduce syntactic sugar + return new TargetClass(input.getModifiers(),input.getClassName().toString(), sigma.get(input.getSuperClass()), + input.getSuperInterfaces().stream().map(it -> sigma.get(it)).collect(Collectors.toList()), + targetConstructors, + input.getFieldDecl().stream().map(it -> convert(it, sigma)).collect(Collectors.toList()), + input.getMethods().stream().map(it -> convert(it, sigma)).collect(Collectors.toList())); + } + + private TargetMethod convert(Method input, Map sigma) { + return null; + } + + private TargetField convert(Field input, Map sigma) { + return null; + } + + private TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, Map sigma) { + return input.acceptTV(new TypeVisitor<>() { + @Override + public TargetType visit(RefType refType) { + return new TargetRefType(refType.getName().toString(), + refType.getParaList().stream().map((it) -> convert(it, sigma)).collect(Collectors.toList())); + } + + @Override + public TargetType visit(SuperWildcardType superWildcardType) { + return new TargetSuperWildcard(convert(superWildcardType.getInnerType(), sigma)); + } + + @Override + public TargetType visit(TypePlaceholder typePlaceholder) { + return convert(sigma.get(typePlaceholder), sigma); + } + + @Override + public TargetType visit(ExtendsWildcardType extendsWildcardType) { + return null; + } + + @Override + public TargetType visit(GenericRefType genericRefType) { + return null; + } + }); + } +} diff --git a/src/main/java/de/dhbwstuttgart/target/tree/MethodParameter.java b/src/main/java/de/dhbwstuttgart/target/tree/MethodParameter.java new file mode 100644 index 000000000..4ae318281 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/MethodParameter.java @@ -0,0 +1,6 @@ +package de.dhbwstuttgart.target.tree; + +import de.dhbwstuttgart.target.tree.type.TargetType; + +public record MethodParameter(TargetType type, String name) { +} diff --git a/src/main/java/de/dhbwstuttgart/target/tree/TargetClass.java b/src/main/java/de/dhbwstuttgart/target/tree/TargetClass.java new file mode 100644 index 000000000..a78da9d3a --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/TargetClass.java @@ -0,0 +1,10 @@ +package de.dhbwstuttgart.target.tree; + +import de.dhbwstuttgart.target.tree.type.TargetRefType; +import de.dhbwstuttgart.target.tree.type.TargetType; + +import java.util.List; + +public record TargetClass(int modifiers, String qualifiedName, TargetType superType, List implementingInterfaces, + List constructors, List fields, List methods) {} + diff --git a/src/main/java/de/dhbwstuttgart/target/tree/TargetConstructor.java b/src/main/java/de/dhbwstuttgart/target/tree/TargetConstructor.java new file mode 100644 index 000000000..b93219ff5 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/TargetConstructor.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.target.tree; + +import java.util.List; + +public record TargetConstructor(List parameterTypes) { +} + diff --git a/src/main/java/de/dhbwstuttgart/target/tree/TargetField.java b/src/main/java/de/dhbwstuttgart/target/tree/TargetField.java new file mode 100644 index 000000000..cbba1dec3 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/TargetField.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.target.tree; + +import de.dhbwstuttgart.target.tree.type.TargetType; + +public record TargetField(TargetType type, String name) { +} + diff --git a/src/main/java/de/dhbwstuttgart/target/tree/TargetMethod.java b/src/main/java/de/dhbwstuttgart/target/tree/TargetMethod.java new file mode 100644 index 000000000..910c12a02 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/TargetMethod.java @@ -0,0 +1,9 @@ +package de.dhbwstuttgart.target.tree; + +import de.dhbwstuttgart.target.tree.type.TargetType; + +import java.util.List; + +public record TargetMethod(String name, List parameterTypes) { +} + diff --git a/src/main/java/de/dhbwstuttgart/target/tree/type/TargetExtendsWildcard.java b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetExtendsWildcard.java new file mode 100644 index 000000000..b30b85e9c --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetExtendsWildcard.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.target.tree.type; + +import java.util.List; + +public record TargetExtendsWildcard(TargetType innerType) implements TargetType{ +} + diff --git a/src/main/java/de/dhbwstuttgart/target/tree/type/TargetFunNType.java b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetFunNType.java new file mode 100644 index 000000000..c3e86f79e --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetFunNType.java @@ -0,0 +1,6 @@ +package de.dhbwstuttgart.target.tree.type; + +import java.util.List; + +public record TargetFunNType(int N, List params) implements TargetType { +} diff --git a/src/main/java/de/dhbwstuttgart/target/tree/type/TargetRefType.java b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetRefType.java new file mode 100644 index 000000000..1c27cd62c --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetRefType.java @@ -0,0 +1,8 @@ +package de.dhbwstuttgart.target.tree.type; + +import de.dhbwstuttgart.target.tree.type.TargetType; + +import java.util.List; + +public record TargetRefType(String name, List params) implements TargetType { +} diff --git a/src/main/java/de/dhbwstuttgart/target/tree/type/TargetSuperWildcard.java b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetSuperWildcard.java new file mode 100644 index 000000000..421102cba --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetSuperWildcard.java @@ -0,0 +1,4 @@ +package de.dhbwstuttgart.target.tree.type; + +public record TargetSuperWildcard(TargetType innerType) implements TargetType { +} diff --git a/src/main/java/de/dhbwstuttgart/target/tree/type/TargetType.java b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetType.java new file mode 100644 index 000000000..849df99c5 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/target/tree/type/TargetType.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.target.tree.type; + +public sealed interface TargetType + permits TargetExtendsWildcard, TargetFunNType, TargetRefType, TargetSuperWildcard { +}