add expected type infer results. Enables gernation of bytecode
This commit is contained in:
parent
f3dc0cbeb7
commit
4009a28333
@ -4,6 +4,8 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -12,35 +14,41 @@ import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
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.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsFields
|
||||
{
|
||||
|
||||
private String resourcePath;
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourcePath = System.getProperty("user.dir")
|
||||
+ "/src/test/resources/inferWildcards/TestClassWildcardsFields.java";
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsFields.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourcePath) };
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourcePath) };
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
@ -50,6 +58,22 @@ public class TestInferWildcardsFields
|
||||
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
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
@ -96,5 +120,27 @@ public class TestInferWildcardsFields
|
||||
List<ResultSet> typeInference = wildcardsCompiler.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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user