Compare commits
11 Commits
inferWildc
...
typeErasur
Author | SHA1 | Date | |
---|---|---|---|
87064f8c7d | |||
c7c50f4669 | |||
65448c3bf3 | |||
ac6980b5e0 | |||
59d50bd2c6 | |||
c613ed7e12 | |||
2ba966a4e7 | |||
7eaddd67a3 | |||
0aab2d9f53 | |||
33d6adf899 | |||
00add07132 |
.gitignore
src
main
java
de
dhbwstuttgart
bytecode
core
inferWildcards
ConstraintsGenerationUtils.javaFindInAstVisitor.javaJavaTXCompilerWildcards.javaReplaceTypeparamVisitor.javaTypePlaceholderReplaceUtils.java
parser
SyntaxTreeGenerator
syntaxtree
typeinference
unify2
test
java
bytecode
general
inferWildcards
resources
1
.gitignore
vendored
1
.gitignore
vendored
@ -29,4 +29,3 @@ logFiles/**
|
||||
|
||||
src/main/java/de/dhbwstuttgart/parser/antlr/
|
||||
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
|
||||
/pull.sh
|
||||
|
@ -584,6 +584,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
//ToDo Etienne: Für Type Erasure relevant?!
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
this.lamCounter++;
|
||||
@ -653,6 +654,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// generateBCForFunN(lambdaExpression, typeErasure);
|
||||
}
|
||||
|
||||
//ToDo Etienne: Relevant?!
|
||||
private String addUsedVarsToDesugaredMethodDescriptor(String lamDesc) {
|
||||
String newDesc = "(";
|
||||
int pos = 0;
|
||||
@ -674,6 +676,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
//ToDo Etienne: Relevant?!
|
||||
private String createDescriptorWithTypeErasure(LambdaExpression lambdaExpression) {
|
||||
String typeErasure = "(";
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
@ -767,6 +770,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// This will be used if the class is not standard class (not in API)
|
||||
ClassLoader cLoader2;
|
||||
|
||||
//ToDo methodCallType wird nicht korrekt resolved, da kein Constraint vorhanden ist
|
||||
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
||||
try {
|
||||
@ -811,11 +815,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
} catch (NotInCurrentPackageException | NotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
} else if(!helper.isInCurrPkg(clazz)){
|
||||
if(clazz.contains(CONSTANTS.$$)) {
|
||||
//ToDo Methoden Deskriptor neu setzen
|
||||
//ToDo Receiver neu setzen?!
|
||||
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
||||
helper.generateBCForFunN(mDesc);
|
||||
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
||||
helper.generateBCForFunN(typesOfParams, methCallType);
|
||||
}else {
|
||||
try {
|
||||
cLoader2 = new DirectoryClassLoader(path, classLoader);
|
||||
@ -872,6 +878,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
if(parentBinary || isBinaryExp) {
|
||||
doUnboxing(resolver.getResolvedType(methodCall.getType()));
|
||||
}
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
} else if(receiverName.contains(CONSTANTS.$$) && !methCallType.equals(Type.getInternalName(Object.class))) {
|
||||
helper.createCheckCast(methodCall,mv);
|
||||
}
|
||||
@ -899,6 +906,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
private void visitInvokeInsn(MethodCall methodCall, String receiverName, java.lang.reflect.Method methodRefl, String clazz, String mDesc, String receiverRefl) {
|
||||
// is methodCall.receiver functional Interface)?
|
||||
if (varsFunInterface.contains(methodCall.receiver.getType()) || (methodRefl!= null && receiverRefl.contains("interface")) ||
|
||||
|
@ -68,6 +68,7 @@ public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
|
||||
}
|
||||
}
|
||||
}
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
//TODO: generate a class java%% ... %%
|
||||
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains(CONSTANTS.ANGLEBRACKET)){
|
||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace(CONSTANTS.ANGLEBRACKET, "$$$").replace(">", "$$$")+ ";";
|
||||
@ -207,7 +208,7 @@ public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
|
||||
String desc = "(";
|
||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
//ToDo Etienne: Ändern von $$ nötig für TypeErasure?
|
||||
if(d.contains(CONSTANTS.TPH) ||d.contains(CONSTANTS.ANGLEBRACKET) || methodFromMethodCall.getReceiverName().contains("$$")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
@ -225,6 +226,7 @@ public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
|
||||
System.out.println("DescriptorToString retType = " + retType);
|
||||
if(retType.equals(CONSTANTS.VOID)) {
|
||||
desc += ")V";
|
||||
//ToDo Etienne: Ändern von $$ nötig für TypeErasure?
|
||||
}else if(retType.contains(CONSTANTS.TPH)|| retType.contains(CONSTANTS.ANGLEBRACKET) || methodFromMethodCall.getReceiverName().contains("$$")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
@ -240,6 +242,7 @@ public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
|
||||
return desc;
|
||||
}
|
||||
|
||||
//ToDo Etienne: Ändern für TypeErasure
|
||||
@Override
|
||||
public String createDescForFunN(ArgumentList argumentList, String returnType) {
|
||||
Iterator<Expression> itr1 = argumentList.getArguments().iterator();
|
||||
|
@ -11,7 +11,9 @@ public interface DescriptorVisitor {
|
||||
String visit(NormalMethod method);
|
||||
String visit(NormalConstructor constructor);
|
||||
String visit(Lambda lambdaExpression);
|
||||
//ToDo Etienne: Was ist SamMethod?
|
||||
String visit(SamMethod samMethod);
|
||||
//ToDo Etienne: Was ist MethodFromMethodCall?
|
||||
String visit(MethodFromMethodCall methodFromMethodCall);
|
||||
String createDescForFunN(ArgumentList argumentList, String returnType);
|
||||
}
|
||||
|
@ -136,6 +136,7 @@ public class Signature {
|
||||
defineGenericsFromConstraints(constraints,genericsAndBoundsMethod);
|
||||
}
|
||||
|
||||
//ToDo Etienne: für TypeErasure anschauen
|
||||
private void createSignatureForFunN(int numberOfParams, String to, String[] paramTypes) {
|
||||
defineTypeVariablesForParametersOfFunN(numberOfParams);
|
||||
|
||||
@ -147,6 +148,7 @@ public class Signature {
|
||||
|
||||
}
|
||||
|
||||
//ToDo Etienne: für TypeErasure anschauen
|
||||
private void createSignatureForFunN(int numberOfParams) {
|
||||
|
||||
defineTypeVariablesForParametersOfFunN(numberOfParams);
|
||||
@ -202,6 +204,7 @@ public class Signature {
|
||||
if (r instanceof GenericRefType) {
|
||||
sv.visitTypeVariable(sig2);
|
||||
} else if (!(r instanceof TypePlaceholder)) {
|
||||
//ToDo Etienne: Wichtig für Type Erasure?!
|
||||
if (sig2.contains(SPECIAL_CHAR_FOR_FUN)) {
|
||||
sv.visitInterface().visitClassType(sig2.substring(1));
|
||||
} else {
|
||||
@ -266,6 +269,7 @@ public class Signature {
|
||||
}
|
||||
|
||||
private void checkInnerSignatureOfWildCard(SignatureVisitor sv, String sigInner, int length, char superOrExtendsChar) {
|
||||
//ToDo Etienne: Wichtig für Type Erasure?!
|
||||
if (sigInner.contains(SPECIAL_CHAR_FOR_FUN)) {
|
||||
sv.visitTypeArgument(superOrExtendsChar).visitInterface().visitClassType(sigInner.substring(1, length));
|
||||
} else {
|
||||
|
@ -99,4 +99,34 @@ public class TypeToSignature implements TypeVisitor<String> {
|
||||
.filter(c -> c.getConstraint().getLeft().equals(tph) || c.getEqualsTPHs().contains(tph))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* //ToDo beschreiben
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author Etienne Zink
|
||||
*/
|
||||
public String visit(RefTypeOrTPHOrWildcardOrGeneric type){
|
||||
String returnString = "";
|
||||
if (type instanceof GenericRefType){
|
||||
GenericRefType genericRefType = (GenericRefType) type;
|
||||
returnString += visit(genericRefType);
|
||||
} else if (type instanceof RefType){
|
||||
RefType refType = (RefType) type;
|
||||
returnString += visit(refType);
|
||||
} else if (type instanceof TypePlaceholder){
|
||||
TypePlaceholder typePlaceholder = (TypePlaceholder) type;
|
||||
returnString += visit(typePlaceholder);
|
||||
} else if (type instanceof SuperWildcardType){
|
||||
SuperWildcardType superWildcardType = (SuperWildcardType) type;
|
||||
returnString += visit(superWildcardType);
|
||||
} else if (type instanceof ExtendsWildcardType) {
|
||||
ExtendsWildcardType extendsWildcardType = (ExtendsWildcardType) type;
|
||||
returnString += visit(extendsWildcardType);
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,38 @@
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.sql.Ref;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class ByteCodeForFunNGenerator {
|
||||
|
||||
/**
|
||||
* HashSet which contains the parameter number for which already a FunN$$ interface was generated.
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author Etienne Zink
|
||||
*/
|
||||
private static HashSet<Integer> alreadyGeneratedFunN = new HashSet<>();
|
||||
|
||||
//ToDo Etienne: wird in Test OLFun nicht verwendet!
|
||||
public static void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc, File path) {
|
||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
@ -38,57 +51,121 @@ public class ByteCodeForFunNGenerator {
|
||||
// ")"+lam.getReturn.getBounds
|
||||
Signature sig = new Signature(numberOfParams);
|
||||
String name = CONSTANTS.FUN + numberOfParams + CONSTANTS.$$;
|
||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||
classWriter.visit(V1_8, ACC_PUBLIC + ACC_INTERFACE + ACC_ABSTRACT, name, sig.toString(),
|
||||
Type.getInternalName(Object.class), null);
|
||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||
MethodVisitor mvApply = classWriter.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "apply", methDesc,
|
||||
methSig.toString(), null);
|
||||
mvApply.visitEnd();
|
||||
writeClassFile(classWriter.toByteArray(), name, path);
|
||||
writeClassFile(name, classWriter.toByteArray(), path);
|
||||
}
|
||||
|
||||
public static void generateBCForFunN(ArgumentList argumentList, String methDesc, File path) {
|
||||
/**
|
||||
* //ToDo beschreiben
|
||||
*
|
||||
* @param typesOfFormalParameters
|
||||
* @param returnType
|
||||
* @param path
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author Etienne Zink
|
||||
*/
|
||||
public static void generateBCForFunN(String[] typesOfFormalParameters, String returnType, File path) {
|
||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
int numberOfParameters = typesOfFormalParameters.length;
|
||||
generateSuperFunNInterface(numberOfParameters, path);
|
||||
|
||||
SignatureWriter methSig = new SignatureWriter();
|
||||
String className = getBaseFunClassname(numberOfParameters);
|
||||
String classSignature = String.format("L%s;L%s<", Type.getInternalName(Object.class), className);
|
||||
|
||||
int numberOfParams = 0;
|
||||
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
||||
Iterator<Expression> itr1 = argumentList.getArguments().iterator();
|
||||
|
||||
while(itr1.hasNext()) {
|
||||
numberOfParams++;
|
||||
// getBounds
|
||||
paramVisitor.visitTypeVariable(CONSTANTS.T + numberOfParams);
|
||||
itr1.next();
|
||||
//ToDo testen ob der Klassenname und -signatur so passt
|
||||
for (String typeOfFormalParameter: typesOfFormalParameters) {
|
||||
className += String.format("%s$_$", typeOfFormalParameter);
|
||||
classSignature += String.format("L%s;", typeOfFormalParameter);
|
||||
}
|
||||
className += returnType;
|
||||
className = className.replace('/', '$');
|
||||
classSignature += String.format("L%s>;", returnType);
|
||||
|
||||
methSig.visitReturnType().visitTypeVariable(CONSTANTS.R);
|
||||
// ")"+lam.getReturn.getBounds
|
||||
Signature sig = new Signature(numberOfParams);
|
||||
String name = CONSTANTS.FUN + numberOfParams + CONSTANTS.$$;
|
||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||
Type.getInternalName(Object.class), null);
|
||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||
methSig.toString(), null);
|
||||
mvApply.visitEnd();
|
||||
writeClassFile(classWriter.toByteArray(), name, path);
|
||||
System.out.println("Generated className: " + className);
|
||||
System.out.println("Generated signature: " + classSignature);
|
||||
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_INTERFACE | ACC_ABSTRACT, className, classSignature,
|
||||
Type.getInternalName(Object.class), new String[]{getBaseFunClassname(numberOfParameters)});
|
||||
writeClassFile(className, classWriter.toByteArray(), path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function which generates a {@code class-File} for the super interface
|
||||
* Fun<{@code numberOfParameters}>$$ if it doesn't exist already.
|
||||
*
|
||||
* @param numberOfParameters
|
||||
* @return {@code true}, iff the {@code class-File} exists after this method invocation
|
||||
* based on {@link #alreadyGeneratedFunN alreadyGeneratedFunN}.
|
||||
*
|
||||
* @since Studienarbeit Type Erase
|
||||
* @author Etienne Zink
|
||||
*/
|
||||
public static boolean generateSuperFunNInterface(int numberOfParameters, File path){
|
||||
if(alreadyGeneratedFunN.contains(numberOfParameters)) return true;
|
||||
//ToDo Etienne: Generierung der Signaturen/Deskriptoren vielleicht auslagern? Bzw. schauen ob nicht schon vorhanden und anpassen!
|
||||
String className = getBaseFunClassname(numberOfParameters);
|
||||
String classSignature = "<";
|
||||
String methodSignature = "(";
|
||||
String methodDescriptor = "(";
|
||||
for (int parameter = 1; parameter <= numberOfParameters; parameter++) {
|
||||
classSignature += String.format("T%d:L%s;", parameter, Type.getInternalName(Object.class));
|
||||
methodSignature += String.format("TT%d;", parameter);
|
||||
methodDescriptor += String.format("L%s;", Type.getInternalName(Object.class));
|
||||
}
|
||||
classSignature += String.format("R:L%s;>L%s;",Type.getInternalName(Object.class),Type.getInternalName(Object.class));
|
||||
methodSignature += ")TR;";
|
||||
methodDescriptor += String.format(")L%s;",Type.getInternalName(Object.class));
|
||||
|
||||
public static void writeClassFile(byte[] bytecode, String name, File path) {
|
||||
FileOutputStream output;
|
||||
try {
|
||||
System.out.println("generating " + name + ".class file...");
|
||||
output = new FileOutputStream(
|
||||
new File(path , name + CONSTANTS.EXTENSIONCLASS));
|
||||
ClassWriter classWriter = new ClassWriter(0);
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, className, classSignature, Type.getInternalName(Object.class), null);
|
||||
|
||||
MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", methodDescriptor, methodSignature, null);
|
||||
methodVisitor.visitEnd();
|
||||
classWriter.visitEnd();
|
||||
|
||||
byte[] bytecode = classWriter.toByteArray();
|
||||
if(writeClassFile(className, bytecode, path)) {
|
||||
alreadyGeneratedFunN.add(numberOfParameters);
|
||||
}
|
||||
return alreadyGeneratedFunN.contains(numberOfParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param countParameters
|
||||
* @return the String of the super Fun$$ type
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author Etienne Zink
|
||||
*/
|
||||
private static String getBaseFunClassname(int countParameters){
|
||||
return String.format("Fun%d$$", countParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a {@code class-File} for the class {@code className} with the {@code bytecode}.
|
||||
*
|
||||
* @param className of the class to generate
|
||||
* @param bytecode of the class
|
||||
* @param directory where the class should be saved to
|
||||
* @return {@code true}, iff the {@code class-File} could be generated.
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author Etienne Zink
|
||||
*/
|
||||
private static boolean writeClassFile(String className, byte[] bytecode, File directory) {
|
||||
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
|
||||
output.write(bytecode);
|
||||
output.close();
|
||||
System.out.println(name + ".class file generated");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
output.flush();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -220,10 +220,13 @@ public class MethodCallHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public void generateBCForFunN(String methodDescriptor) {
|
||||
ByteCodeForFunNGenerator.generateBCForFunN(methCall.arglist,methodDescriptor,path);
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
public void generateBCForFunN(String[] typesOfFormalParams, String receiverType) {
|
||||
//ToDo return Descriptor auf apply Methode?
|
||||
ByteCodeForFunNGenerator.generateBCForFunN(typesOfFormalParams, receiverType,path);
|
||||
}
|
||||
|
||||
//ToDo Etienne: Für Type Erasure wichtig
|
||||
public String getDescriptorOfApplyMethod(String methodCallType) {
|
||||
return new DescriptorToString().createDescForFunN(methCall.arglist, methodCallType);
|
||||
}
|
||||
|
@ -92,9 +92,6 @@ public class JavaTXCompiler {
|
||||
this(sourceFile);
|
||||
this.log = log;
|
||||
}
|
||||
public JavaTXCompiler(File[] sourceFiles) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFiles), null);
|
||||
}
|
||||
public JavaTXCompiler(List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||
this(sourceFiles, null);
|
||||
}
|
||||
@ -111,8 +108,7 @@ public class JavaTXCompiler {
|
||||
//INSTANCE = this;
|
||||
}
|
||||
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
ClassOrInterface objectClass = ASTFactory.createClass(
|
||||
@ -888,6 +884,7 @@ public class JavaTXCompiler {
|
||||
return result;
|
||||
}
|
||||
|
||||
//ToDo Etienne: Für Type Erasure wichtig?! (alle generatedBytecode-Methoden?)
|
||||
public void generateBytecode() throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||
generateBytecode((File) null);
|
||||
}
|
||||
|
@ -1,132 +0,0 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
/**
|
||||
* Utilities to generate the constraints for the infer wildcards algorithm.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class ConstraintsGenerationUtils
|
||||
{
|
||||
|
||||
private ConstraintsGenerationUtils () {
|
||||
throw new AssertionError("No ConstraintsGenerationUtils instance for you");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a map of type placeholder and RefType and merge
|
||||
* these to the already provided constraints.
|
||||
*
|
||||
* @param tphMap {@link Map} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @param constraints {@link ConstraintSet} over {@link Pair} to merge to
|
||||
* @return The same instance {@code constraints} provided including the merged
|
||||
* constraints
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateAndMergeConstraints (
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap,
|
||||
ConstraintSet<Pair> constraints) {
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
constraints.addAll(generateConstraints);
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a map of type placeholder and RefType.
|
||||
*
|
||||
* @param tphMap {@link Map} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link ConstraintSet} of {@link Pair} containing the constraints to
|
||||
* infer the matching wildcard type.
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateConstraints (
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap) {
|
||||
return tphMap.entrySet().stream().map(ConstraintsGenerationUtils::generateConstraints)
|
||||
.reduce(
|
||||
new ConstraintSet<>(),
|
||||
(cs, c) -> {
|
||||
cs.addAll(c);
|
||||
return cs;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a single RefType type placeholder pair to infer
|
||||
* the wildcards for the generic parameter type.
|
||||
*
|
||||
* @param tphEntry {@link Entry} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link ConstraintSet} of {@link Pair} generated containing the
|
||||
* constraints.
|
||||
*/
|
||||
private static ConstraintSet<Pair> generateConstraints (
|
||||
Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphEntry) {
|
||||
return generateConstraints(tphEntry.getValue(), tphEntry.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a single RefType type placeholder pair to infer
|
||||
* the wildcards for the generic parameter type.
|
||||
*
|
||||
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @param tph {@link TypePlaceholder}
|
||||
* @return {@link ConstraintSet} of {@link Pair} generated containing the
|
||||
* constraints.
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateConstraints (RefTypeOrTPHOrWildcardOrGeneric refType,
|
||||
TypePlaceholder tph) {
|
||||
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
|
||||
Set<Constraint<Pair>> oderConstraints = new HashSet<>();
|
||||
constraintSet.addOderConstraint(oderConstraints);
|
||||
|
||||
// single type
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, refType);
|
||||
|
||||
// extends type
|
||||
ExtendsWildcardType extendsWildcardType = new ExtendsWildcardType(refType, new NullToken());
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, extendsWildcardType);
|
||||
|
||||
// super type
|
||||
SuperWildcardType superWildcardType = new SuperWildcardType(refType, new NullToken());
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, superWildcardType);
|
||||
|
||||
return constraintSet;
|
||||
}
|
||||
|
||||
private static void addToOderConstraint (Set<Constraint<Pair>> oderConstraints, TypePlaceholder tph,
|
||||
RefTypeOrTPHOrWildcardOrGeneric refType) {
|
||||
Constraint<Pair> c = new Constraint<>();
|
||||
oderConstraints.add(c);
|
||||
|
||||
ConstraintsGenerationUtils.addToConstraint(c, tph, refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a pair and adds it to a constraint.
|
||||
*
|
||||
* @param c {@link Constraint} of {@link Pair}
|
||||
* @param tph {@link TypePlaceholder}
|
||||
* @param type {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
*/
|
||||
private static void addToConstraint (Constraint<Pair> c, TypePlaceholder tph,
|
||||
RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
Pair pair = new Pair(tph, type, PairOperator.EQUALSDOT);
|
||||
c.add(pair);
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class FindInAstVisitor
|
||||
{
|
||||
|
||||
public static boolean find (SourceFile file, TypePlaceholder tph) {
|
||||
FindInAstVisitor findInAstVisitor = new FindInAstVisitor(tph);
|
||||
return findInAstVisitor.find(file);
|
||||
}
|
||||
|
||||
private boolean find;
|
||||
private TypePlaceholder tph;
|
||||
|
||||
|
||||
public FindInAstVisitor (TypePlaceholder tph) {
|
||||
this.tph = tph;
|
||||
find = false;
|
||||
}
|
||||
|
||||
public boolean find (SourceFile file) {
|
||||
CostumASTWalker walker = new CostumASTWalker();
|
||||
walker.visit(file);
|
||||
return find;
|
||||
}
|
||||
|
||||
private class CostumASTWalker extends AbstractASTWalker{
|
||||
|
||||
@Override
|
||||
public void visit (TypePlaceholder typePlaceholder) {
|
||||
if (typePlaceholder.equals(tph))
|
||||
find = true;
|
||||
else
|
||||
super.visit(typePlaceholder);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
/**
|
||||
* Extension of the JavaTX Compiler providing the capabilities to inference
|
||||
* wildcard types.
|
||||
* <p>
|
||||
* <code>
|
||||
* <ul>
|
||||
* <li>? super Type</li>
|
||||
* <li>? extends Type</li>
|
||||
* <li>Type</li>
|
||||
* </ul>
|
||||
* </code>
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public class JavaTXCompilerWildcards
|
||||
extends JavaTXCompiler
|
||||
{
|
||||
|
||||
/**
|
||||
* Generated Type placeholder and the implementation type represented.
|
||||
*/
|
||||
private final Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap;
|
||||
|
||||
public JavaTXCompilerWildcards (File... sourceFile) throws IOException, ClassNotFoundException {
|
||||
super(Arrays.asList(sourceFile));
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||
super(sourceFile, log);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||
super(sourceFiles);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sources, List<File> contextPath)
|
||||
throws IOException, ClassNotFoundException {
|
||||
super(sources, contextPath);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Type Placeholder generated.
|
||||
*
|
||||
* @return {@link Map} over {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
*/
|
||||
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
|
||||
return tphMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet<Pair> getConstraints () throws ClassNotFoundException, IOException {
|
||||
ConstraintSet<Pair> constraints = super.getConstraints();
|
||||
return ConstraintsGenerationUtils.generateAndMergeConstraints(tphMap, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the source code for manipulated Java Generic Types to a new .java
|
||||
* file.
|
||||
*
|
||||
* @param outputDir {@link File}
|
||||
* @throws IOException if an i/o exception during file reading and
|
||||
* writing occurs
|
||||
* @throws ClassNotFoundException see {@link #typeInference()}
|
||||
*/
|
||||
public void generateSourceCode (File outputDir) throws IOException, ClassNotFoundException {
|
||||
if (!outputDir.exists()) {
|
||||
boolean mkdirs = outputDir.mkdirs();
|
||||
if (!mkdirs)
|
||||
throw new IOException("Could not create output directory at: " + outputDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
List<ResultSet> typeInference = typeInference();
|
||||
|
||||
if (typeInference.isEmpty())
|
||||
return;
|
||||
|
||||
ResultSet resultSet = typeInference.get(0); // Use the first available result sets
|
||||
|
||||
for (Map.Entry<File, SourceFile> e : sourceFiles.entrySet()) {
|
||||
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> list = tphMap.entrySet().stream().filter(d -> FindInAstVisitor.find(e.getValue(), d.getKey())).sorted( (c1, c2) -> Integer.compare(c1.getValue().getOffset().getStartIndex(),
|
||||
c2.getValue().getOffset().getStartIndex())).collect(Collectors.toList());
|
||||
generateSourceCode(e.getKey(), outputDir, list, resultSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void generateSourceCode (File inputFile, File outputDir,
|
||||
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> tphs,
|
||||
ResultSet results)
|
||||
throws IOException {
|
||||
|
||||
File outputFile = new File(outputDir, inputFile.getName());
|
||||
|
||||
Files.deleteIfExists(outputFile.toPath());
|
||||
|
||||
if(!outputFile.createNewFile())
|
||||
throw new IOException("File could not be created at: " + outputFile.getAbsolutePath());
|
||||
|
||||
try(BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))){
|
||||
|
||||
|
||||
int readIdx = 0;
|
||||
|
||||
for (Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> e : tphs) {
|
||||
Token token = e.getValue().getOffset();
|
||||
|
||||
// read the characters before the token
|
||||
int startIndex = token.getStartIndex();
|
||||
char[] read = new char[startIndex - readIdx];
|
||||
|
||||
int i = reader.read(read);
|
||||
if (i != read.length)
|
||||
throw new IOException("Could not read the assumed number of character, read " + i
|
||||
+ " assumed " + read.length);
|
||||
|
||||
readIdx += read.length;
|
||||
|
||||
// Write to output file
|
||||
writer.write(read);
|
||||
|
||||
// Write the new type
|
||||
ResolvedType resolveType = results.resolveType(e.getKey());
|
||||
String string = resolveType.resolvedType.toString();
|
||||
writer.write(string);
|
||||
|
||||
// Read the replaced type and count the read counter
|
||||
int length = token.getStopIndex() - token.getStartIndex() + 1;
|
||||
reader.read(new char[length]);
|
||||
readIdx += length;
|
||||
|
||||
// Read the replaced nested type if the result was a nested type
|
||||
Pattern pattern = Pattern.compile("<.*>");
|
||||
Matcher matcher = pattern.matcher(string);
|
||||
if (matcher.find()) {
|
||||
|
||||
// Read the first and check if it will be a Java Generic Expression starting
|
||||
// with <
|
||||
char c = (char) reader.read();
|
||||
readIdx++;
|
||||
|
||||
if (c != '<')
|
||||
throw new IllegalStateException("At this position is a < expected, found " + c);
|
||||
|
||||
// Read and forget all content until a > on the same level
|
||||
int opens = 1;
|
||||
while (opens > 0) {
|
||||
c = (char) reader.read();
|
||||
readIdx++;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '<':
|
||||
opens++;
|
||||
break;
|
||||
case '>':
|
||||
opens--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read the rest of the file.
|
||||
while (true) {
|
||||
char[] tmp = new char[1024];
|
||||
int read = reader.read(tmp);
|
||||
if (read == -1)
|
||||
break;
|
||||
|
||||
writer.write(tmp, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Visitor replace type parameter of the type RefType by Type Placeholder in a
|
||||
* AST.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ReplaceTypeparamVisitor
|
||||
extends AbstractASTWalker
|
||||
{
|
||||
|
||||
/**
|
||||
* Containing the replaced RefType and the mapping TPH
|
||||
*/
|
||||
private final Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> tphMap;
|
||||
|
||||
/**
|
||||
* Constructor for a {@code ReplaceTypeparamVisitor}.
|
||||
*/
|
||||
public ReplaceTypeparamVisitor () {
|
||||
this.tphMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (Field field) {
|
||||
System.out.println("Field: " + field.getName());
|
||||
|
||||
field.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (FormalParameter formalParameter) {
|
||||
System.out.println("FormalParameter: " + formalParameter.getName());
|
||||
|
||||
formalParameter.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(formalParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (LocalVarDecl localVarDecl) {
|
||||
System.out.println("LocalVarDecl: " + localVarDecl.getName());
|
||||
|
||||
localVarDecl.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(localVarDecl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (Method method) {
|
||||
System.out.println("Method: " + method.getName());
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||
if (returnType != null)
|
||||
returnType.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mapping of the replaced {@link RefType} and the inserted
|
||||
* {@link TypePlaceholder}.
|
||||
*
|
||||
* @return {@link Map} of {@link TypePlaceholder} and {@link RefType}
|
||||
*/
|
||||
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
|
||||
return tphMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visitor replace each RefType occurs.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
private class ReplaceRefTypeVisitor
|
||||
extends AbstractASTWalker
|
||||
{
|
||||
@Override
|
||||
public void visit (RefType refType) {
|
||||
|
||||
// check if RefType has Parameter Types
|
||||
if (!refType.getParaList().isEmpty()) {
|
||||
System.out.print("Visit Type: " + refType + " -> ");
|
||||
|
||||
// Iterate over all Parameter Types
|
||||
for (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator = refType.getParaList()
|
||||
.listIterator(); listIterator.hasNext();) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric next = listIterator.next();
|
||||
|
||||
// If Parameter type is RefType replace with TPH
|
||||
if (next instanceof RefType) {
|
||||
RefType nextRefType = (RefType) next;
|
||||
|
||||
// Visit replaced RefType to get all nested type parameters
|
||||
// Should be done before generating parents TPH to include child TPH in the
|
||||
// parent TPH mapping
|
||||
this.visit(nextRefType);
|
||||
|
||||
generateTphAndReplaceInTree(listIterator, next);
|
||||
}
|
||||
else if (next instanceof GenericRefType) {
|
||||
|
||||
// Visit of nested type arguments not necessary as Generic Types cannot contain
|
||||
// type parameters
|
||||
|
||||
generateTphAndReplaceInTree(listIterator, next);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(refType);
|
||||
}
|
||||
|
||||
// Let the parent take care about all the other stuff
|
||||
super.visit(refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric} and saves the
|
||||
* mapping.
|
||||
*
|
||||
* @param t {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link TypePlaceholder} generated
|
||||
*/
|
||||
private TypePlaceholder generateTypePlaceholder (RefTypeOrTPHOrWildcardOrGeneric t) {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(new NullToken());
|
||||
tphMap.put(tph, t);
|
||||
return tph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric}, saves the
|
||||
* mapping and replaces the type by the type placeholder in the tree.
|
||||
*
|
||||
* @param listIterator {@link ListIterator} over
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric} representing the
|
||||
* tree to replace in
|
||||
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric} to generate type
|
||||
* placeholder for and replace
|
||||
*/
|
||||
private void generateTphAndReplaceInTree (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator,
|
||||
RefTypeOrTPHOrWildcardOrGeneric refType) {
|
||||
// Generate TPH
|
||||
TypePlaceholder tph = generateTypePlaceholder(refType);
|
||||
|
||||
// Replace in AST
|
||||
listIterator.set(tph);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Class providing utilities to generate the Type placeholder for parameter
|
||||
* types which shall be inferred.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class TypePlaceholderReplaceUtils
|
||||
{
|
||||
|
||||
private TypePlaceholderReplaceUtils () {
|
||||
throw new AssertionError("No TypePlaceholderReplaceUtils instance for you");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map of the generated type placeholder for the associate parameter
|
||||
* type
|
||||
*
|
||||
* @param compiler {@link JavaTXCompiler} to get the source file from
|
||||
* @return {@link Map} over {@link TypePlaceholder} and the {@link RefType}
|
||||
* replaced
|
||||
*/
|
||||
public static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTypePlaceholder (
|
||||
JavaTXCompiler compiler) {
|
||||
Map<File, SourceFile> sourceFiles = compiler.sourceFiles;
|
||||
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
||||
sourceFiles.forEach( (k, v) -> v.accept(visitor));
|
||||
return visitor.getTphMap();
|
||||
}
|
||||
|
||||
}
|
@ -272,8 +272,10 @@ public class StatementGenerator {
|
||||
whole+=".";
|
||||
}
|
||||
|
||||
if(parts.length < 2){
|
||||
if(parts.length < 2 || parts[0].contentEquals("this") ){
|
||||
receiver = new This(offset);
|
||||
} else if (parts[0].contentEquals("super")) {
|
||||
receiver = new Super(offset);
|
||||
}else if(receiver == null){ //Handelt es sich um keinen Statischen Klassennamen:
|
||||
String part = expression.substring(0,expression.length() - (1 + parts[parts.length-1].length()));
|
||||
receiver = generateLocalOrFieldVarOrClassName(part, offset);
|
||||
|
@ -185,6 +185,7 @@ public class TypeGenerator {
|
||||
}else{
|
||||
Pattern p = Pattern.compile("Fun(\\d+)[$][$]");
|
||||
Matcher m = p.matcher(name);
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
if (m.matches()) {//es ist FunN$$-Type
|
||||
return new RefType(new JavaClassName(name), convert(typeArguments, reg, generics), offset);
|
||||
} else {
|
||||
|
@ -9,6 +9,7 @@ import org.antlr.v4.runtime.Token;
|
||||
*
|
||||
*/
|
||||
|
||||
//ToDo Etienne: Wieso abstrakte Klasse? -> Dadurch keine Inferenz mit ? möglich!
|
||||
public abstract class WildcardType extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
|
||||
protected RefTypeOrTPHOrWildcardOrGeneric innerType = null;
|
||||
|
@ -63,6 +63,7 @@ public class MethodAssumption extends Assumption{
|
||||
//Die Generics werden alle zu TPHs umgewandelt.
|
||||
params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken())));
|
||||
}
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||
if(receiver instanceof FunNClass){
|
||||
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString()+"$$"), params, new NullToken()); // new FunN(params);
|
||||
|
@ -68,6 +68,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
lambdaParams.add(tphRetType);
|
||||
//lambdaParams.add(0,tphRetType);
|
||||
constraintsSet.addUndConstraint(
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
new Pair(lambdaExpression.getType(),
|
||||
new RefType(new JavaClassName("Fun"+(lambdaParams.size()-1)+"$$"), lambdaParams, new NullToken()),
|
||||
//new FunN(lambdaParams),
|
||||
|
@ -21,6 +21,7 @@ public class FunNType extends UnifyType {
|
||||
/**
|
||||
* Creates a FunN-Type with the specified TypeParameters.
|
||||
*/
|
||||
//ToDo Etienne: Für Type Erasure wichtig?!
|
||||
protected FunNType(TypeParams p) {
|
||||
super("Fun"+(p.size()-1)+"$$", p);
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
package de.dhbwstuttgart.unify2.model;
|
||||
|
||||
public class Result<A> {
|
||||
private final A v;
|
||||
|
||||
private Result(A a, UnifyError e){
|
||||
this.v = a;
|
||||
}
|
||||
|
||||
public static <A> Result<A> of(A a){
|
||||
return new Result(a, null);
|
||||
}
|
||||
|
||||
public static <A> Result<A> error(UnifyError error){
|
||||
return new Result(null, error);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package de.dhbwstuttgart.unify2.model;
|
||||
|
||||
public class UnifyError {
|
||||
|
||||
}
|
@ -1,52 +1,65 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import general.TestCleanUp;
|
||||
import org.junit.*;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test which only checks if the class {@code OLFun} was correctly compiled.
|
||||
* This is achived by verifying the existence of the three implementations of {@code m}.
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author Etienne Zink
|
||||
*/
|
||||
public class OLFunTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Class<?> classFun1;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||
classToTest = loader.loadClass("OLFun");
|
||||
/*
|
||||
classFun1 = loader.loadClass("Fun1$$");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
Method m = classToTest.getDeclaredMethod("m");
|
||||
Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
||||
Method apply = lambda.getMethod("apply", Object.class);
|
||||
|
||||
// Damit man auf die Methode zugreifen kann
|
||||
apply.setAccessible(true);
|
||||
|
||||
Integer i = 77;
|
||||
|
||||
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
||||
|
||||
assertEquals(77, result);
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithInteger() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1 ,Integer.class);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithString() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1 ,String.class);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithDouble() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1 ,Double.class);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp(){
|
||||
TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class"));
|
||||
}
|
||||
}
|
||||
|
14
src/test/java/general/TestCleanUp.java
Normal file
14
src/test/java/general/TestCleanUp.java
Normal file
@ -0,0 +1,14 @@
|
||||
package general;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
public class TestCleanUp {
|
||||
|
||||
public static void cleanUpDirectory(File directory, FileFilter fileFilter){
|
||||
if(!directory.isDirectory()) throw new RuntimeException("Directory for bytecode generation is wrong!");
|
||||
for (File file: directory.listFiles(fileFilter)) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsFields
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsFields.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
private static List<ResultSet> generateExpectedTypeInferResult (JavaTXCompilerWildcards compiler) {
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = compiler.getTphMap();
|
||||
|
||||
ArrayList<ResultSet> list = new ArrayList<>();
|
||||
|
||||
tphMap.forEach( (tph, t) -> {
|
||||
ResultPair r = new PairTPHequalRefTypeOrWildcardType(tph,
|
||||
new RefType(new JavaClassName("java.lang.String"), new NullToken()));
|
||||
HashSet<ResultPair> set = new HashSet<>();
|
||||
set.add(r);
|
||||
list.add(new ResultSet(set));
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsMap
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsMap.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsMapNested
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsMapNested.java";
|
||||
}
|
||||
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 9", 9, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsNested
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsNested.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsParamType
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsParamType.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsSingle
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingle.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 3", 3, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsSingleLib
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingleLib.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 2", 2, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import java.lang.Boolean;
|
||||
public class OLFun {
|
||||
|
||||
//f = x -> {return x + x;};
|
||||
|
||||
m(f, x) {
|
||||
x = f.apply(x+x);
|
||||
}
|
||||
|
2
src/test/resources/inferWildcards/.gitignore
vendored
2
src/test/resources/inferWildcards/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/generatedSC/
|
||||
/generatedBC/
|
@ -1,31 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
|
||||
class TestClassWildcardsFields
|
||||
{
|
||||
|
||||
private List<String> field1;
|
||||
//private int counter;
|
||||
|
||||
public TestClassWildcards () {
|
||||
//field1 = new ArrayList<>();
|
||||
//counter = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Working method for Java
|
||||
* @param param1
|
||||
* @return
|
||||
*/
|
||||
public List<String> test (List<String> param1) {
|
||||
List<String> localVar = field1;
|
||||
field1 = param1;
|
||||
//counter++;
|
||||
return localVar;
|
||||
}
|
||||
|
||||
public void foo() {
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsMap
|
||||
{
|
||||
|
||||
public Map<Integer, Object> test(Map<Integer, String> input){
|
||||
Map<Integer, Object> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsMapNested
|
||||
{
|
||||
|
||||
public Map<Integer, Collection<Object>> test(Map<Integer, List<String>> input){
|
||||
Map<Integer, Collection<Object>> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsNested
|
||||
{
|
||||
public List<Collection<Object>> test(List<List<String>> input){
|
||||
List<Collection<Object>> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
|
||||
public final class TestClassWildcardsParamType<T1, T2> {
|
||||
public final T1 first;
|
||||
public final T2 second;
|
||||
|
||||
public TestClassWildcardsParamType(T1 first, T2 second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public static <T1, T2> TestClassWildcardsParamType<T1, T2> of(T1 first, T2 second) {
|
||||
return new TestClassWildcardsParamType<>(first, second);
|
||||
}
|
||||
|
||||
public static void main(String[] agrs) {
|
||||
TestClassWildcardsParamType<Class<?>, String> pair = TestClassWildcardsParamType.of(List.class, "hello");
|
||||
|
||||
//Output of compiler
|
||||
//TestClassWildcardsParamType<? extends Class<?>, String> pair = TestClassWildcardsParamType.of(List.class, "hello");
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
|
||||
class TestClassWildcardsSingle
|
||||
{
|
||||
|
||||
/**
|
||||
* Non working method in normal Java
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public List<Object> test (List<String> input) {
|
||||
List<Object> listOfObjects = input;
|
||||
Object test = listOfObjects.get(0);
|
||||
String string = "Test";
|
||||
input.add(string);
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import java.util.List;
|
||||
|
||||
class TestClassWildcardsLib
|
||||
{
|
||||
|
||||
// public <T> List<T> merge (List<T> l1, List<T> l2) {
|
||||
// l2.forEach(s -> {if(!l1.contains(s)) l1.add(s);});
|
||||
// return l2;
|
||||
// }
|
||||
|
||||
public static <T> List<T> foo(List<T> dd){
|
||||
T t = dd.get(1);
|
||||
return dd;
|
||||
}
|
||||
}
|
14
src/test/resources/javFiles/packageTest/Pair2.jav
Normal file
14
src/test/resources/javFiles/packageTest/Pair2.jav
Normal file
@ -0,0 +1,14 @@
|
||||
import de.test.Pair;
|
||||
|
||||
class Pairs {
|
||||
setfst(fst) {
|
||||
return new Pair<>(snd, fst);
|
||||
}
|
||||
|
||||
swap () {
|
||||
return new Pair<> (snd, fst); }
|
||||
|
||||
polyrec(p) {
|
||||
return polyrec (p.swap());
|
||||
}
|
||||
}
|
12
src/test/resources/javFiles/packageTest/de/test/Pair.jav
Normal file
12
src/test/resources/javFiles/packageTest/de/test/Pair.jav
Normal file
@ -0,0 +1,12 @@
|
||||
package de.test;
|
||||
|
||||
class Pair {
|
||||
fst;
|
||||
snd;
|
||||
|
||||
Pair(fst, snd) {
|
||||
this.fst = fst;
|
||||
this.snd = snd;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user