Let generateClassFiles accept multiple arguments

This commit is contained in:
Victorious3 2023-03-24 13:27:29 +01:00
parent 6b767bc09b
commit b55fc71811
17 changed files with 127 additions and 95 deletions

View File

@ -0,0 +1,9 @@
class TestAssign {
assign(x, y) {
x = y;
}
assign2(x, y) {
assign(x, y);
}
}

View File

@ -36,7 +36,11 @@ public class ASTToTargetAST {
return all.stream().map(GenericsResult::new).toList();
}
record Generics(Set<ResultPair<?, ?>> javaGenerics, Set<ResultPair<?, ?>> txGenerics) {}
record Generics(Set<ResultPair<?, ?>> javaGenerics, Set<ResultPair<?, ?>> txGenerics, Set<GenericTypeVar> userDefinedGenerics) {
Generics(Set<ResultPair<?, ?>> javaGenerics, Set<ResultPair<?, ?>> txGenerics) {
this(javaGenerics, txGenerics, Set.of());
}
}
class Sigma {
Map<Method, Generics> computedGenericsOfMethods = new HashMap<>();
@ -140,14 +144,16 @@ public class ASTToTargetAST {
private void methodFindConstraints(
ClassOrInterface owner, Method method,
Set<PairTPHsmallerTPH> simplifiedConstraints,
HashSet<TypePlaceholder> typeVariables,
HashSet<TypePlaceholder> typeVariablesOfClass,
Set<TypePlaceholder> typeVariables,
Set<GenericTypeVar> userDefinedGenericsOfClass,
Set<TypePlaceholder> typeVariablesOfClass,
Set<ResultPair<?, ?>> result,
Map<TypePlaceholder, TypePlaceholder> equality
) {
// Type variables with bounds that are also type variables of the method
for (var typeVariable : new HashSet<>(typeVariables)) {
if (typeVariablesOfClass.contains(typeVariable)) continue;
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
continue;
for (var pair : simplifiedConstraints) {
if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
addToPairs(result, new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
@ -192,7 +198,6 @@ public class ASTToTargetAST {
var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
if (optMethod.isEmpty()) return;
var method = optMethod.get();
var generics = generics(owner, method).javaGenerics();
// transitive and
@ -448,7 +453,8 @@ public class ASTToTargetAST {
// All unbounded type variables (bounds not in method)
outer:
for (var typeVariable : typeVariables) {
if (typeVariablesOfClass.contains(typeVariable)) continue;
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
continue;
for (var pair : result) {
if (pair.getLeft().equals(typeVariable))
continue outer;
@ -463,12 +469,16 @@ public class ASTToTargetAST {
if (pair.right.equals(pair2.left))
continue outer;
}
if (!typeVariablesOfClass.contains(pair.right) && typeVariables.contains(pair.right)) {
if (!classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, pair.right) && typeVariables.contains(pair.right)) {
addToPairs(result, new PairTPHequalRefTypeOrWildcardType(pair.right, OBJECT));
}
}
}
private boolean classHasGeneric(Set<GenericTypeVar> userDefinedGenericsOfClass, Set<TypePlaceholder> typeVariablesOfClass, TypePlaceholder typeVariable) {
return typeVariablesOfClass.contains(typeVariable) || userDefinedGenericsOfClass.stream().anyMatch(g -> g.getName().equals(typeVariable.getName()));
}
private void methodFindTypeVariables(
Method method,
Set<ResultPair<?, ?>> genericsOfClass,
@ -514,7 +524,8 @@ public class ASTToTargetAST {
var generics = new Generics(javaResult, txResult);
computedGenericsOfMethods.put(method, generics);
var genericsOfClass = generics(owner).javaGenerics();
var classGenerics = generics(owner);
var genericsOfClass = classGenerics.javaGenerics();
var simplifiedConstraints = new HashSet<>(this.simplifiedConstraints);
HashSet<TypePlaceholder> txTypeVariables = new HashSet<>();
@ -525,8 +536,8 @@ public class ASTToTargetAST {
methodFindTypeVariables(method, genericsOfClass, javaTypeVariablesOfClass, javaTypeVariables, equality);
methodFindTypeVariables(method, genericsOfClass, txTypeVariablesOfClass, txTypeVariables, txEquality);
methodFindConstraints(owner, method, simplifiedConstraints, javaTypeVariables, javaTypeVariablesOfClass, javaResult, equality);
methodFindConstraints(owner, method, simplifiedConstraints, txTypeVariables, txTypeVariablesOfClass, txResult, txEquality);
methodFindConstraints(owner, method, simplifiedConstraints, javaTypeVariables, classGenerics.userDefinedGenerics, javaTypeVariablesOfClass, javaResult, equality);
methodFindConstraints(owner, method, simplifiedConstraints, txTypeVariables, classGenerics.userDefinedGenerics, txTypeVariablesOfClass, txResult, txEquality);
{ // Java Generics
var referenced = new HashSet<TypePlaceholder>();
@ -949,9 +960,11 @@ public class ASTToTargetAST {
var genericsIter = input.getGenerics().iterator();
if (genericsIter.hasNext()) {
// Add empty set of generics to cache so that it doesn't try to calculate it later
sigma.computedGenericsOfClasses.put(input, new Generics(new HashSet<>(), new HashSet<>()));
var userDefinedGenerics = new HashSet<GenericTypeVar>();
sigma.computedGenericsOfClasses.put(input, new Generics(new HashSet<>(), new HashSet<>(), userDefinedGenerics));
while (genericsIter.hasNext()) {
var next = genericsIter.next();
userDefinedGenerics.add(next);
javaGenerics.addAll(convert(next));
}
} else {
@ -995,7 +1008,7 @@ public class ASTToTargetAST {
}
convertedGenerics.addAll(convert(typeVar));
}
var returnType = sigma.getType(input.getReturnType(), equality);
/*var returnType = sigma.getType(input.getReturnType(), equality);
if ((returnType instanceof GenericRefType refType) && !hasGeneric(convertedGenerics, refType)) {
convertedGenerics.add(new TargetGeneric(refType.getParsedName(), convert(OBJECT)));
}
@ -1004,7 +1017,7 @@ public class ASTToTargetAST {
if (type instanceof GenericRefType refType && !hasGeneric(convertedGenerics, refType)) {
convertedGenerics.add(new TargetGeneric(refType.getParsedName(), convert(OBJECT)));
}
}
}*/
return convertedGenerics;
}

View File

@ -16,7 +16,7 @@ public class GreaterEqualTest {
@BeforeClass
public static void beforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("GreaterEqual.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "GreaterEqual.jav");
classToTest = classFiles.get("GreaterEqual");
instance = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -15,7 +15,7 @@ public class GreaterThanTest {
@BeforeClass
public static void beforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("GreaterThan.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "GreaterThan.jav");
classToTest = classFiles.get("GreaterThan");
instance = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -17,14 +17,12 @@ public class InheritTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classLoader = new ByteArrayClassLoader();
// TODO Box is loaded and has a method called m so it is generating overloads for it
classLoader.loadClass(Path.of(System.getProperty("user.dir"), "/src/test/resources/target/Box.class"));
classToTest = TestCodegen.generateClassFiles("Inherit.jav", classLoader).get("Inherit");
classToTestAA = TestCodegen.generateClassFiles("AA.jav", classLoader).get("AA");
classToTestBB = TestCodegen.generateClassFiles("BB.jav", classLoader).get("BB");
classToTestCC = TestCodegen.generateClassFiles("CC.jav", classLoader).get("CC");
classToTestDD = TestCodegen.generateClassFiles("DD.jav", classLoader).get("DD");
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
classToTestCC = TestCodegen.generateClassFiles(classLoader, "CC.jav").get("CC");
classToTestDD = TestCodegen.generateClassFiles(classLoader, "DD.jav").get("DD");
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit.jav").get("Inherit");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();

View File

@ -16,11 +16,11 @@ public class InheritTest2 {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classLoader = new ByteArrayClassLoader();
classToTest = TestCodegen.generateClassFiles("Inherit2.jav", classLoader).get("Inherit2");
classToTestAA = TestCodegen.generateClassFiles("AA.jav", classLoader).get("AA");
classToTestBB = TestCodegen.generateClassFiles("BB.jav", classLoader).get("BB");
classToTestCC = TestCodegen.generateClassFiles("CC.jav", classLoader).get("CC");
classToTestDD = TestCodegen.generateClassFiles("DD.jav", classLoader).get("DD");
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit2.jav").get("Inherit2");
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
classToTestCC = TestCodegen.generateClassFiles(classLoader, "CC.jav").get("CC");
classToTestDD = TestCodegen.generateClassFiles(classLoader,"DD.jav").get("DD");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();

View File

@ -15,7 +15,7 @@ public class LessEqualTest {
@BeforeClass
public static void beforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("LessEqual.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "LessEqual.jav");
classToTest = classFiles.get("LessEqual");
instance = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -15,7 +15,7 @@ public class LessThanTest {
@BeforeClass
public static void beforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("LessThan.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "LessThan.jav");
classToTest = classFiles.get("LessThan");
instance = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -16,7 +16,7 @@ public class OLTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("OL.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "OL.jav");
classToTest = classFiles.get("OL");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
classToTest1 = classFiles.get("OLMain");

View File

@ -14,7 +14,7 @@ public class PostIncTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("PostIncDec.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "PostIncDec.jav");
classToTest = classFiles.get("PostIncDec");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -14,7 +14,7 @@ public class PreIncTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("PreInc.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "PreInc.jav");
classToTest = classFiles.get("PreInc");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -16,7 +16,7 @@ public class PutTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("Put.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Put.jav");
classToTest = classFiles.get("Put");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -20,6 +20,8 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@ -27,11 +29,11 @@ import java.util.stream.Collectors;
public class TestCodegen {
static final Path outputPath = Path.of(System.getProperty("user.dir"), "src/test/resources/target/");
private static void writeClassFile(String name, byte[] code) throws IOException {
var path = Path.of(System.getProperty("user.dir"), "src/test/resources/target/");
Files.createDirectories(path);
Files.write(path.resolve(name + ".class"), code);
Files.createDirectories(outputPath);
Files.write(outputPath.resolve(name + ".class"), code);
}
public static Class<?> generateClass(TargetClass clazz, IByteArrayClassLoader classLoader) throws IOException {
@ -41,25 +43,29 @@ public class TestCodegen {
return classLoader.loadClass(code);
}
public static Map<String, ? extends Class<?>> generateClassFiles(String filename, IByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/", filename).toFile();
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()));
public static Map<String, ? extends Class<?>> generateClassFiles(IByteArrayClassLoader classLoader, String... files) throws IOException, ClassNotFoundException {
var path = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/");
var filenames = Arrays.stream(files).map(filename -> Path.of(path.toString(), filename).toFile()).toList();
var compiler = new JavaTXCompiler(filenames, List.of(path.toFile(), outputPath.toFile()));
var resultSet = compiler.typeInference();
var sourceFile = compiler.sourceFiles.get(file);
var converter = new ASTToTargetAST(resultSet, sourceFile, classLoader);
var classes = compiler.sourceFiles.get(file).getClasses();
var result = new HashMap<String, Class<?>>();
for (var file : filenames) {
var sourceFile = compiler.sourceFiles.get(file);
var converter = new ASTToTargetAST(resultSet, sourceFile, classLoader);
var classes = compiler.sourceFiles.get(file).getClasses();
var result = classes.stream().map(cli -> {
try {
return generateClass(converter.convert(cli), classLoader);
} catch (IOException exception) {
throw new RuntimeException(exception);
result.putAll(classes.stream().map(cli -> {
try {
return generateClass(converter.convert(cli), classLoader);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}).collect(Collectors.toMap(Class::getName, Function.identity())));
for (var entry : converter.auxiliaries.entrySet()) {
writeClassFile(entry.getKey(), entry.getValue());
}
}).collect(Collectors.toMap(Class::getName, Function.identity()));
for (var entry : converter.auxiliaries.entrySet()) {
writeClassFile(entry.getKey(), entry.getValue());
}
return result;

View File

@ -16,7 +16,7 @@ import static targetast.TestCodegen.generateClassFiles;
public class TestComplete {
@Test
public void applyLambdaTest() throws Exception {
var classFiles = generateClassFiles("applyLambda.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "applyLambda.jav");
var applyLambda = classFiles.get("applyLambda");
var instance = applyLambda.getDeclaredConstructor().newInstance();
var m = applyLambda.getDeclaredMethod("m");
@ -27,7 +27,7 @@ public class TestComplete {
@Test
public void binaryTest() throws Exception {
var classFiles = generateClassFiles("BinaryInMeth.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "BinaryInMeth.jav");
var binaryInMeth = classFiles.get("BinaryInMeth");
var instance = binaryInMeth.getDeclaredConstructor().newInstance();
@ -40,13 +40,13 @@ public class TestComplete {
@Test
public void classGenLamTest() throws Exception {
var classFiles = generateClassFiles("ClassGenLam.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "ClassGenLam.jav");
classFiles.get("ClassGenLam").getDeclaredConstructor().newInstance();
}
@Test
public void facTest() throws Exception {
var classFiles = generateClassFiles("Fac.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Fac.jav");
var fac = classFiles.get("Fac");
var instance = fac.getDeclaredConstructor().newInstance();
@ -56,7 +56,7 @@ public class TestComplete {
@Test
public void facultyTest() throws Exception {
var classFiles = generateClassFiles("Faculty.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Faculty.jav");
var fac = classFiles.get("Faculty");
var constructor = fac.getDeclaredConstructor();
@ -69,7 +69,7 @@ public class TestComplete {
@Test
public void fieldTest() throws Exception {
var classFiles = generateClassFiles("Field.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Field.jav");
var field = classFiles.get("Field");
var instance = field.getDeclaredConstructor().newInstance();
assertEquals(1, field.getFields().length);
@ -77,7 +77,7 @@ public class TestComplete {
@Test
public void fieldTph2Test() throws Exception {
var classFiles = generateClassFiles("FieldTph2.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "FieldTph2.jav");
var fieldtph2 = classFiles.get("FieldTph2");
var instance = fieldtph2.getDeclaredConstructor().newInstance();
@ -91,7 +91,7 @@ public class TestComplete {
@Test
public void fieldTphConsMethTest() throws Exception {
var classFiles = generateClassFiles("FieldTphConsMeth.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "FieldTphConsMeth.jav");
var fieldTphConsMeth = classFiles.get("FieldTphConsMeth");
var ctor = fieldTphConsMeth.getDeclaredConstructor(Object.class);
@ -105,7 +105,7 @@ public class TestComplete {
@Test
public void fieldTphMMethTest() throws Exception {
var classFiles = generateClassFiles("FieldTphMMeth.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "FieldTphMMeth.jav");
var fieldTphMMeth = classFiles.get("FieldTphMMeth");
var ctor = fieldTphMMeth.getDeclaredConstructor(Object.class, Object.class, Boolean.class);
@ -122,37 +122,37 @@ public class TestComplete {
@Test
public void genTest() throws Exception {
var classFiles = generateClassFiles("Gen.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Gen.jav");
}
@Test
public void idTest() throws Exception {
var classFiles = generateClassFiles("Id.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Id.jav");
var instance = classFiles.get("Id").getDeclaredConstructor().newInstance();
}
@Test
public void infTest() throws Exception {
var classFiles = generateClassFiles("Inf.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Inf.jav");
var instance = classFiles.get("Inf").getDeclaredConstructor().newInstance();
// TODO check generics
}
@Test
public void kompTphTest() throws Exception {
var classFiles = generateClassFiles("KompTph.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "KompTph.jav");
var instance = classFiles.get("KompTph").getDeclaredConstructor().newInstance();
}
@Test
public void lambdaCaptureTest() throws Exception {
var classFiles = generateClassFiles("LambdaCapture.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "LambdaCapture.jav");
var instance = classFiles.get("LambdaCapture").getDeclaredConstructor().newInstance();
}
@Test
public void lambdaTest() throws Exception {
var classFiles = generateClassFiles("Lambda.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Lambda.jav");
var classToTest = classFiles.get("Lambda");
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@ -167,21 +167,21 @@ public class TestComplete {
@Test
public void mathStrucInteger() throws Exception {
var classFiles = generateClassFiles("mathStrucInteger.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "mathStrucInteger.jav");
var mathStrucInteger = classFiles.get("mathStrucInteger");
mathStrucInteger.getDeclaredConstructor(Integer.class).newInstance(10);
}
@Test
public void mathStruc() throws Exception {
var classFiles = generateClassFiles("mathStruc.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "mathStruc.jav");
var mathStruc = classFiles.get("mathStruc");
mathStruc.getDeclaredConstructor(Object.class).newInstance("A");
}
@Test
public void matrixOpTest() throws Exception {
var classFiles = generateClassFiles("MatrixOP.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "MatrixOP.jav");
var matrixOP = classFiles.get("MatrixOP");
Vector<Vector<Integer>> vv = new Vector<>();
@ -234,7 +234,7 @@ public class TestComplete {
@Test
public void matrixTest() throws Exception {
var classFiles = generateClassFiles("Matrix.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Matrix.jav");
var matrix = classFiles.get("Matrix");
Vector<Vector<Integer>> vv = new Vector<>();
@ -281,19 +281,19 @@ public class TestComplete {
@Test
public void mergeTest() throws Exception {
var classFiles = generateClassFiles("Merge.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Merge.jav");
var instance = classFiles.get("Merge").getDeclaredConstructor().newInstance();
}
@Test
public void overloadingSortingTest() throws Exception {
var classFiles = generateClassFiles("Sorting.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Sorting.jav");
var instance = classFiles.get("Sorting").getDeclaredConstructor().newInstance();
}
@Test
public void overloadingTest() throws Exception {
var classFiles = generateClassFiles("Overloading.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Overloading.jav");
var overloading = classFiles.get("Overloading");
var overloading2 = classFiles.get("Overloading2");
var instance1 = overloading.getDeclaredConstructor().newInstance();
@ -307,7 +307,7 @@ public class TestComplete {
@Test
public void plusTest() throws Exception {
var classFiles = generateClassFiles("Plus.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Plus.jav");
var plus = classFiles.get("Plus");
var instance = plus.getDeclaredConstructor().newInstance();
@ -320,7 +320,7 @@ public class TestComplete {
@Test
public void relOpsTest() throws Exception {
var classFiles = generateClassFiles("RelOps.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "RelOps.jav");
var relOps = classFiles.get("RelOps");
var instance = relOps.getDeclaredConstructor().newInstance();
@ -330,26 +330,26 @@ public class TestComplete {
@Test
public void simpleCyclesTest() throws Exception {
var classFiles = generateClassFiles("SimpleCycle.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SimpleCycle.jav");
var instance = classFiles.get("SimpleCycle").getDeclaredConstructor().newInstance();
}
@Test
public void subMatTest() throws Exception {
var classFiles = generateClassFiles("SubMatrix.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SubMatrix.jav");
var instance = classFiles.get("SubMatrix").getDeclaredConstructor().newInstance();
}
@Test
public void tphTest() throws Exception {
var classFiles = generateClassFiles("Tph.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Tph.jav");
var tph = classFiles.get("Tph");
var instance = tph.getDeclaredConstructor().newInstance();
}
@Test
public void tph2Test() throws Exception {
var classFiles = generateClassFiles("Tph2.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Tph2.jav");
var tph2 = classFiles.get("Tph2");
var instance = tph2.getDeclaredConstructor().newInstance();
@ -376,7 +376,7 @@ public class TestComplete {
@Test
public void tph3Test() throws Exception {
var classFiles = generateClassFiles("Tph3.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Tph3.jav");
var tph3 = classFiles.get("Tph3");
var instance = tph3.getDeclaredConstructor().newInstance();
var m1 = tph3.getDeclaredMethod("m1", Object.class, Object.class);
@ -402,7 +402,7 @@ public class TestComplete {
@Test
public void tph4Test() throws Exception {
var classFiles = generateClassFiles("Tph4.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Tph4.jav");
var tph4 = classFiles.get("Tph4");
var instance = tph4.getDeclaredConstructor().newInstance();
var m = tph4.getDeclaredMethod("m", Object.class, Object.class);
@ -433,7 +433,7 @@ public class TestComplete {
@Test
public void tph5Test() throws Exception {
var classFiles = generateClassFiles("Tph5.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Tph5.jav");
var tph5 = classFiles.get("Tph5");
var instance = tph5.getDeclaredConstructor().newInstance();
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
@ -461,7 +461,7 @@ public class TestComplete {
@Test
public void tph6Test() throws Exception {
var classFiles = generateClassFiles("Tph6.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Tph6.jav");
var tph5 = classFiles.get("Tph6");
var instance = tph5.getDeclaredConstructor().newInstance();
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
@ -490,7 +490,7 @@ public class TestComplete {
@Test
public void Tph7Test() throws Exception {
var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Tph7.jav");
var classToTest = classFiles.get("Tph7");
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@ -552,56 +552,56 @@ public class TestComplete {
@Test
public void typedIdTest() throws Exception {
var classFiles = generateClassFiles("TypedID.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "TypedID.jav");
var instance = classFiles.get("TypedID").getDeclaredConstructor().newInstance();
}
@Test
public void vectorAddTest() throws Exception {
var classFiles = generateClassFiles("VectorAdd.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "VectorAdd.jav");
var instance = classFiles.get("VectorAdd").getDeclaredConstructor().newInstance();
}
@Test
public void vectorSuperTest() throws Exception {
var classFiles = generateClassFiles("VectorSuper.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "VectorSuper.jav");
var instance = classFiles.get("VectorSuper").getDeclaredConstructor().newInstance();
}
@Test
public void yTest() throws Exception {
var classFiles = generateClassFiles("Y.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Y.jav");
var instance = classFiles.get("Y").getDeclaredConstructor().newInstance();
}
@Test
@Ignore("This one isn't working")
public void boxTest() throws Exception {
var classFiles = generateClassFiles("Box.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Box.jav");
var instance = classFiles.get("Box_Main").getDeclaredConstructor().newInstance();
}
@Test
public void cycleTest() throws Exception {
var classFiles = generateClassFiles("Cycle.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Cycle.jav");
var instance = classFiles.get("Cycle").getDeclaredConstructor().newInstance();
}
@Test
public void olFunTest() throws Exception {
var classFiles = generateClassFiles("OLFun.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "OLFun.jav");
var instance = classFiles.get("OLFun").getDeclaredConstructor().newInstance();
}
@Test
public void olFun2Test() throws Exception {
var classFiles = generateClassFiles("OLFun2.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "OLFun2.jav");
var instance = classFiles.get("OLFun2").getDeclaredConstructor().newInstance();
}
@Test
public void pairTest() throws Exception {
var classFiles = generateClassFiles("Pair.jav", new ByteArrayClassLoader());
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Pair.jav");
var instance = classFiles.get("Pair").getDeclaredConstructor().newInstance();
}
}

View File

@ -361,4 +361,10 @@ public class TestGenerics {
public void testVoidMeth() throws Exception {
var result = computeGenerics("TestVoidMeth.jav");
}
@Test
public void testAssign() throws Exception {
// TODO Check generics
var result = computeGenerics("TestAssign.jav");
}
}

View File

@ -15,7 +15,7 @@ public class TphTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("Tph.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Tph.jav");
classToTest = classFiles.get("Tph");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}

View File

@ -14,7 +14,7 @@ public class WhileTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles("While.jav", new ByteArrayClassLoader());
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "While.jav");
classToTest = classFiles.get("While");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}