Set language level to Java 17. Add target AST as records

This commit is contained in:
Andreas Stadelmeier 2022-03-29 19:25:01 +02:00
parent c65102d89a
commit dfd12422a6
12 changed files with 152 additions and 2 deletions

15
pom.xml
View File

@ -118,6 +118,14 @@ http://maven.apache.org/maven-v4_0_0.xsd">
</descriptorRefs> </descriptorRefs>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<repositories> <repositories>
@ -129,8 +137,11 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
<compilerArgs>
--enable-preview
</compilerArgs>
<tycho.version>0.23.0</tycho.version> <tycho.version>0.23.0</tycho.version>
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass> <mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
</properties> </properties>

View File

@ -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<TypePlaceholder, TargetType> sigma){
List<TargetConstructor> 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<TypePlaceholder, TargetType> sigma) {
return null;
}
private TargetField convert(Field input, Map<TypePlaceholder, TargetType> sigma) {
return null;
}
private TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> 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;
}
});
}
}

View File

@ -0,0 +1,6 @@
package de.dhbwstuttgart.target.tree;
import de.dhbwstuttgart.target.tree.type.TargetType;
public record MethodParameter(TargetType type, String name) {
}

View File

@ -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<TargetType> implementingInterfaces,
List<TargetConstructor> constructors, List<TargetField> fields, List<TargetMethod> methods) {}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.target.tree;
import java.util.List;
public record TargetConstructor(List<MethodParameter> parameterTypes) {
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.target.tree;
import de.dhbwstuttgart.target.tree.type.TargetType;
public record TargetField(TargetType type, String name) {
}

View File

@ -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<MethodParameter> parameterTypes) {
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.target.tree.type;
import java.util.List;
public record TargetExtendsWildcard(TargetType innerType) implements TargetType{
}

View File

@ -0,0 +1,6 @@
package de.dhbwstuttgart.target.tree.type;
import java.util.List;
public record TargetFunNType(int N, List<TargetRefType> params) implements TargetType {
}

View File

@ -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<TargetType> params) implements TargetType {
}

View File

@ -0,0 +1,4 @@
package de.dhbwstuttgart.target.tree.type;
public record TargetSuperWildcard(TargetType innerType) implements TargetType {
}

View File

@ -0,0 +1,5 @@
package de.dhbwstuttgart.target.tree.type;
public sealed interface TargetType
permits TargetExtendsWildcard, TargetFunNType, TargetRefType, TargetSuperWildcard {
}