add expected type infer results. Enables gernation of bytecode

This commit is contained in:
Till Schnell 2021-04-24 14:14:19 +02:00
parent f3dc0cbeb7
commit 4009a28333

View File

@ -4,6 +4,8 @@ import static org.junit.Assert.assertThat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -12,35 +14,41 @@ import org.hamcrest.CoreMatchers;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils; import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards; import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils; import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsFields public class TestInferWildcardsFields
{ {
private String resourcePath; private String resourceFilePath;
private String resourceDirPath;
@Before @Before
public void setup () { public void setup () {
resourcePath = System.getProperty("user.dir") resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
+ "/src/test/resources/inferWildcards/TestClassWildcardsFields.java"; resourceFilePath = resourceDirPath + "/TestClassWildcardsFields.java";
} }
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException { private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourcePath) }; File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1); return new JavaTXCompiler(files1);
} }
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException { private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourcePath) }; File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1); return new JavaTXCompilerWildcards(files1);
} }
@ -50,6 +58,22 @@ public class TestInferWildcardsFields
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler); return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
} }
private static List<ResultSet> generateExpectedTypeInferResult (JavaTXCompilerWildcards compiler) {
Map<? extends TypePlaceholder, ? extends RefType> tphMap = compiler.getTphMap();
ArrayList<ResultSet> list = new ArrayList<>();
tphMap.forEach( (tph, t) -> {
ResultPair r = new PairTPHequalRefTypeOrWildcardType(tph,
new RefType(new JavaClassName("java.lan.String"), new NullToken()));
HashSet<ResultPair> set = new HashSet<>();
set.add(r);
list.add(new ResultSet(set));
});
return list;
}
@Test @Test
public void testGenerateTph () throws ClassNotFoundException, IOException { public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n"); System.out.println("\n--------- Test Generate TPH --------------\n");
@ -96,5 +120,27 @@ public class TestInferWildcardsFields
List<ResultSet> typeInference = wildcardsCompiler.typeInference(); List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference); System.out.println(typeInference);
List<ResultSet> expectedTypeInferResult = generateExpectedTypeInferResult(wildcardsCompiler);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.hasItems(expectedTypeInferResult.toArray(new ResultSet[] {})));
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.getTphMap();
List<ResultSet> typeinferenceResult = generateExpectedTypeInferResult(wildcardsCompiler);
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = wildcardsCompiler
.getGeneratedGenericResultsForAllSourceFiles(
typeinferenceResult);
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"), typeinferenceResult,
simplifyResultsForAllSourceFiles);
assertThat("Generation Succeeded", null, CoreMatchers.anything());
} }
} }