From 136bccab93e5f79095a5bb4f717db351fa4c5398 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Tue, 16 May 2023 13:31:05 +0200 Subject: [PATCH] Fix type deployment --- pom.xml | 8 ++-- .../typedeployment/TypeInsertPlacer.java | 4 +- src/test/java/TestTypeDeployment.java | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/test/java/TestTypeDeployment.java diff --git a/pom.xml b/pom.xml index 63e8985a..8fe3f636 100644 --- a/pom.xml +++ b/pom.xml @@ -54,8 +54,8 @@ http://maven.apache.org/maven-v4_0_0.xsd"> 3.8.0 --enable-preview - 20 - 20 + 19 + 19 @@ -112,8 +112,8 @@ http://maven.apache.org/maven-v4_0_0.xsd"> - 20 - 20 + 19 + 19 de.dhbwstuttgart.core.ConsoleInterface diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java index 71c1a67c..bbeda06c 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java @@ -55,8 +55,8 @@ class TypeInsertPlacerClass extends AbstractASTWalker{ @Override public void visit(Method method) { this.method = method; - //constraints = generatedGenerics.getMethodConstraintsByID(id); - classConstraints = generatedGenerics.get(method); + constraints = generatedGenerics.get(method); + classConstraints = generatedGenerics.get(cl); if(method.getReturnType() instanceof TypePlaceholder) inserts.add(TypeInsertFactory.createInsertPoints( method.getReturnType(), method.getReturnType().getOffset(), cl, method, results, constraints, classConstraints)); diff --git a/src/test/java/TestTypeDeployment.java b/src/test/java/TestTypeDeployment.java new file mode 100644 index 00000000..bd2f5438 --- /dev/null +++ b/src/test/java/TestTypeDeployment.java @@ -0,0 +1,40 @@ +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.nio.file.Path; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class TestTypeDeployment { + + @Test + public void testTypeDeployment() throws Exception { + var path = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav"); + var file = path.toFile(); + var compiler = new JavaTXCompiler(file, false); + var parsedSource = compiler.sourceFiles.get(file); + var tiResults = compiler.typeInference(); + Set tips = new HashSet<>(); + + for (var sf : compiler.sourceFiles.values()) { + Map bytecode = compiler.generateBytecode(sf, tiResults); + } + + System.out.println(compiler.getGeneratedGenerics()); + + for (int i = 0; i < tiResults.size(); i++) { + ResultSet tiResult = tiResults.get(i); + tips.addAll(TypeInsertFactory.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i))); + for (TypeInsert p : tips) { + System.out.println(p); + } + } + } +}