Merge branch 'unif23' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into Unif23
Conflicts: src/test/java/targetast/TestComplete.java
This commit is contained in:
commit
ce29f4bcf1
@ -1,6 +1,6 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Float;
|
//import java.lang.Float;
|
||||||
//import java.lang.Byte;
|
//import java.lang.Byte;
|
||||||
//import java.lang.Boolean;
|
//import java.lang.Boolean;
|
||||||
|
|
||||||
|
30
resources/bytecode/javFiles/Scalar.jav
Normal file
30
resources/bytecode/javFiles/Scalar.jav
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Float;
|
||||||
|
//import java.lang.Byte;
|
||||||
|
//import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class Scalar extends Vector<Integer> {
|
||||||
|
|
||||||
|
|
||||||
|
/* /statistics auskommentiert
|
||||||
|
Scalar(v) {
|
||||||
|
Integer i;
|
||||||
|
i = 0;
|
||||||
|
while(i < v.size()) {
|
||||||
|
this.add(v.elementAt(i));
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
mul(v) {
|
||||||
|
var ret = 0;
|
||||||
|
var i = 0;
|
||||||
|
while(i < size()) {
|
||||||
|
ret = ret + this.elementAt(i) * v.elementAt(i);
|
||||||
|
i = i+1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
9
resources/insertGenericsJav/TestAssign.jav
Normal file
9
resources/insertGenericsJav/TestAssign.jav
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class TestAssign {
|
||||||
|
assign(x, y) {
|
||||||
|
x = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
assign2(x, y) {
|
||||||
|
assign(x, y);
|
||||||
|
}
|
||||||
|
}
|
@ -717,10 +717,14 @@ public class Codegen {
|
|||||||
.toList());
|
.toList());
|
||||||
|
|
||||||
impl = new TargetMethod(
|
impl = new TargetMethod(
|
||||||
0, name, Set.of(), Set.of(),
|
0, name,
|
||||||
parameters,
|
lambda.block(),
|
||||||
lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType(),
|
new TargetMethod.Signature(
|
||||||
lambda.block()
|
Set.of(),
|
||||||
|
parameters,
|
||||||
|
lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType()
|
||||||
|
),
|
||||||
|
null
|
||||||
);
|
);
|
||||||
generateMethod(impl);
|
generateMethod(impl);
|
||||||
lambdas.put(lambda, impl);
|
lambdas.put(lambda, impl);
|
||||||
@ -758,7 +762,7 @@ public class Codegen {
|
|||||||
|
|
||||||
mv.visitInvokeDynamicInsn("apply", descriptor,
|
mv.visitInvokeDynamicInsn("apply", descriptor,
|
||||||
bootstrap, Type.getType(desugared), handle,
|
bootstrap, Type.getType(desugared), handle,
|
||||||
Type.getType(TargetMethod.getDescriptor(impl.returnType(), lambda.params().stream().map(MethodParameter::type).toArray(TargetType[]::new)))
|
Type.getType(TargetMethod.getDescriptor(impl.signature().returnType(), lambda.params().stream().map(MethodParameter::type).toArray(TargetType[]::new)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -995,8 +999,8 @@ public class Codegen {
|
|||||||
|
|
||||||
private void generateConstructor(TargetConstructor constructor) {
|
private void generateConstructor(TargetConstructor constructor) {
|
||||||
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
||||||
if (!constructor.txGenerics().isEmpty())
|
if (constructor.txGenerics() != null)
|
||||||
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(constructor.getTXSignature())));
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(null, mv, 1);
|
var state = new State(null, mv, 1);
|
||||||
@ -1022,17 +1026,18 @@ public class Codegen {
|
|||||||
private void generateMethod(TargetMethod method) {
|
private void generateMethod(TargetMethod method) {
|
||||||
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
||||||
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
||||||
if (!method.txGenerics().isEmpty())
|
if (method.txSignature() != null) {
|
||||||
mv.visitAttribute(new JavaTXSignatureAttribute(method.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(method.getTXSignature())));
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println(method.getDescriptor());
|
System.out.println(method.getDescriptor());
|
||||||
System.out.println(method.getSignature());
|
System.out.println(method.getSignature());
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(method.returnType(), mv, method.isStatic() ? 0 : 1);
|
var state = new State(method.signature().returnType(), mv, method.isStatic() ? 0 : 1);
|
||||||
for (var param: method.parameters())
|
for (var param: method.signature().parameters())
|
||||||
state.createVariable(param.name(), param.type());
|
state.createVariable(param.name(), param.type());
|
||||||
generate(state, method.block());
|
generate(state, method.block());
|
||||||
if (method.returnType() == null)
|
if (method.signature().returnType() == null)
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
mv.visitMaxs(0, 0);
|
mv.visitMaxs(0, 0);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
@ -1054,8 +1059,8 @@ public class Codegen {
|
|||||||
generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
|
generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
|
||||||
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
||||||
);
|
);
|
||||||
if (!clazz.txGenerics().isEmpty())
|
if (clazz.txGenerics() != null)
|
||||||
cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics())));
|
cw.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(generateSignature(clazz, clazz.txGenerics()))));
|
||||||
|
|
||||||
clazz.fields().forEach(this::generateField);
|
clazz.fields().forEach(this::generateField);
|
||||||
clazz.constructors().forEach(this::generateConstructor);
|
clazz.constructors().forEach(this::generateConstructor);
|
||||||
|
@ -2,13 +2,10 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
|
|
||||||
import org.objectweb.asm.*;
|
import org.objectweb.asm.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class JavaTXSignatureAttribute extends Attribute {
|
public class JavaTXSignatureAttribute extends Attribute {
|
||||||
final String signature;
|
final int signature;
|
||||||
|
|
||||||
protected JavaTXSignatureAttribute(String signature) {
|
protected JavaTXSignatureAttribute(int signature) {
|
||||||
super("JavaTXSignature");
|
super("JavaTXSignature");
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
}
|
}
|
||||||
@ -17,13 +14,13 @@ public class JavaTXSignatureAttribute extends Attribute {
|
|||||||
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
|
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
|
||||||
var data = new byte[length];
|
var data = new byte[length];
|
||||||
System.arraycopy(classReader.b, offset, data, 0, length);
|
System.arraycopy(classReader.b, offset, data, 0, length);
|
||||||
return new JavaTXSignatureAttribute(new String(data, StandardCharsets.UTF_8));
|
return new JavaTXSignatureAttribute(data[0] << 8 | data[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
|
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
|
||||||
var data = new ByteVector();
|
var data = new ByteVector();
|
||||||
data.putUTF8(this.signature);
|
data.putShort(this.signature);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -887,7 +887,7 @@ public class JavaTXCompiler {
|
|||||||
path = new File(outputPath ,sf.getPkgName().replace(".","/")); //add package path to root path
|
path = new File(outputPath ,sf.getPkgName().replace(".","/")); //add package path to root path
|
||||||
}
|
}
|
||||||
|
|
||||||
var converter = new ASTToTargetAST(typeinferenceResult);
|
var converter = new ASTToTargetAST(typeinferenceResult, sf, classLoader);
|
||||||
var generatedClasses = new HashMap<JavaClassName, byte[]>();
|
var generatedClasses = new HashMap<JavaClassName, byte[]>();
|
||||||
for (var clazz : sf.getClasses()) {
|
for (var clazz : sf.getClasses()) {
|
||||||
var codegen = new Codegen(converter.convert(clazz));
|
var codegen = new Codegen(converter.convert(clazz));
|
||||||
|
@ -36,7 +36,11 @@ public class ASTToTargetAST {
|
|||||||
return all.stream().map(GenericsResult::new).toList();
|
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 {
|
class Sigma {
|
||||||
Map<Method, Generics> computedGenericsOfMethods = new HashMap<>();
|
Map<Method, Generics> computedGenericsOfMethods = new HashMap<>();
|
||||||
@ -112,11 +116,23 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
} else if (input.stream().anyMatch(p -> p.getLeft().equals(pair.getLeft()))) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.add(pair);
|
input.add(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addToEquality(Map<TypePlaceholder, TypePlaceholder> equality, TypePlaceholder from, TypePlaceholder to) {
|
||||||
|
for (var entry : new HashSet<>(equality.entrySet())) {
|
||||||
|
if (entry.getValue().equals(from)) {
|
||||||
|
equality.remove(entry.getKey());
|
||||||
|
equality.put(entry.getKey(), to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
equality.put(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
static Set<ResultPair<?, ?>> transitiveClosure(Set<ResultPair<?, ?>> generics) {
|
static Set<ResultPair<?, ?>> transitiveClosure(Set<ResultPair<?, ?>> generics) {
|
||||||
Set<ResultPair<?, ?>> all = new HashSet<>(generics);
|
Set<ResultPair<?, ?>> all = new HashSet<>(generics);
|
||||||
HashSet<ResultPair<?, ?>> toAdd = new HashSet<>();
|
HashSet<ResultPair<?, ?>> toAdd = new HashSet<>();
|
||||||
@ -140,14 +156,17 @@ public class ASTToTargetAST {
|
|||||||
private void methodFindConstraints(
|
private void methodFindConstraints(
|
||||||
ClassOrInterface owner, Method method,
|
ClassOrInterface owner, Method method,
|
||||||
Set<PairTPHsmallerTPH> simplifiedConstraints,
|
Set<PairTPHsmallerTPH> simplifiedConstraints,
|
||||||
HashSet<TypePlaceholder> typeVariables,
|
Set<TypePlaceholder> typeVariables,
|
||||||
HashSet<TypePlaceholder> typeVariablesOfClass,
|
Set<GenericTypeVar> userDefinedGenericsOfClass,
|
||||||
|
Set<TypePlaceholder> typeVariablesOfClass,
|
||||||
Set<ResultPair<?, ?>> result,
|
Set<ResultPair<?, ?>> result,
|
||||||
Map<TypePlaceholder, TypePlaceholder> equality
|
Map<TypePlaceholder, TypePlaceholder> equality
|
||||||
) {
|
) {
|
||||||
// Type variables with bounds that are also type variables of the method
|
// Type variables with bounds that are also type variables of the method
|
||||||
for (var typeVariable : new HashSet<>(typeVariables)) {
|
for (var typeVariable : new HashSet<>(typeVariables)) {
|
||||||
if (typeVariablesOfClass.contains(typeVariable)) continue;
|
typeVariable = equality.getOrDefault(typeVariable, typeVariable);
|
||||||
|
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
|
||||||
|
continue;
|
||||||
for (var pair : simplifiedConstraints) {
|
for (var pair : simplifiedConstraints) {
|
||||||
if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
|
if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
|
||||||
addToPairs(result, new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
addToPairs(result, new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
||||||
@ -192,7 +211,6 @@ public class ASTToTargetAST {
|
|||||||
var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
|
var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
|
||||||
if (optMethod.isEmpty()) return;
|
if (optMethod.isEmpty()) return;
|
||||||
var method = optMethod.get();
|
var method = optMethod.get();
|
||||||
|
|
||||||
var generics = generics(owner, method).javaGenerics();
|
var generics = generics(owner, method).javaGenerics();
|
||||||
|
|
||||||
// transitive and
|
// transitive and
|
||||||
@ -448,7 +466,8 @@ public class ASTToTargetAST {
|
|||||||
// All unbounded type variables (bounds not in method)
|
// All unbounded type variables (bounds not in method)
|
||||||
outer:
|
outer:
|
||||||
for (var typeVariable : typeVariables) {
|
for (var typeVariable : typeVariables) {
|
||||||
if (typeVariablesOfClass.contains(typeVariable)) continue;
|
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
|
||||||
|
continue;
|
||||||
for (var pair : result) {
|
for (var pair : result) {
|
||||||
if (pair.getLeft().equals(typeVariable))
|
if (pair.getLeft().equals(typeVariable))
|
||||||
continue outer;
|
continue outer;
|
||||||
@ -463,12 +482,16 @@ public class ASTToTargetAST {
|
|||||||
if (pair.right.equals(pair2.left))
|
if (pair.right.equals(pair2.left))
|
||||||
continue outer;
|
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));
|
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(
|
private void methodFindTypeVariables(
|
||||||
Method method,
|
Method method,
|
||||||
Set<ResultPair<?, ?>> genericsOfClass,
|
Set<ResultPair<?, ?>> genericsOfClass,
|
||||||
@ -514,7 +537,9 @@ public class ASTToTargetAST {
|
|||||||
var generics = new Generics(javaResult, txResult);
|
var generics = new Generics(javaResult, txResult);
|
||||||
computedGenericsOfMethods.put(method, generics);
|
computedGenericsOfMethods.put(method, generics);
|
||||||
|
|
||||||
var genericsOfClass = generics(owner).javaGenerics();
|
var classGenerics = generics(owner);
|
||||||
|
var genericsOfClass = classGenerics.javaGenerics();
|
||||||
|
var txGenericsOfClass = classGenerics.txGenerics();
|
||||||
var simplifiedConstraints = new HashSet<>(this.simplifiedConstraints);
|
var simplifiedConstraints = new HashSet<>(this.simplifiedConstraints);
|
||||||
|
|
||||||
HashSet<TypePlaceholder> txTypeVariables = new HashSet<>();
|
HashSet<TypePlaceholder> txTypeVariables = new HashSet<>();
|
||||||
@ -523,10 +548,10 @@ public class ASTToTargetAST {
|
|||||||
HashSet<TypePlaceholder> javaTypeVariablesOfClass = new HashSet<>();
|
HashSet<TypePlaceholder> javaTypeVariablesOfClass = new HashSet<>();
|
||||||
|
|
||||||
methodFindTypeVariables(method, genericsOfClass, javaTypeVariablesOfClass, javaTypeVariables, equality);
|
methodFindTypeVariables(method, genericsOfClass, javaTypeVariablesOfClass, javaTypeVariables, equality);
|
||||||
methodFindTypeVariables(method, genericsOfClass, txTypeVariablesOfClass, txTypeVariables, txEquality);
|
methodFindTypeVariables(method, txGenericsOfClass, txTypeVariablesOfClass, txTypeVariables, txEquality);
|
||||||
|
|
||||||
methodFindConstraints(owner, method, simplifiedConstraints, javaTypeVariables, javaTypeVariablesOfClass, javaResult, equality);
|
methodFindConstraints(owner, method, simplifiedConstraints, javaTypeVariables, classGenerics.userDefinedGenerics, javaTypeVariablesOfClass, javaResult, equality);
|
||||||
methodFindConstraints(owner, method, simplifiedConstraints, txTypeVariables, txTypeVariablesOfClass, txResult, txEquality);
|
methodFindConstraints(owner, method, simplifiedConstraints, txTypeVariables, classGenerics.userDefinedGenerics, txTypeVariablesOfClass, txResult, txEquality);
|
||||||
|
|
||||||
{ // Java Generics
|
{ // Java Generics
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
var referenced = new HashSet<TypePlaceholder>();
|
||||||
@ -562,7 +587,6 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(method.name + ": " + txResult + " & " + javaResult);
|
System.out.println(method.name + ": " + txResult + " & " + javaResult);
|
||||||
|
|
||||||
return generics;
|
return generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,14 +607,14 @@ public class ASTToTargetAST {
|
|||||||
if (left.equals(tph)) {
|
if (left.equals(tph)) {
|
||||||
var pair = new PairTPHsmallerTPH(tph, right);
|
var pair = new PairTPHsmallerTPH(tph, right);
|
||||||
if (!generics.contains(pair)) {
|
if (!generics.contains(pair)) {
|
||||||
generics.add(pair);
|
addToPairs(generics, pair);
|
||||||
findAllBounds(right, generics, equality);
|
findAllBounds(right, generics, equality);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
generics.add(new PairTPHequalRefTypeOrWildcardType(tph, OBJECT));
|
addToPairs(generics, new PairTPHequalRefTypeOrWildcardType(tph, OBJECT));
|
||||||
} else if (type instanceof RefType refType) {
|
} else if (type instanceof RefType refType) {
|
||||||
refType.getParaList().forEach(t -> findAllBounds(t, generics, equality));
|
refType.getParaList().forEach(t -> findAllBounds(t, generics, equality));
|
||||||
}
|
}
|
||||||
@ -610,33 +634,32 @@ public class ASTToTargetAST {
|
|||||||
findAllBounds(field.getType(), txResult, txEquality);
|
findAllBounds(field.getType(), txResult, txEquality);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Java Generics
|
var referenced = new HashSet<TypePlaceholder>();
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
eliminateCycles(javaResult, equality, referenced);
|
||||||
eliminateCycles(javaResult, equality, referenced);
|
eliminateInfima(javaResult, equality, referenced);
|
||||||
eliminateInfima(javaResult, equality, referenced);
|
var txReferenced = new HashSet<TypePlaceholder>();
|
||||||
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality, referenced);
|
eliminateInfima(txResult, txEquality, txReferenced);
|
||||||
equalizeTypeVariables(javaResult, equality);
|
|
||||||
}
|
|
||||||
{ // TX Generics
|
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
|
||||||
eliminateInfima(txResult, txEquality, referenced);
|
|
||||||
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality, referenced);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + txResult);
|
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality, referenced);
|
||||||
|
equalizeTypeVariables(javaResult, equality);
|
||||||
|
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality, txReferenced);
|
||||||
|
|
||||||
|
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + txResult + ", " + javaResult);
|
||||||
return generics;
|
return generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
void equalizeTypeVariables(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
void equalizeTypeVariables(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
|
System.out.println(input);
|
||||||
for (var pair : new HashSet<>(input)) {
|
for (var pair : new HashSet<>(input)) {
|
||||||
if (pair instanceof PairTPHsmallerTPH ptph) {
|
if (pair instanceof PairTPHsmallerTPH ptph) {
|
||||||
|
System.out.println(pair + " " + ptph.left.getVariance() + " " + ptph.right.getVariance());
|
||||||
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
|
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
|
||||||
equality.put(ptph.left, ptph.right);
|
addToEquality(equality, ptph.left, ptph.right);
|
||||||
input.remove(ptph);
|
input.remove(ptph);
|
||||||
for (var pair2 : new HashSet<>(input)) {
|
for (var pair2 : new HashSet<>(simplifiedConstraints)) {
|
||||||
if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.right.equals(ptph.left)) {
|
if (pair2.right.equals(ptph.left)) {
|
||||||
input.remove(pair2);
|
simplifiedConstraints.remove(pair2);
|
||||||
addToPairs(input, new PairTPHsmallerTPH(ptph2.left, ptph.right));
|
simplifiedConstraints.add(new PairTPHsmallerTPH(pair2.left, ptph.right));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -724,7 +747,7 @@ public class ASTToTargetAST {
|
|||||||
var right = cycle.get(i + 1);
|
var right = cycle.get(i + 1);
|
||||||
var pair = new PairTPHsmallerTPH(left, right);
|
var pair = new PairTPHsmallerTPH(left, right);
|
||||||
input.remove(pair);
|
input.remove(pair);
|
||||||
equality.put(left, newTph);
|
addToEquality(equality, left, newTph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -748,7 +771,7 @@ public class ASTToTargetAST {
|
|||||||
addToPairs(input, new PairTPHsmallerTPH(left, newTph));
|
addToPairs(input, new PairTPHsmallerTPH(left, newTph));
|
||||||
input.removeAll(infima);
|
input.removeAll(infima);
|
||||||
for (var infimum : infima) {
|
for (var infimum : infima) {
|
||||||
equality.put(infimum.right, newTph);
|
addToEquality(equality, infimum.right, newTph);
|
||||||
new HashSet<>(input).forEach(pair -> {
|
new HashSet<>(input).forEach(pair -> {
|
||||||
if (pair.getLeft().equals(infimum.right)) {
|
if (pair.getLeft().equals(infimum.right)) {
|
||||||
input.remove(pair);
|
input.remove(pair);
|
||||||
@ -922,22 +945,22 @@ public class ASTToTargetAST {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<TargetGeneric> convert(Set<ResultPair<?, ?>> result) {
|
Set<TargetGeneric> convert(Set<ResultPair<?, ?>> result, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
return result.stream().map(p -> {
|
return result.stream().map(p -> {
|
||||||
if (p instanceof PairTPHsmallerTPH pair) {
|
if (p instanceof PairTPHsmallerTPH pair) {
|
||||||
return new TargetGeneric(pair.left.getName(), convert(pair.right));
|
return new TargetGeneric(pair.left.getName(), convert(pair.right, equality));
|
||||||
} else if (p instanceof PairTPHequalRefTypeOrWildcardType pair) {
|
} else if (p instanceof PairTPHequalRefTypeOrWildcardType pair) {
|
||||||
return new TargetGeneric(pair.left.getName(), convert(pair.right));
|
return new TargetGeneric(pair.left.getName(), convert(pair.right, equality));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}).collect(Collectors.toSet());
|
}).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TargetGeneric> convert(GenericTypeVar typeVar) {
|
public List<TargetGeneric> convert(GenericTypeVar typeVar, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
var ret = new ArrayList<TargetGeneric>();
|
var ret = new ArrayList<TargetGeneric>();
|
||||||
for (var bound : typeVar.getBounds()) {
|
for (var bound : typeVar.getBounds()) {
|
||||||
ret.add(new TargetGeneric(typeVar.getName(), convert(bound)));
|
ret.add(new TargetGeneric(typeVar.getName(), convert(bound, equality)));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -949,16 +972,18 @@ public class ASTToTargetAST {
|
|||||||
var genericsIter = input.getGenerics().iterator();
|
var genericsIter = input.getGenerics().iterator();
|
||||||
if (genericsIter.hasNext()) {
|
if (genericsIter.hasNext()) {
|
||||||
// Add empty set of generics to cache so that it doesn't try to calculate it later
|
// 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()) {
|
while (genericsIter.hasNext()) {
|
||||||
var next = genericsIter.next();
|
var next = genericsIter.next();
|
||||||
javaGenerics.addAll(convert(next));
|
userDefinedGenerics.add(next);
|
||||||
|
javaGenerics.addAll(convert(next, sigma.equality));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Generate generics only if there are no user defined ones
|
// Generate generics only if there are no user defined ones
|
||||||
var generics = sigma.generics(input);
|
var generics = sigma.generics(input);
|
||||||
javaGenerics = convert(generics.javaGenerics());
|
javaGenerics = convert(generics.javaGenerics(), sigma.equality);
|
||||||
txGenerics = convert(generics.txGenerics());
|
txGenerics = convert(generics.txGenerics(), sigma.txEquality);
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetBlock fieldInitializer = null;
|
TargetBlock fieldInitializer = null;
|
||||||
@ -975,9 +1000,9 @@ public class ASTToTargetAST {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MethodParameter> convert(ParameterList input) {
|
private List<MethodParameter> convert(ParameterList input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
return input.getFormalparalist().stream()
|
return input.getFormalparalist().stream()
|
||||||
.map(param -> new MethodParameter(convert(param.getType()), param.getName())).toList();
|
.map(param -> new MethodParameter(convert(param.getType(), equality), param.getName())).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasGeneric(Set<TargetGeneric> generics, GenericRefType type) {
|
private boolean hasGeneric(Set<TargetGeneric> generics, GenericRefType type) {
|
||||||
@ -985,7 +1010,7 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Set<TargetGeneric> collectMethodGenerics(Set<ResultPair<?, ?>> generics, Map<TypePlaceholder, TypePlaceholder> equality, Method input) {
|
private Set<TargetGeneric> collectMethodGenerics(Set<ResultPair<?, ?>> generics, Map<TypePlaceholder, TypePlaceholder> equality, Method input) {
|
||||||
var convertedGenerics = new HashSet<>(convert(generics));
|
var convertedGenerics = new HashSet<>(convert(generics, equality));
|
||||||
outer:
|
outer:
|
||||||
for (GenericTypeVar typeVar : input.getGenerics()) {
|
for (GenericTypeVar typeVar : input.getGenerics()) {
|
||||||
for (var classGeneric : currentClass.getGenerics()) {
|
for (var classGeneric : currentClass.getGenerics()) {
|
||||||
@ -993,9 +1018,9 @@ public class ASTToTargetAST {
|
|||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
convertedGenerics.addAll(convert(typeVar));
|
convertedGenerics.addAll(convert(typeVar, equality));
|
||||||
}
|
}
|
||||||
var returnType = sigma.getType(input.getReturnType(), equality);
|
/*var returnType = sigma.getType(input.getReturnType(), equality);
|
||||||
if ((returnType instanceof GenericRefType refType) && !hasGeneric(convertedGenerics, refType)) {
|
if ((returnType instanceof GenericRefType refType) && !hasGeneric(convertedGenerics, refType)) {
|
||||||
convertedGenerics.add(new TargetGeneric(refType.getParsedName(), convert(OBJECT)));
|
convertedGenerics.add(new TargetGeneric(refType.getParsedName(), convert(OBJECT)));
|
||||||
}
|
}
|
||||||
@ -1004,7 +1029,7 @@ public class ASTToTargetAST {
|
|||||||
if (type instanceof GenericRefType refType && !hasGeneric(convertedGenerics, refType)) {
|
if (type instanceof GenericRefType refType && !hasGeneric(convertedGenerics, refType)) {
|
||||||
convertedGenerics.add(new TargetGeneric(refType.getParsedName(), convert(OBJECT)));
|
convertedGenerics.add(new TargetGeneric(refType.getParsedName(), convert(OBJECT)));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return convertedGenerics;
|
return convertedGenerics;
|
||||||
}
|
}
|
||||||
@ -1017,12 +1042,13 @@ public class ASTToTargetAST {
|
|||||||
for (var s : all) {
|
for (var s : all) {
|
||||||
sigma = s;
|
sigma = s;
|
||||||
var generics = sigma.generics(currentClass, input);
|
var generics = sigma.generics(currentClass, input);
|
||||||
List<MethodParameter> params = convert(input.getParameterList());
|
List<MethodParameter> params = convert(input.getParameterList(), sigma.equality);
|
||||||
if (parameterSet.stream().noneMatch(p -> p.equals(params))) {
|
if (parameterSet.stream().noneMatch(p -> p.equals(params))) {
|
||||||
|
List<MethodParameter> txParams = convert(input.getParameterList(), sigma.txEquality);
|
||||||
var javaGenerics = collectMethodGenerics(generics.javaGenerics(), sigma.equality, input);
|
var javaGenerics = collectMethodGenerics(generics.javaGenerics(), sigma.equality, input);
|
||||||
var txGenerics = collectMethodGenerics(generics.txGenerics(), sigma.txEquality, input);
|
var txGenerics = collectMethodGenerics(generics.txGenerics(), sigma.txEquality, input);
|
||||||
|
|
||||||
result.add(new TargetConstructor(input.modifier, javaGenerics, txGenerics, params, convert(input.block), fieldInitializer));
|
result.add(new TargetConstructor(input.modifier, javaGenerics, txGenerics, params, txParams, convert(input.block), fieldInitializer));
|
||||||
parameterSet.add(params);
|
parameterSet.add(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1038,16 +1064,18 @@ public class ASTToTargetAST {
|
|||||||
for (var s : all) {
|
for (var s : all) {
|
||||||
sigma = s;
|
sigma = s;
|
||||||
var generics = sigma.generics(currentClass, input);
|
var generics = sigma.generics(currentClass, input);
|
||||||
List<MethodParameter> params = convert(input.getParameterList());
|
List<MethodParameter> params = convert(input.getParameterList(), sigma.equality);
|
||||||
if (parameterSet.stream().noneMatch(p -> p.equals(params))) {
|
if (parameterSet.stream().noneMatch(p -> p.equals(params))) {
|
||||||
|
List<MethodParameter> txParams = convert(input.getParameterList(), sigma.txEquality);
|
||||||
|
|
||||||
var javaGenerics = collectMethodGenerics(generics.javaGenerics(), sigma.equality, input);
|
var javaGenerics = collectMethodGenerics(generics.javaGenerics(), sigma.equality, input);
|
||||||
var txGenerics = collectMethodGenerics(generics.txGenerics(), sigma.txEquality, input);
|
var txGenerics = collectMethodGenerics(generics.txGenerics(), sigma.txEquality, input);
|
||||||
|
|
||||||
result.add(new TargetMethod(
|
result.add(new TargetMethod(
|
||||||
input.modifier,
|
input.modifier,
|
||||||
input.name, javaGenerics, txGenerics, params,
|
input.name, convert(input.block),
|
||||||
convert(input.getReturnType()),
|
new TargetMethod.Signature(javaGenerics, params, convert(input.getReturnType(), sigma.equality)),
|
||||||
convert(input.block)
|
new TargetMethod.Signature(txGenerics, txParams, convert(input.getReturnType(), sigma.txEquality))
|
||||||
));
|
));
|
||||||
parameterSet.add(params);
|
parameterSet.add(params);
|
||||||
}
|
}
|
||||||
@ -1079,7 +1107,11 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
public Map<String, byte[]> auxiliaries = new HashMap<>();
|
public Map<String, byte[]> auxiliaries = new HashMap<>();
|
||||||
|
|
||||||
protected TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input) {
|
protected TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input) {
|
||||||
|
return convert(input, sigma.equality);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
return input.acceptTV(new TypeVisitor<>() {
|
return input.acceptTV(new TypeVisitor<>() {
|
||||||
@Override
|
@Override
|
||||||
public TargetType visit(RefType refType) {
|
public TargetType visit(RefType refType) {
|
||||||
@ -1113,7 +1145,7 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TargetType visit(TypePlaceholder typePlaceholder) {
|
public TargetType visit(TypePlaceholder typePlaceholder) {
|
||||||
return sigma.getTargetType(typePlaceholder, sigma.equality);
|
return sigma.getTargetType(typePlaceholder, equality);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,14 +18,14 @@ public class GenericsResult {
|
|||||||
public Set<ResultPair<?, ?>> get(ClassOrInterface clazz) {
|
public Set<ResultPair<?, ?>> get(ClassOrInterface clazz) {
|
||||||
var generics = this.sigma.computedGenericsOfClasses.get(clazz);
|
var generics = this.sigma.computedGenericsOfClasses.get(clazz);
|
||||||
if (generics == null) return Set.of();
|
if (generics == null) return Set.of();
|
||||||
return generics.txGenerics();
|
return generics.javaGenerics();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Compute generics if not present?
|
// TODO Compute generics if not present?
|
||||||
public Set<ResultPair<?, ?>> get(Method method) {
|
public Set<ResultPair<?, ?>> get(Method method) {
|
||||||
var generics = this.sigma.computedGenericsOfMethods.get(method);
|
var generics = this.sigma.computedGenericsOfMethods.get(method);
|
||||||
if (generics == null) return Set.of();
|
if (generics == null) return Set.of();
|
||||||
return generics.txGenerics();
|
return generics.javaGenerics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz) {
|
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz) {
|
||||||
|
@ -25,7 +25,7 @@ public record TargetClass(int modifiers, String qualifiedName, TargetType superT
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addMethod(int access, String name, Set<TargetGeneric> generics, List<MethodParameter> parameterTypes, TargetType returnType, TargetBlock block) {
|
public void addMethod(int access, String name, Set<TargetGeneric> generics, List<MethodParameter> parameterTypes, TargetType returnType, TargetBlock block) {
|
||||||
this.methods.add(new TargetMethod(access, name, generics, Set.of(), parameterTypes, returnType, block));
|
this.methods.add(new TargetMethod(access, name, block, new TargetMethod.Signature(generics, parameterTypes, returnType), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMethod(int access, String name, List<MethodParameter> parameterTypes, TargetType returnType, TargetBlock block) {
|
public void addMethod(int access, String name, List<MethodParameter> parameterTypes, TargetType returnType, TargetBlock block) {
|
||||||
@ -33,7 +33,7 @@ public record TargetClass(int modifiers, String qualifiedName, TargetType superT
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addConstructor(int access, Set<TargetGeneric> generics, List<MethodParameter> paramterTypes, TargetBlock block) {
|
public void addConstructor(int access, Set<TargetGeneric> generics, List<MethodParameter> paramterTypes, TargetBlock block) {
|
||||||
this.constructors.add(new TargetConstructor(access, generics, Set.of(), paramterTypes, block, null));
|
this.constructors.add(new TargetConstructor(access, generics, Set.of(), paramterTypes, List.of(), block, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addConstructor(int access, List<MethodParameter> paramterTypes, TargetBlock block) {
|
public void addConstructor(int access, List<MethodParameter> paramterTypes, TargetBlock block) {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package de.dhbwstuttgart.target.tree;
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public record TargetConstructor(int access, Set<TargetGeneric> generics, Set<TargetGeneric> txGenerics, List<MethodParameter> parameters, TargetBlock block, TargetBlock fieldInitializer) {
|
public record TargetConstructor(int access, Set<TargetGeneric> generics, Set<TargetGeneric> txGenerics, List<MethodParameter> parameters, List<MethodParameter> txParameters, TargetBlock block, TargetBlock fieldInitializer) {
|
||||||
|
|
||||||
public String getDescriptor() {
|
public String getDescriptor() {
|
||||||
return TargetMethod.getDescriptor(null, parameters.stream().map(MethodParameter::type).toArray(TargetType[]::new));
|
return TargetMethod.getDescriptor(null, parameters.stream().map(MethodParameter::type).toArray(TargetType[]::new));
|
||||||
@ -17,7 +18,7 @@ public record TargetConstructor(int access, Set<TargetGeneric> generics, Set<Tar
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getTXSignature() {
|
public String getTXSignature() {
|
||||||
return TargetMethod.getSignature(txGenerics, parameters, null);
|
return TargetMethod.getSignature(txGenerics, txParameters, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,9 @@ import org.objectweb.asm.Opcodes;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public record TargetMethod(int access, String name, Set<TargetGeneric> generics, Set<TargetGeneric> txGenerics, List<MethodParameter> parameters, TargetType returnType, TargetBlock block) {
|
public record TargetMethod(int access, String name, TargetBlock block, Signature signature, Signature txSignature) {
|
||||||
|
public record Signature(Set<TargetGeneric> generics, List<MethodParameter> parameters, TargetType returnType) { }
|
||||||
|
|
||||||
public static String getDescriptor(TargetType returnType, TargetType... parameters) {
|
public static String getDescriptor(TargetType returnType, TargetType... parameters) {
|
||||||
String ret = "(";
|
String ret = "(";
|
||||||
for (var parameterType : parameters) {
|
for (var parameterType : parameters) {
|
||||||
@ -35,15 +37,15 @@ public record TargetMethod(int access, String name, Set<TargetGeneric> generics,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getDescriptor() {
|
public String getDescriptor() {
|
||||||
return getDescriptor(returnType, parameters.stream().map(MethodParameter::type).toArray(TargetType[]::new));
|
return getDescriptor(signature.returnType, signature.parameters.stream().map(MethodParameter::type).toArray(TargetType[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSignature() {
|
public String getSignature() {
|
||||||
return getSignature(generics, parameters, returnType);
|
return getSignature(signature.generics, signature.parameters, signature.returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTXSignature() {
|
public String getTXSignature() {
|
||||||
return getSignature(txGenerics, parameters, returnType);
|
return getSignature(txSignature.generics, txSignature.parameters, txSignature.returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStatic() {
|
public boolean isStatic() {
|
||||||
|
@ -16,7 +16,7 @@ public class GreaterEqualTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("GreaterEqual");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class GreaterThanTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("GreaterThan");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,12 @@ public class InheritTest {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classLoader = new ByteArrayClassLoader();
|
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(classLoader, "AA.jav").get("AA");
|
||||||
classToTestAA = TestCodegen.generateClassFiles("AA.jav", classLoader).get("AA");
|
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
|
||||||
classToTestBB = TestCodegen.generateClassFiles("BB.jav", classLoader).get("BB");
|
classToTestCC = TestCodegen.generateClassFiles(classLoader, "CC.jav").get("CC");
|
||||||
classToTestCC = TestCodegen.generateClassFiles("CC.jav", classLoader).get("CC");
|
classToTestDD = TestCodegen.generateClassFiles(classLoader, "DD.jav").get("DD");
|
||||||
classToTestDD = TestCodegen.generateClassFiles("DD.jav", classLoader).get("DD");
|
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit.jav").get("Inherit");
|
||||||
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||||
|
@ -16,11 +16,11 @@ public class InheritTest2 {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classLoader = new ByteArrayClassLoader();
|
var classLoader = new ByteArrayClassLoader();
|
||||||
classToTest = TestCodegen.generateClassFiles("Inherit2.jav", classLoader).get("Inherit2");
|
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit2.jav").get("Inherit2");
|
||||||
classToTestAA = TestCodegen.generateClassFiles("AA.jav", classLoader).get("AA");
|
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
|
||||||
classToTestBB = TestCodegen.generateClassFiles("BB.jav", classLoader).get("BB");
|
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
|
||||||
classToTestCC = TestCodegen.generateClassFiles("CC.jav", classLoader).get("CC");
|
classToTestCC = TestCodegen.generateClassFiles(classLoader, "CC.jav").get("CC");
|
||||||
classToTestDD = TestCodegen.generateClassFiles("DD.jav", classLoader).get("DD");
|
classToTestDD = TestCodegen.generateClassFiles(classLoader,"DD.jav").get("DD");
|
||||||
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||||
|
@ -15,7 +15,7 @@ public class LessEqualTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("LessEqual");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class LessThanTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("LessThan");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class OLTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("OL");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
classToTest1 = classFiles.get("OLMain");
|
classToTest1 = classFiles.get("OLMain");
|
||||||
|
@ -14,7 +14,7 @@ public class PostIncTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("PostIncDec");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public class PreIncTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("PreInc");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class PutTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("Put");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -27,11 +29,11 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
|
|
||||||
public class TestCodegen {
|
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 {
|
private static void writeClassFile(String name, byte[] code) throws IOException {
|
||||||
var path = Path.of(System.getProperty("user.dir"), "src/test/resources/target/");
|
Files.createDirectories(outputPath);
|
||||||
Files.createDirectories(path);
|
Files.write(outputPath.resolve(name + ".class"), code);
|
||||||
Files.write(path.resolve(name + ".class"), code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> generateClass(TargetClass clazz, IByteArrayClassLoader classLoader) throws IOException {
|
public static Class<?> generateClass(TargetClass clazz, IByteArrayClassLoader classLoader) throws IOException {
|
||||||
@ -41,25 +43,29 @@ public class TestCodegen {
|
|||||||
return classLoader.loadClass(code);
|
return classLoader.loadClass(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, ? extends Class<?>> generateClassFiles(String filename, IByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException {
|
public static Map<String, ? extends Class<?>> generateClassFiles(IByteArrayClassLoader classLoader, String... files) throws IOException, ClassNotFoundException {
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/", filename).toFile();
|
var path = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/");
|
||||||
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()));
|
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 resultSet = compiler.typeInference();
|
||||||
|
|
||||||
var sourceFile = compiler.sourceFiles.get(file);
|
var result = new HashMap<String, Class<?>>();
|
||||||
var converter = new ASTToTargetAST(resultSet, sourceFile, classLoader);
|
for (var file : filenames) {
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
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 -> {
|
result.putAll(classes.stream().map(cli -> {
|
||||||
try {
|
try {
|
||||||
return generateClass(converter.convert(cli), classLoader);
|
return generateClass(converter.convert(cli), classLoader);
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
throw new RuntimeException(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;
|
return result;
|
||||||
|
@ -16,7 +16,7 @@ import static targetast.TestCodegen.generateClassFiles;
|
|||||||
public class TestComplete {
|
public class TestComplete {
|
||||||
@Test
|
@Test
|
||||||
public void applyLambdaTest() throws Exception {
|
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 applyLambda = classFiles.get("applyLambda");
|
||||||
var instance = applyLambda.getDeclaredConstructor().newInstance();
|
var instance = applyLambda.getDeclaredConstructor().newInstance();
|
||||||
var m = applyLambda.getDeclaredMethod("m");
|
var m = applyLambda.getDeclaredMethod("m");
|
||||||
@ -27,7 +27,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void binaryTest() throws Exception {
|
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 binaryInMeth = classFiles.get("BinaryInMeth");
|
||||||
var instance = binaryInMeth.getDeclaredConstructor().newInstance();
|
var instance = binaryInMeth.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -40,13 +40,13 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void classGenLamTest() throws Exception {
|
public void classGenLamTest() throws Exception {
|
||||||
var classFiles = generateClassFiles("ClassGenLam.jav", new ByteArrayClassLoader());
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "ClassGenLam.jav");
|
||||||
classFiles.get("ClassGenLam").getDeclaredConstructor().newInstance();
|
classFiles.get("ClassGenLam").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void facTest() throws Exception {
|
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 fac = classFiles.get("Fac");
|
||||||
var instance = fac.getDeclaredConstructor().newInstance();
|
var instance = fac.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void facultyTest() throws Exception {
|
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 fac = classFiles.get("Faculty");
|
||||||
var constructor = fac.getDeclaredConstructor();
|
var constructor = fac.getDeclaredConstructor();
|
||||||
@ -69,7 +69,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldTest() throws Exception {
|
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 field = classFiles.get("Field");
|
||||||
var instance = field.getDeclaredConstructor().newInstance();
|
var instance = field.getDeclaredConstructor().newInstance();
|
||||||
assertEquals(1, field.getFields().length);
|
assertEquals(1, field.getFields().length);
|
||||||
@ -77,7 +77,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldTph2Test() throws Exception {
|
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 fieldtph2 = classFiles.get("FieldTph2");
|
||||||
var instance = fieldtph2.getDeclaredConstructor().newInstance();
|
var instance = fieldtph2.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldTphConsMethTest() throws Exception {
|
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 fieldTphConsMeth = classFiles.get("FieldTphConsMeth");
|
||||||
|
|
||||||
var ctor = fieldTphConsMeth.getDeclaredConstructor(Object.class);
|
var ctor = fieldTphConsMeth.getDeclaredConstructor(Object.class);
|
||||||
@ -105,7 +105,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldTphMMethTest() throws Exception {
|
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 fieldTphMMeth = classFiles.get("FieldTphMMeth");
|
||||||
var ctor = fieldTphMMeth.getDeclaredConstructor(Object.class, Object.class, Boolean.class);
|
var ctor = fieldTphMMeth.getDeclaredConstructor(Object.class, Object.class, Boolean.class);
|
||||||
|
|
||||||
@ -122,37 +122,37 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genTest() throws Exception {
|
public void genTest() throws Exception {
|
||||||
var classFiles = generateClassFiles("Gen.jav", new ByteArrayClassLoader());
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Gen.jav");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void idTest() throws Exception {
|
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();
|
var instance = classFiles.get("Id").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infTest() throws Exception {
|
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();
|
var instance = classFiles.get("Inf").getDeclaredConstructor().newInstance();
|
||||||
// TODO check generics
|
// TODO check generics
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void kompTphTest() throws Exception {
|
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();
|
var instance = classFiles.get("KompTph").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lambdaCaptureTest() throws Exception {
|
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();
|
var instance = classFiles.get("LambdaCapture").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lambdaTest() throws Exception {
|
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 classToTest = classFiles.get("Lambda");
|
||||||
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -167,21 +167,21 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mathStrucInteger() throws Exception {
|
public void mathStrucInteger() throws Exception {
|
||||||
var classFiles = generateClassFiles("mathStrucInteger.jav", new ByteArrayClassLoader());
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "mathStrucInteger.jav");
|
||||||
var mathStrucInteger = classFiles.get("mathStrucInteger");
|
var mathStrucInteger = classFiles.get("mathStrucInteger");
|
||||||
mathStrucInteger.getDeclaredConstructor(Integer.class).newInstance(10);
|
mathStrucInteger.getDeclaredConstructor(Integer.class).newInstance(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mathStruc() throws Exception {
|
public void mathStruc() throws Exception {
|
||||||
var classFiles = generateClassFiles("mathStruc.jav", new ByteArrayClassLoader());
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "mathStruc.jav");
|
||||||
var mathStruc = classFiles.get("mathStruc");
|
var mathStruc = classFiles.get("mathStruc");
|
||||||
mathStruc.getDeclaredConstructor(Object.class).newInstance("A");
|
mathStruc.getDeclaredConstructor(Object.class).newInstance("A");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matrixOpTest() throws Exception {
|
public void matrixOpTest() throws Exception {
|
||||||
var classFiles = generateClassFiles("MatrixOP.jav", new ByteArrayClassLoader());
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "MatrixOP.jav");
|
||||||
var matrixOP = classFiles.get("MatrixOP");
|
var matrixOP = classFiles.get("MatrixOP");
|
||||||
|
|
||||||
Vector<Vector<Integer>> vv = new Vector<>();
|
Vector<Vector<Integer>> vv = new Vector<>();
|
||||||
@ -234,7 +234,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matrixTest() throws Exception {
|
public void matrixTest() throws Exception {
|
||||||
var classFiles = generateClassFiles("Matrix.jav", new ByteArrayClassLoader());
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Matrix.jav");
|
||||||
var matrix = classFiles.get("Matrix");
|
var matrix = classFiles.get("Matrix");
|
||||||
|
|
||||||
Vector<Vector<Integer>> vv = new Vector<>();
|
Vector<Vector<Integer>> vv = new Vector<>();
|
||||||
@ -281,25 +281,46 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scalarTest() throws Exception {
|
public void scalarTest() throws Exception {
|
||||||
var classFiles = generateClassFiles("Scalar.jav", new ByteArrayClassLoader());
|
|
||||||
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Scalar.jav");
|
||||||
var scalar = classFiles.get("Scalar");
|
var scalar = classFiles.get("Scalar");
|
||||||
|
|
||||||
|
Vector<Vector<Integer>> vv = new Vector<>();
|
||||||
|
Vector<Integer> v1 = new Vector<> ();
|
||||||
|
v1.addElement(2);
|
||||||
|
v1.addElement(2);
|
||||||
|
|
||||||
|
var instanceOfClass_s1 = scalar.getDeclaredConstructor(Vector.class).newInstance(v1);
|
||||||
|
|
||||||
|
Vector<Integer> v2 = new Vector<> ();
|
||||||
|
v2.addElement(2);
|
||||||
|
v2.addElement(2);
|
||||||
|
|
||||||
|
var instanceOfClass_s2 = scalar.getDeclaredConstructor(Vector.class).newInstance(v2);
|
||||||
|
|
||||||
|
var mul = scalar.getDeclaredMethod("mul", Vector.class);
|
||||||
|
var result = mul.invoke(instanceOfClass_s1, instanceOfClass_s2);
|
||||||
|
System.out.println(instanceOfClass_s1.toString() + " * " + instanceOfClass_s2.toString() + " = " + result.toString());
|
||||||
|
|
||||||
|
assertEquals(result, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeTest() throws Exception {
|
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();
|
var instance = classFiles.get("Merge").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overloadingSortingTest() throws Exception {
|
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();
|
var instance = classFiles.get("Sorting").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overloadingTest() throws Exception {
|
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 overloading = classFiles.get("Overloading");
|
||||||
var overloading2 = classFiles.get("Overloading2");
|
var overloading2 = classFiles.get("Overloading2");
|
||||||
var instance1 = overloading.getDeclaredConstructor().newInstance();
|
var instance1 = overloading.getDeclaredConstructor().newInstance();
|
||||||
@ -313,7 +334,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void plusTest() throws Exception {
|
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 plus = classFiles.get("Plus");
|
||||||
var instance = plus.getDeclaredConstructor().newInstance();
|
var instance = plus.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -326,7 +347,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void relOpsTest() throws Exception {
|
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 relOps = classFiles.get("RelOps");
|
||||||
var instance = relOps.getDeclaredConstructor().newInstance();
|
var instance = relOps.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -336,26 +357,26 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleCyclesTest() throws Exception {
|
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();
|
var instance = classFiles.get("SimpleCycle").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void subMatTest() throws Exception {
|
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();
|
var instance = classFiles.get("SubMatrix").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tphTest() throws Exception {
|
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 tph = classFiles.get("Tph");
|
||||||
var instance = tph.getDeclaredConstructor().newInstance();
|
var instance = tph.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tph2Test() throws Exception {
|
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 tph2 = classFiles.get("Tph2");
|
||||||
var instance = tph2.getDeclaredConstructor().newInstance();
|
var instance = tph2.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -382,7 +403,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tph3Test() throws Exception {
|
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 tph3 = classFiles.get("Tph3");
|
||||||
var instance = tph3.getDeclaredConstructor().newInstance();
|
var instance = tph3.getDeclaredConstructor().newInstance();
|
||||||
var m1 = tph3.getDeclaredMethod("m1", Object.class, Object.class);
|
var m1 = tph3.getDeclaredMethod("m1", Object.class, Object.class);
|
||||||
@ -408,7 +429,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tph4Test() throws Exception {
|
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 tph4 = classFiles.get("Tph4");
|
||||||
var instance = tph4.getDeclaredConstructor().newInstance();
|
var instance = tph4.getDeclaredConstructor().newInstance();
|
||||||
var m = tph4.getDeclaredMethod("m", Object.class, Object.class);
|
var m = tph4.getDeclaredMethod("m", Object.class, Object.class);
|
||||||
@ -439,7 +460,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tph5Test() throws Exception {
|
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 tph5 = classFiles.get("Tph5");
|
||||||
var instance = tph5.getDeclaredConstructor().newInstance();
|
var instance = tph5.getDeclaredConstructor().newInstance();
|
||||||
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
|
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
|
||||||
@ -467,7 +488,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tph6Test() throws Exception {
|
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 tph5 = classFiles.get("Tph6");
|
||||||
var instance = tph5.getDeclaredConstructor().newInstance();
|
var instance = tph5.getDeclaredConstructor().newInstance();
|
||||||
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
|
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
|
||||||
@ -496,7 +517,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void Tph7Test() throws Exception {
|
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 classToTest = classFiles.get("Tph7");
|
||||||
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
@ -558,56 +579,56 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void typedIdTest() throws Exception {
|
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();
|
var instance = classFiles.get("TypedID").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void vectorAddTest() throws Exception {
|
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();
|
var instance = classFiles.get("VectorAdd").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void vectorSuperTest() throws Exception {
|
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();
|
var instance = classFiles.get("VectorSuper").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void yTest() throws Exception {
|
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();
|
var instance = classFiles.get("Y").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("This one isn't working")
|
@Ignore("This one isn't working")
|
||||||
public void boxTest() throws Exception {
|
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();
|
var instance = classFiles.get("Box_Main").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cycleTest() throws Exception {
|
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();
|
var instance = classFiles.get("Cycle").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void olFunTest() throws Exception {
|
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();
|
var instance = classFiles.get("OLFun").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void olFun2Test() throws Exception {
|
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();
|
var instance = classFiles.get("OLFun2").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pairTest() throws Exception {
|
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();
|
var instance = classFiles.get("Pair").getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ public class TestGenerics {
|
|||||||
var anyMethod = result.findMethod("anyMethod");
|
var anyMethod = result.findMethod("anyMethod");
|
||||||
var otherMethod = result.findMethod("otherMethod");
|
var otherMethod = result.findMethod("otherMethod");
|
||||||
var a = result.findField("a");
|
var a = result.findField("a");
|
||||||
|
var b = result.findField("b");
|
||||||
|
|
||||||
var generics = result.genericsResults.get(0);
|
var generics = result.genericsResults.get(0);
|
||||||
assertEquals(1, generics.get(anyMethod).size());
|
assertEquals(1, generics.get(anyMethod).size());
|
||||||
@ -60,7 +61,7 @@ public class TestGenerics {
|
|||||||
var ECK2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, anyMethod);
|
var ECK2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, anyMethod);
|
||||||
var ECKChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
var ECKChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
||||||
assertEquals(ECK1, ECK2);
|
assertEquals(ECK1, ECK2);
|
||||||
assertEquals(ECK2, ECKChain);
|
assertEquals(ECK2, generics.getBounds(b.getType(), result.clazz));
|
||||||
|
|
||||||
var M = generics.getBounds(a.getType(), result.clazz);
|
var M = generics.getBounds(a.getType(), result.clazz);
|
||||||
var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("ECK")), new Bound(false, ASTToTargetAST.OBJECT));
|
var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("ECK")), new Bound(false, ASTToTargetAST.OBJECT));
|
||||||
@ -126,26 +127,22 @@ public class TestGenerics {
|
|||||||
assertEquals(R, RChain);
|
assertEquals(R, RChain);
|
||||||
|
|
||||||
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||||
var OChain = new BoundsList(new Bound(true, TypePlaceholder.of("AB")), new Bound(true, ASTToTargetAST.OBJECT));
|
|
||||||
assertEquals(O, OChain);
|
|
||||||
var AB = generics.getBounds(id.getReturnType(), result.clazz, id);
|
var AB = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||||
|
assertEquals(O, AB);
|
||||||
assertEquals(AB, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(AB, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
||||||
var SChain = new BoundsList(new Bound(true, TypePlaceholder.of("R")), new Bound(false, ASTToTargetAST.OBJECT));
|
assertEquals(S, RChain);
|
||||||
assertEquals(S, SChain);
|
|
||||||
assertEquals(generics.getBounds(setA.getReturnType(), result.clazz, setA), RChain);
|
assertEquals(generics.getBounds(setA.getReturnType(), result.clazz, setA), RChain);
|
||||||
|
|
||||||
var X = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
var X = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||||
var XChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
var XChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
||||||
var YChain = new BoundsList(new Bound(true, TypePlaceholder.of("Y")), new Bound(true, ASTToTargetAST.OBJECT));
|
|
||||||
assertEquals(X, XChain);
|
assertEquals(X, XChain);
|
||||||
assertEquals(Y, YChain);
|
assertEquals(Y, X);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Not implemented")
|
|
||||||
public void testLocalVarLambda() throws Exception {
|
public void testLocalVarLambda() throws Exception {
|
||||||
var result = computeGenerics("TestLocalVarLambda.jav");
|
var result = computeGenerics("TestLocalVarLambda.jav");
|
||||||
// TODO Generics of lambdas
|
// TODO Generics of lambdas
|
||||||
@ -161,33 +158,30 @@ public class TestGenerics {
|
|||||||
|
|
||||||
var generics = result.genericsResults.get(0);
|
var generics = result.genericsResults.get(0);
|
||||||
assertEquals(1, generics.get(result.clazz).size());
|
assertEquals(1, generics.get(result.clazz).size());
|
||||||
assertEquals(3, generics.get(id).size());
|
assertEquals(2, generics.get(id).size());
|
||||||
assertEquals(2, generics.get(m).size());
|
assertEquals(2, generics.get(m).size());
|
||||||
assertEquals(3, generics.get(main).size());
|
assertEquals(3, generics.get(main).size());
|
||||||
|
|
||||||
var M = generics.getBounds(a.getType(), result.clazz);
|
var N = generics.getBounds(a.getType(), result.clazz);
|
||||||
assertEquals(M, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
|
assertEquals(N, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
var P = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||||
var OChain = new BoundsList(new Bound(true, TypePlaceholder.of("P")), new Bound(true, ASTToTargetAST.OBJECT));
|
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||||
assertEquals(O, OChain);
|
assertEquals(P, O);
|
||||||
var AK = generics.getBounds(id.getReturnType(), result.clazz, id);
|
assertEquals(O, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
var AKChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
|
||||||
assertEquals(AK, AKChain);
|
|
||||||
|
|
||||||
// TODO Shouldn't AK and AK2 be the same and on the class?
|
assertEquals(generics.resolve(m.getParameterList().getParameterAt(0).getType()), generics.resolve(m.getReturnType()));
|
||||||
var AK2 = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
var Y = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
var AA = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||||
assertEquals(AK2, AKChain);
|
assertEquals(Y, AA);
|
||||||
assertEquals(Y, AKChain);
|
assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
var AF = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
var AI = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||||
var AG= generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
var AJ = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||||
var AK3 = generics.getBounds(main.getReturnType(), result.clazz, main);
|
var AH = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||||
var AFChain = new BoundsList(new Bound(true, TypePlaceholder.of("AG")), new Bound(true, ASTToTargetAST.OBJECT));
|
assertEquals(AI, AJ);
|
||||||
assertEquals(AF, AFChain);
|
assertEquals(AJ, AH);
|
||||||
assertEquals(AG, AKChain);
|
assertEquals(AH, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(AK3, AKChain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -220,9 +214,10 @@ public class TestGenerics {
|
|||||||
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
||||||
assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
|
System.out.println(otherMethod.getReturnType());
|
||||||
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
|
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
|
||||||
assertEquals(DYX, DYX2);
|
assertEquals(DYX, DYX2);
|
||||||
assertEquals(DYX2, DYXChain);
|
assertEquals(DYX, generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -246,7 +241,7 @@ public class TestGenerics {
|
|||||||
var AA = generics.getBounds(m.getReturnType(), result.clazz, m);
|
var AA = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||||
var AC = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
var AC = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||||
assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(AC, new BoundsList(new Bound(true, TypePlaceholder.of("AD")), new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(AC, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
|
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
|
||||||
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
|
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
|
||||||
@ -297,9 +292,9 @@ public class TestGenerics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("main changes in between runs")
|
|
||||||
public void testTwoArgs2() throws Exception {
|
public void testTwoArgs2() throws Exception {
|
||||||
var result = computeGenerics("TestTwoArgs2.jav");
|
var result = computeGenerics("TestTwoArgs2.jav");
|
||||||
|
// TODO Test generics
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -326,6 +321,7 @@ public class TestGenerics {
|
|||||||
public void testVector() throws Exception {
|
public void testVector() throws Exception {
|
||||||
var result = computeGenerics("TestVector.jav");
|
var result = computeGenerics("TestVector.jav");
|
||||||
var m = result.findMethod("m");
|
var m = result.findMethod("m");
|
||||||
|
var id = result.findMethod("id");
|
||||||
|
|
||||||
var generics = result.genericsResults.get(0);
|
var generics = result.genericsResults.get(0);
|
||||||
var par1 = generics.resolve(m.getParameterList().getParameterAt(0).getType());
|
var par1 = generics.resolve(m.getParameterList().getParameterAt(0).getType());
|
||||||
@ -333,8 +329,12 @@ public class TestGenerics {
|
|||||||
|
|
||||||
var S = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, m);
|
var S = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, m);
|
||||||
var ACM = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, m);
|
var ACM = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, m);
|
||||||
assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("V")), new Bound(true, TypePlaceholder.of("ACM")), new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("V")), new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(ACM, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(ACM, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
|
var Y = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||||
|
assertEquals(Y, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
assertEquals(Y, generics.getBounds(id.getReturnType(), result.clazz, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -361,4 +361,10 @@ public class TestGenerics {
|
|||||||
public void testVoidMeth() throws Exception {
|
public void testVoidMeth() throws Exception {
|
||||||
var result = computeGenerics("TestVoidMeth.jav");
|
var result = computeGenerics("TestVoidMeth.jav");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAssign() throws Exception {
|
||||||
|
// TODO Check generics
|
||||||
|
var result = computeGenerics("TestAssign.jav");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class TphTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("Tph");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public class WhileTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
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");
|
classToTest = classFiles.get("While");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user